Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Protect against zero divisions in RH for cold T #230

Merged
merged 1 commit into from
Oct 14, 2024

Conversation

trontrytel
Copy link
Member

We are getting NaNs in RH for very low temperatures because our saturation vapor pressure is zero. For example

TD.saturation_vapor_pressure(tps, FT(30), TD.Ice()) = 0
TD.saturation_vapor_pressure(tps, FT(40), TD.Ice()) = 0
TD.saturation_vapor_pressure(tps, FT(50), TD.Ice()) = 4.16f-42

This PR adds a small number in the denominator to prevent that.

eps(Float32(0)) = 1.0f-45

Copy link

codecov bot commented Oct 14, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.40%. Comparing base (f6fc4c8) to head (7610265).
Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #230   +/-   ##
=======================================
  Coverage   90.40%   90.40%           
=======================================
  Files           9        9           
  Lines        1167     1167           
=======================================
  Hits         1055     1055           
  Misses        112      112           

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

Copy link
Member

@szy21 szy21 left a comment

Choose a reason for hiding this comment

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

Could we also limit relative humidity between 0 and 1, and add a test for saturation_vapor_pressure at cold temperature?

@trontrytel
Copy link
Member Author

Could we also limit relative humidity between 0 and 1, and add a test for saturation_vapor_pressure at cold temperature?

I can add the test. I thought that Tapio wanted to avoid actually clipping the RH.

Copy link
Member

@charleskawczynski charleskawczynski left a comment

Choose a reason for hiding this comment

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

This looks fine to me. I'm just wondering if we know or can know what inputs could lead to this? Is it dominated by temperature?

@szy21
Copy link
Member

szy21 commented Oct 14, 2024

Could we also limit relative humidity between 0 and 1, and add a test for saturation_vapor_pressure at cold temperature?

I can add the test. I thought that Tapio wanted to avoid actually clipping the RH.

I think @tapios wants to clip RH to 1 (because this won't prevent that)? Let's double check.

@trontrytel
Copy link
Member Author

This looks fine to me. I'm just wondering if we know or can know what inputs could lead to this? Is it dominated by temperature?

Yes, for T < 40K our parameterization for saturation vapor pressure returns zero Hence the nans

@charleskawczynski charleskawczynski added the Launch Buildkite Add label to launch Buildkite label Oct 14, 2024
@trontrytel
Copy link
Member Author

Lets wait for me to add the test

@tapios
Copy link
Contributor

tapios commented Oct 14, 2024

Could we also limit relative humidity between 0 and 1, and add a test for saturation_vapor_pressure at cold temperature?

I can add the test. I thought that Tapio wanted to avoid actually clipping the RH.

I think @tapios wants to clip RH to 1 (because this won't prevent that)? Let's double check.

I think clipping to <= 1 makes sense, provided (a) we document this clearly in the doc string, and (b) there is no case where we use this for microphysics and assessing supersaturation. @trontrytel Is there any reason we'd want to diagnose supersaturation here?

@trontrytel
Copy link
Member Author

I think clipping to <= 1 makes sense, provided (a) we document this clearly in the doc string, and (b) there is no case where we use this for microphysics and assessing supersaturation. @trontrytel Is there any reason we'd want to diagnose supersaturation here?

Sounds good. And no, I was just thinking that for debugging Atmos it might be easier to see the actual RH numbers we get from the division than to mask them with clipping. But we can always add saturation_excess to diagnostics if we need it.

Copy link
Member

@szy21 szy21 left a comment

Choose a reason for hiding this comment

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

Thanks! Just one more thing. Should we add the eps to relative humidity, or should we add it to saturation_vapor_pressure itself? I don't have a strong preference. The latter can prevent issues if we use saturation_vapor_pressure elsewhere, but we can also remember to limit it if we use it in the denominator.

@trontrytel
Copy link
Member Author

trontrytel commented Oct 14, 2024

I'm voting for adding it to RH only. The only reason why we need to do anything is because we are dividing by it here

@trontrytel trontrytel added this pull request to the merge queue Oct 14, 2024
@trontrytel
Copy link
Member Author

I'm going to try to merge it in, so that our nightly tiny AMIP can run with it. We can always revisit tomorrow, if we want to change something about the epsilon!

Merged via the queue into main with commit 8563eb6 Oct 14, 2024
23 of 24 checks passed
@szy21
Copy link
Member

szy21 commented Oct 14, 2024

Great. This issue may not show up in the nightly AMIP run now. I'll run one with 55km top later tonight, which will be more likely to have the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Launch Buildkite Add label to launch Buildkite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants