Skip to content

Commit 67d9211

Browse files
committed
Control zero humidity in thermo computations
1 parent c96026e commit 67d9211

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/earthkit/meteo/thermo/array/thermo.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,7 @@ def dewpoint_from_relative_humidity(t, r, eps=1e-8, out=None):
824824
td = temperature_from_saturation_vapour_pressure(es)
825825

826826
if out is not None and not np.isnan(out):
827+
td = np.asarray(td)
827828
td[mask] = out
828829

829830
return td
@@ -880,6 +881,7 @@ def dewpoint_from_specific_humidity(q, p, eps=1e-8, out=None):
880881
td = temperature_from_saturation_vapour_pressure(es)
881882

882883
if out is not None and not np.isnan(out):
884+
td = np.asarray(td)
883885
td[mask] = out
884886

885887
return td

tests/thermo/test_thermo_array.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,11 @@ def test_specific_humidity_from_relative_humidity():
485485
{"eps": 1e-3, "out": np.nan},
486486
[10, np.nan, np.nan],
487487
),
488+
(20.0, 52.5224541378, {}, 10.0),
489+
(20.0, 0.0, {"eps": 1e-3, "out": thermo.array.celsius_to_kelvin(100)}, 100),
490+
(20.0, 0.000001, {"eps": 1e-3, "out": thermo.array.celsius_to_kelvin(100)}, 100),
491+
(20.0, 0.0, {"eps": 1e-3, "out": np.nan}, np.nan),
492+
(20, 0.000001, {"eps": 1e-3, "out": np.nan}, np.nan),
488493
],
489494
)
490495
def test_dewpoint_from_relative_humidity(t, r, kwargs, expected_values):
@@ -536,6 +541,11 @@ def test_dewpoint_from_relative_humidity(t, r, kwargs, expected_values):
536541
{"eps": 1e-3, "out": np.nan},
537542
[21.78907, np.nan, np.nan],
538543
),
544+
(0.0169461501, 967.508, {}, 21.78907),
545+
(0.0, 967.5085, {"eps": 1e-3, "out": thermo.array.celsius_to_kelvin(100)}, 100),
546+
(0.000001, 967.5085, {"eps": 1e-3, "out": thermo.array.celsius_to_kelvin(100)}, 100),
547+
(0.0, 967.5085, {"eps": 1e-3, "out": np.nan}, np.nan),
548+
(0.000001, 967.5085, {"eps": 1e-3, "out": np.nan}, np.nan),
539549
],
540550
)
541551
def test_dewpoint_from_specific_humidity(q, p, kwargs, expected_values):

0 commit comments

Comments
 (0)