Skip to content

StemStochiometry basic structure.#825

Merged
sallymatson merged 27 commits intodevelopfrom
749-initial-stochiometry
Jul 7, 2025
Merged

StemStochiometry basic structure.#825
sallymatson merged 27 commits intodevelopfrom
749-initial-stochiometry

Conversation

@sallymatson
Copy link
Copy Markdown
Collaborator

@sallymatson sallymatson commented Apr 9, 2025

Description

This PR adds a new module, Stochiometry, to track plant NP values. The class stricture includes a baseclass Foliage which has subclasses for each tissue type. The Foliage models store the element quantity, ideal ratios, and perform simple calculations using these values. The set of tissues for a cohort is stored in the StemStochiometry class. This class has further fuctionality which can balance element surplus/deficit, and perform calculations across the whole plant foliage groups.

The next steps for stochiometry include expanding the initialization so that each PFT can specify the initial ratios (#899), dealing with mortality (#800), and creating more robust tests to ensure all cases are covered (#801).

Fixes #749

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

@sallymatson sallymatson linked an issue Apr 9, 2025 that may be closed by this pull request
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 9, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.22%. Comparing base (de3daeb) to head (a847c38).

Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #825      +/-   ##
===========================================
+ Coverage    94.08%   94.22%   +0.13%     
===========================================
  Files           78       79       +1     
  Lines         6172     6320     +148     
===========================================
+ Hits          5807     5955     +148     
  Misses         365      365              

☔ 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.

Yup - that looks good!

n_weighted_avg = np.dot(
self.data["ecto_supply_limit_n"][cell_id]
+ self.data["arbuscular_supply_limit_n"][cell_id],
cohorts.n_individuals,
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.

Should this be n_individuals * total tissue mass or crown_area?

Comment on lines +296 to +301
if self.n_surplus[cohort] > self.n_tissue_deficit[cohort]:
# If there is sufficient surplus N to cover the existing deficit, the
# amount of the deficit is subtracted from the surplus which persists until
# the next update. All tissue types are updated to the ideal N ratios.
self.n_surplus[cohort] = (
self.n_surplus[cohort] - self.n_tissue_deficit[cohort]
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.

Handle with .max() and the subtract to get remaining surplus

@sallymatson sallymatson requested a review from davidorme June 17, 2025 14:40
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.

@sallymatson Looks really good - very clean coding. Changes are mostly either "more comments" or minor structural changes.

The bigger one is the setup of the Tissues abstract class, which I think we can finesse a bit. I've called in @dalonsoa to just check this isn't an "everything looks like a nail" issue.

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.

This looks good - it's nicely structured and seems really coherent with the rest of the existing test suite.

The only thing I'd add are more comments in the test code to walk through what is happening. These really don't have to be extensive but even # now create the XYZ object to test ABC style comments make it much easier to pick tests up if they need updating.

Comment on lines +927 to +930
n_avaiable_per_cohort = n_weighted_avg / sum(n_weighted_avg)
n_available_per_stem = np.divide(
n_avaiable_per_cohort, cohorts.n_individuals
)
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.

Suggested change
n_avaiable_per_cohort = n_weighted_avg / sum(n_weighted_avg)
n_available_per_stem = np.divide(
n_avaiable_per_cohort, cohorts.n_individuals
)
n_available_per_cohort = n_weighted_avg / sum(n_weighted_avg)
n_available_per_stem = np.divide(
n_available_per_cohort, cohorts.n_individuals
)

Co-authored-by: arne-scheire <97458577+arne-exe@users.noreply.github.com>
@sallymatson sallymatson requested review from arne-exe and davidorme July 3, 2025 15:15
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 - basic structure of the class is now very clean looking and all the stretch goals are clearly noted for later PRs.

@davidorme
Copy link
Copy Markdown
Collaborator

We should also add the stochiometric data into the CommunityDataExporter...

@sallymatson sallymatson marked this pull request as ready for review July 7, 2025 14:44
@sallymatson sallymatson merged commit 0b9f7de into develop Jul 7, 2025
16 checks passed
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.

Initial stochiometry

4 participants