Skip to content

Change mycorrhizal supply calculation to prevent negative populations#1163

Merged
jacobcook1995 merged 7 commits intodevelopfrom
bugfix/symbiotic_supply_limits
Dec 1, 2025
Merged

Change mycorrhizal supply calculation to prevent negative populations#1163
jacobcook1995 merged 7 commits intodevelopfrom
bugfix/symbiotic_supply_limits

Conversation

@jacobcook1995
Copy link
Copy Markdown
Collaborator

Description

Negative mycorrhizal populations were occurring after the initial time step because the calculation of the maximum amount of nutrient that they can supply to the plant was using guesses for temperature and matric potential. This resulted in mycorrhizal fungi promising far more nutrient than they could provide (even from their existing biomass). I have partially addressed this overpromising by using mean annual temperature as a guess for the soil temperature (which is a fairly common assumption) and by calculating initial values for matric potential based on the initial values for soil moisture.

This partly addresses #835, but does not fully resolve it, as there is still no initial value for soil temperatures, and the initial value of matric potential could be significantly off. This is arguably an issue that won't be completely fixed until we have decided an approach to model spin up.

@vgro, one thing we should decide is whether the calculations make sense in their current location, or are better moved to the hydrology model init? (happy to do the work to move them if so)

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 Nov 27, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.36%. Comparing base (98f2629) to head (274facf).
⚠️ Report is 14 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #1163   +/-   ##
========================================
  Coverage    94.35%   94.36%           
========================================
  Files           70       70           
  Lines         7055     7058    +3     
========================================
+ Hits          6657     6660    +3     
  Misses         398      398           

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

@jacobcook1995 jacobcook1995 requested a review from vgro November 27, 2025 10:56
soil_water_potential = np.full_like(
self.data["pH"].to_numpy(),
self.model_constants.soil_microbe_water_potential_optimum,
# As soil temperature hasn't be calculated yet we assume that it matches the
Copy link
Copy Markdown
Collaborator

@vgro vgro Nov 27, 2025

Choose a reason for hiding this comment

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

soil temperature is initialised in the abiotic simple model but no values are assigned

# create soil temperature array
self.data["soil_temperature"] = self.layer_structure.from_template()

I think it would make sense to just add the mean annual temperature there. I'm happy for you to do that if that helps here

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.

Oh yeah that massively simplifies the work flow on my side!

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.

Actually, scratch that I would need both the soil temperature and the air temperature (for the surface temperature) to be populated. I guess populating the soil temperature with the mean annual temperature is an acceptable initial guess but that doing the same with air temperature wouldn't be?

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.

yeah that's true. The abiotic model initializes everything but the abiotic_simple doesn't. Ideally they would have the same set of variables initialized and updated...I think for now your solution is good, it might be worth changing the init of the simple model in case that comes up elsewhere, but that can be my TODO.

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.

Okay, I'll add a TODO to the docstring of abiotic simple model init about this

Copy link
Copy Markdown
Collaborator

@vgro vgro left a comment

Choose a reason for hiding this comment

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

Looks sensible to me, I agree that moving the initialization to the abiotic and hydrology model might make it simpler and I'm happy for you to do that. The set of variables that are initialized with values was purely based on my requirements, there is no reason why that shouldn't include more variables.
Let me know when you made the changes and I'll approve the PR

@jacobcook1995 jacobcook1995 requested a review from vgro November 28, 2025 09:41
@jacobcook1995
Copy link
Copy Markdown
Collaborator Author

I've moved the matric potential calculation into the soil hydrology init, let me know if that all seems reasonable!

I kept the soil temperature stuff unchanged as I didn't think populating the air temperature with the mean annual temperature seemed like a sane thing to do (though I agreed that it seemed reasonable for the soil temperature).

Copy link
Copy Markdown
Collaborator

@vgro vgro left a comment

Choose a reason for hiding this comment

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

LGTM

@jacobcook1995 jacobcook1995 merged commit 035163b into develop Dec 1, 2025
13 checks passed
@jacobcook1995 jacobcook1995 deleted the bugfix/symbiotic_supply_limits branch December 1, 2025 10:53
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