Skip to content

823 dont allow rainfall to be negative#843

Merged
vgro merged 10 commits intodevelopfrom
823-dont-allow-rainfall-to-be-negative
May 8, 2025
Merged

823 dont allow rainfall to be negative#843
vgro merged 10 commits intodevelopfrom
823-dont-allow-rainfall-to-be-negative

Conversation

@vgro
Copy link
Copy Markdown
Collaborator

@vgro vgro commented May 7, 2025

This PR fixes negative rainfall and adds error logging if it should happen again. I had calculated the evaporation and leaf drainage from each canopy layer with the condition that this should not exceeds the interception pool. In the next step, I summed over all layers and subtracted that from the rainfall, I believe this was the problem. Now I sum first to make sure the sum is smaller than the available water.

Fixes #823

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

@vgro vgro linked an issue May 7, 2025 that may be closed by this pull request
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 7, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.76%. Comparing base (2ec7f4a) to head (8028cd3).
⚠️ Report is 2136 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop     #843   +/-   ##
========================================
  Coverage    94.75%   94.76%           
========================================
  Files           75       75           
  Lines         5550     5559    +9     
========================================
+ Hits          5259     5268    +9     
  Misses         291      291           

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

@vgro vgro requested review from jacobcook1995 and sallymatson May 7, 2025 16:46
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.

LGTM! The function to automatically catch this type of error if it occurs again feels like a really good idea for helping with calibration

@davidorme
Copy link
Copy Markdown
Collaborator

davidorme commented May 8, 2025

I think we should look again at implementing the bounds checking for this too - running the simulation in bounds checking mode would be really useful for calibration.

@vgro
Copy link
Copy Markdown
Collaborator Author

vgro commented May 8, 2025

I think we should look again at implementing the bounds checking for this too - running the simulation in bounds checking mode would be really useful for calibration.

I agree, but future problem :-)

error if precipitation is negative in any grid cell
"""
if (precipitation_surface < 0.0).any():
LOGGER.error("Surface precipitation should not be negative!")
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.

Question about this error message. Since (I believe) the precipitation is a calculated/derived value, how would a modeller reconcile this issue? Is it possible to point them to how to solve it (e.g. "Surface precipitation is negative. Consider checking XX input variable to reconcile.")

Also, should this be a fatal error? It seems here that this error will write to the log but not stop the simulation. But what will that mean going forward for the next runs?

Not requesting changes, just confirming that this is the best way to alert - I leave final judgement to you! And I guess if the simulation now prevents it, then maybe it's not necessary to change.

Copy link
Copy Markdown
Collaborator

@davidorme davidorme May 8, 2025

Choose a reason for hiding this comment

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

We've got a long-standing plan to implement something like this as broader bounds checking. This discussion is old (#135) but I think we'd now add hard or soft bounds data to variables.toml. Those are going to be useful values for users anyway, and then if we run in bounds mode, all changes to a variable in data can be bounds checked. Hard bounds raise, soft bounds warn.

But - as @vgro says: a problem for another day.

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.

Cool. Seems very valuable for calibration..... maybe something for me to work on once stochiometry is figured out.

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.

Good point, I agree that the simulation should stop when this happens and some more info should be given to solve the problem.

@vgro vgro merged commit fc8c6dc into develop May 8, 2025
16 checks passed
@vgro vgro deleted the 823-dont-allow-rainfall-to-be-negative branch May 8, 2025 12:06
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.

Don't allow rainfall to be negative

5 participants