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

Control zero humidity in thermo computations #23

Merged
merged 3 commits into from
Nov 4, 2024

Conversation

sandorkertesz
Copy link
Collaborator

@sandorkertesz sandorkertesz commented Oct 31, 2024

Fixes #20

This PR adds the eps and out keyword arguments to

  • dewpoint_from_specific_humidity
  • dewpoint_from_relative_humidity
  • temperature_from_saturation_vapour_pressure

with the follwoing meaning (e.g. for dewpoint_from_specific_humidity):

def dewpoint_from_specific_humidity(q, p, eps=1e-8, out=None):
...
eps: number
        If ``out`` is not None, return ``out`` when ``q`` < ``eps``.
        If out is None, ``eps`` is ignored and return np.nan for ``q``
        values very close to zero.
out: number or None
        If not None, return ``out`` when ``q`` < ``eps``. If None, ``eps`` is
        ignored and return np.nan for ``q`` values very close to zero.

Examples:

>>> from earthkit.meteo.thermo import dewpoint_from_specific_humidity
>>> dewpoint_from_specific_humidity(0., 10000.)
np.nan
>>> dewpoint_from_specific_humidity(0., 10000, out=100)
100
>>> dewpoint_from_specific_humidity(1e-6, 10000, eps=1e-5, out=100)
100

@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.40%. Comparing base (d6175a8) to head (67d9211).

Additional details and impacted files
@@             Coverage Diff             @@
##           develop      #23      +/-   ##
===========================================
+ Coverage    99.38%   99.40%   +0.02%     
===========================================
  Files            8        8              
  Lines          647      672      +25     
  Branches        20       26       +6     
===========================================
+ Hits           643      668      +25     
  Misses           4        4              

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

@iainrussell
Copy link
Member

Looks like a nice mechanism! I wonder if the kwargs need to be a bit more descriptive, such as zero_q_eps and zero_q_out_value - what do you think @sandorkertesz?

@sandorkertesz
Copy link
Collaborator Author

sandorkertesz commented Nov 4, 2024

@iainrussell, I would like to keep it simple. Other, methods already use eps, while out is coming from numpy methods, e.g. np.log.

@sandorkertesz sandorkertesz merged commit 3b404c0 into develop Nov 4, 2024
102 checks passed
@sandorkertesz sandorkertesz deleted the feature/control-zero-humidity-in-thermo branch November 4, 2024 11:21
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.

Nan values in dewpoint_from_specific_humidity
3 participants