Skip to content

Add nitrogen fixation to the soil model#724

Merged
jacobcook1995 merged 6 commits intodevelopfrom
708-add-functionality-for-nitrogen-fixation
Feb 6, 2025
Merged

Add nitrogen fixation to the soil model#724
jacobcook1995 merged 6 commits intodevelopfrom
708-add-functionality-for-nitrogen-fixation

Conversation

@jacobcook1995
Copy link
Copy Markdown
Collaborator

Description

This PR adds nitrogen fixation to the soil model. There are two distinct types, fixation by free-living microbes and fixation by plant associated microbes. At some point in the future it might make sense for the plant associated fixation to happen within the plants model, but for now keeping it the soil seems simplest.

To get this to work I had to add code to the plants model so @davidorme if you could take a look and check that my changes seem reasonable that would be great.

Again this is a PR with fairly dense scientific content, but any feedback on code style etc would be appreciated.

Fixes #708

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

@jacobcook1995 jacobcook1995 linked an issue Feb 4, 2025 that may be closed by this pull request
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Feb 4, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.73%. Comparing base (185e4c9) to head (89c9e7c).

Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #724      +/-   ##
===========================================
+ Coverage    94.70%   94.73%   +0.02%     
===========================================
  Files           73       73              
  Lines         4946     4974      +28     
===========================================
+ Hits          4684     4712      +28     
  Misses         262      262              

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

Copy link
Copy Markdown
Collaborator

@dalonsoa dalonsoa left a comment

Choose a reason for hiding this comment

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

No idea about the science, but the code looks sensible. I've just made a couple of comments.

"leaf_turnover_c_p_ratio",
"plant_reproductive_tissue_turnover_c_p_ratio",
"root_turnover_c_p_ratio",
"nitrogen_fixation_carbon_supply",
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.

If this is initially populated by the plants model, it seems more reasonable to make the plants model own this process, I think. You have already mentioned this, so just supporting the idea.

Having said that, and looking at the code, I wonder why this needs to be initialised by the plants instead of the soil model. Is it to avoid an unfeasible model execution order or something like that?

Copy link
Copy Markdown
Collaborator Author

@jacobcook1995 jacobcook1995 Feb 6, 2025

Choose a reason for hiding this comment

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

I guess it needs to be populated by the plants model because this variable represents the amount of carbon plants are prepared to supply to microbes living in the soil to fix nitrogen. At the moment this is just a constant that gets passed from the plants model to the soil model, but down the line it should depend on plant productivity, which means the plant model will need to run before it can be populated.

I think down the line it might make sense for symbiotic nitrogen fixation to be represented within the plants module, because there is a grey area here about whose domain this falls into. But when me and @davidorme discussed it we thought it is best to have it contained in the soil model to begin with

:cite:t:`brzostek_modeling_2014`. As the function is not defined below zero degrees
celsius if a negative temperature is input an infinite cost is returned.

TODO - I could not sensibly convert this empirically derived function from Celsius
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.

It's a piecewise function with a cut-off threshold, so the way you have handled it seems totally reasonable specially considering that the input soil_temp is already in Celsius. I don't see any problem with it.

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.

Yeah I think this TODO more speaks to an anxiety I have about how a lot of the models I am drawing from make use of temperature, rather than anything wrong with the function implementation. I've made a broader issue for this #728, so I think it makes sense to make this a comment rather than a TODO

@jacobcook1995 jacobcook1995 merged commit ccc87e9 into develop Feb 6, 2025
@jacobcook1995 jacobcook1995 deleted the 708-add-functionality-for-nitrogen-fixation branch February 6, 2025 15:15
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.

Add functionality for nitrogen fixation

3 participants