From 490f8f4988cba6148a4c39774044878208dd875a Mon Sep 17 00:00:00 2001 From: Sandor Kertesz Date: Tue, 23 Apr 2024 12:00:56 +0100 Subject: [PATCH] Implement array submodule --- earthkit/meteo/thermo/__init__.py | 163 +++++++++++++++- tests/thermo/test_thermo.py | 19 ++ .../test_thermo_array.py} | 174 +++++++++--------- 3 files changed, 269 insertions(+), 87 deletions(-) create mode 100644 tests/thermo/test_thermo.py rename tests/{test_thermo.py => thermo/test_thermo_array.py} (74%) diff --git a/earthkit/meteo/thermo/__init__.py b/earthkit/meteo/thermo/__init__.py index 8842a88..8b22e7e 100644 --- a/earthkit/meteo/thermo/__init__.py +++ b/earthkit/meteo/thermo/__init__.py @@ -1 +1,162 @@ -from .thermo import * # noqa +# (C) Copyright 2021- ECMWF. + +# This software is licensed under the terms of the Apache Licence Version 2.0 +# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. + +# In applying this licence, ECMWF does not waive the privileges and immunities granted to it by +# virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. + + +from . import thermo as array + + +def celsius_to_kelvin(*args, **kwargs): + return array.celsius_to_kelvin(*args, **kwargs) + + +def kelvin_to_celsius(*args, **kwargs): + return array.kelvin_to_celsius(*args, **kwargs) + + +def specific_humidity_from_mixing_ratio(*args, **kwargs): + return array.specific_humidity_from_mixing_ratio(*args, **kwargs) + + +def mixing_ratio_from_specific_humidity(*args, **kwargs): + return array.mixing_ratio_from_specific_humidity(*args, **kwargs) + + +def vapour_pressure_from_specific_humidity(*args, **kwargs): + return array.vapour_pressure_from_specific_humidity(*args, **kwargs) + + +def vapour_pressure_from_mixing_ratio(*args, **kwargs): + return array.vapour_pressure_from_mixing_ratio(*args, **kwargs) + + +def specific_humidity_from_vapour_pressure(*args, **kwargs): + return array.specific_humidity_from_vapour_pressure(*args, **kwargs) + + +def mixing_ratio_from_vapour_pressure(*args, **kwargs): + return array.mixing_ratio_from_vapour_pressure(*args, **kwargs) + + +def saturation_vapour_pressure(*args, **kwargs): + return array.saturation_vapour_pressure(*args, **kwargs) + + +def saturation_mixing_ratio(*args, **kwargs): + return array.saturation_mixing_ratio(*args, **kwargs) + + +def saturation_specific_humidity(*args, **kwargs): + return array.saturation_specific_humidity(*args, **kwargs) + + +def saturation_vapour_pressure_slope(*args, **kwargs): + return array.saturation_vapour_pressure_slope(*args, **kwargs) + + +def saturation_mixing_ratio_slope(*args, **kwargs): + return array.saturation_mixing_ratio_slope(*args, **kwargs) + + +def saturation_specific_humidity_slope(*args, **kwargs): + return array.saturation_specific_humidity_slope(*args, **kwargs) + + +def temperature_from_saturation_vapour_pressure(*args, **kwargs): + return array.temperature_from_saturation_vapour_pressure(*args, **kwargs) + + +def relative_humidity_from_dewpoint(*args, **kwargs): + return array.relative_humidity_from_dewpoint(*args, **kwargs) + + +def relative_humidity_from_specific_humidity(*args, **kwargs): + return array.relative_humidity_from_specific_humidity(*args, **kwargs) + + +def specific_humidity_from_dewpoint(*args, **kwargs): + return array.specific_humidity_from_dewpoint(*args, **kwargs) + + +def mixing_ratio_from_dewpoint(*args, **kwargs): + return array.mixing_ratio_from_dewpoint(*args, **kwargs) + + +def specific_humidity_from_relative_humidity(*args, **kwargs): + return array.specific_humidity_from_relative_humidity(*args, **kwargs) + + +def dewpoint_from_relative_humidity(*args, **kwargs): + return array.dewpoint_from_relative_humidity(*args, **kwargs) + + +def dewpoint_from_specific_humidity(*args, **kwargs): + return array.dewpoint_from_specific_humidity(*args, **kwargs) + + +def virtual_temperature(*args, **kwargs): + return array.virtual_temperature(*args, **kwargs) + + +def virtual_potential_temperature(*args, **kwargs): + return array.virtual_potential_temperature(*args, **kwargs) + + +def potential_temperature(*args, **kwargs): + return array.potential_temperature(*args, **kwargs) + + +def temperature_from_potential_temperature(*args, **kwargs): + return array.temperature_from_potential_temperature(*args, **kwargs) + + +def pressure_on_dry_adiabat(*args, **kwargs): + return array.pressure_on_dry_adiabat(*args, **kwargs) + + +def temperature_on_dry_adiabat(*args, **kwargs): + return array.temperature_on_dry_adiabat(*args, **kwargs) + + +def lcl_temperature(*args, **kwargs): + return array.lcl_temperature(*args, **kwargs) + + +def lcl(*args, **kwargs): + return array.lcl(*args, **kwargs) + + +def ept_from_dewpoint(*args, **kwargs): + return array.ept_from_dewpoint(*args, **kwargs) + + +def ept_from_specific_humidity(*args, **kwargs): + return array.ept_from_specific_humidity(*args, **kwargs) + + +def saturation_ept(*args, **kwargs): + return array.saturation_ept(*args, **kwargs) + + +def temperature_on_moist_adiabat(*args, **kwargs): + return array.temperature_on_moist_adiabat(*args, **kwargs) + + +def wet_bulb_temperature_from_dewpoint(*args, **kwargs): + return array.wet_bulb_temperature_from_dewpoint(*args, **kwargs) + + +def wet_bulb_temperature_from_specific_humidity(*args, **kwargs): + return array.wet_bulb_temperature_from_specific_humidity(*args, **kwargs) + + +def wet_bulb_potential_temperature_from_dewpoint(*args, **kwargs): + return array.wet_bulb_potential_temperature_from_dewpoint(*args, **kwargs) + + +def wet_bulb_potential_temperature_from_specific_humidity(*args, **kwargs): + return array.wet_bulb_potential_temperature_from_specific_humidity(*args, **kwargs) diff --git a/tests/thermo/test_thermo.py b/tests/thermo/test_thermo.py new file mode 100644 index 0000000..aa3dfc0 --- /dev/null +++ b/tests/thermo/test_thermo.py @@ -0,0 +1,19 @@ +# (C) Copyright 2023 ECMWF. +# +# This software is licensed under the terms of the Apache Licence Version 2.0 +# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. +# In applying this licence, ECMWF does not waive the privileges and immunities +# granted to it by virtue of its status as an intergovernmental organisation +# nor does it submit to any jurisdiction. + + +import numpy as np + +from earthkit.meteo import thermo + + +def test_high_level_celsius_to_kelvin(): + t = np.array([-10, 23.6]) + v = thermo.celsius_to_kelvin(t) + v_ref = np.array([263.16, 296.76]) + np.testing.assert_allclose(v, v_ref) diff --git a/tests/test_thermo.py b/tests/thermo/test_thermo_array.py similarity index 74% rename from tests/test_thermo.py rename to tests/thermo/test_thermo_array.py index 4cc5140..1879876 100644 --- a/tests/test_thermo.py +++ b/tests/thermo/test_thermo_array.py @@ -16,7 +16,7 @@ def data_file(name): - return os.path.join(os.path.dirname(__file__), "data", name) + return os.path.join(os.path.dirname(os.path.dirname(__file__)), "data", name) def save_test_reference(file_name, data): @@ -49,28 +49,28 @@ def __init__(self, file_name="t_hum_p_data.csv"): def test_celsius_to_kelvin(): t = np.array([-10, 23.6]) - v = thermo.celsius_to_kelvin(t) + v = thermo.array.celsius_to_kelvin(t) v_ref = np.array([263.16, 296.76]) np.testing.assert_allclose(v, v_ref) def test_kelvin_to_celsius(): t = np.array([263.16, 296.76]) - v = thermo.kelvin_to_celsius(t) + v = thermo.array.kelvin_to_celsius(t) v_ref = np.array([-10, 23.6]) np.testing.assert_allclose(v, v_ref) def test_mixing_ratio_from_specific_humidity(): q = np.array([0.008, 0.018]) - mr = thermo.mixing_ratio_from_specific_humidity(q) + mr = thermo.array.mixing_ratio_from_specific_humidity(q) v_ref = np.array([0.0080645161, 0.0183299389]) np.testing.assert_allclose(mr, v_ref, rtol=1e-7) def test_specific_humidity_from_mixing_ratio(): mr = np.array([0.0080645161, 0.0183299389]) - q = thermo.specific_humidity_from_mixing_ratio(mr) + q = thermo.array.specific_humidity_from_mixing_ratio(mr) v_ref = np.array([0.008, 0.018]) np.testing.assert_allclose(q, v_ref, rtol=1e-07) @@ -79,7 +79,7 @@ def test_vapour_pressure_from_specific_humidity(): q = np.array([0.008, 0.018]) p = np.array([700, 1000]) * 100 v_ref = np.array([895.992614, 2862.662152]) - vp = thermo.vapour_pressure_from_specific_humidity(q, p) + vp = thermo.array.vapour_pressure_from_specific_humidity(q, p) np.testing.assert_allclose(vp, v_ref) @@ -87,7 +87,7 @@ def test_vapour_pressure_from_mixing_ratio(): mr = np.array([0.0080645161, 0.0183299389]) p = np.array([700, 1000]) * 100 v_ref = np.array([895.992614, 2862.662152]) - vp = thermo.vapour_pressure_from_mixing_ratio(mr, p) + vp = thermo.array.vapour_pressure_from_mixing_ratio(mr, p) np.testing.assert_allclose(vp, v_ref) @@ -95,27 +95,27 @@ def test_specific_humidity_from_vapour_pressure(): vp = np.array([895.992614, 2862.662152, 10000]) p = np.array([700, 1000, 50]) * 100 v_ref = np.array([0.008, 0.018, np.nan]) - q = thermo.specific_humidity_from_vapour_pressure(vp, p) + q = thermo.array.specific_humidity_from_vapour_pressure(vp, p) np.testing.assert_allclose(q, v_ref) # single pressure value vp = np.array([895.992614, 2862.662152, 100000]) p = 700 * 100.0 v_ref = np.array([0.008, 0.0258354146, np.nan]) - q = thermo.specific_humidity_from_vapour_pressure(vp, p) + q = thermo.array.specific_humidity_from_vapour_pressure(vp, p) np.testing.assert_allclose(q, v_ref) # numbers vp = 895.992614 p = 700 * 100.0 v_ref = 0.008 - q = thermo.specific_humidity_from_vapour_pressure(vp, p) + q = thermo.array.specific_humidity_from_vapour_pressure(vp, p) np.testing.assert_allclose(q, v_ref) vp = 100000 p = 700 * 100.0 v_ref = np.nan - q = thermo.specific_humidity_from_vapour_pressure(vp, p) + q = thermo.array.specific_humidity_from_vapour_pressure(vp, p) np.testing.assert_allclose(q, v_ref) @@ -123,20 +123,20 @@ def test_mixing_ratio_from_vapour_pressure(): vp = np.array([895.992614, 2862.662152, 100000]) p = np.array([700, 1000, 50]) * 100 v_ref = np.array([0.0080645161, 0.0183299389, np.nan]) - mr = thermo.mixing_ratio_from_vapour_pressure(vp, p) + mr = thermo.array.mixing_ratio_from_vapour_pressure(vp, p) np.testing.assert_allclose(mr, v_ref, rtol=1e-07) # numbers vp = 895.992614 p = 700 * 100.0 v_ref = 0.0080645161 - q = thermo.mixing_ratio_from_vapour_pressure(vp, p) + q = thermo.array.mixing_ratio_from_vapour_pressure(vp, p) np.testing.assert_allclose(q, v_ref) vp = 100000.0 p = 50 * 100.0 v_ref = np.nan - q = thermo.mixing_ratio_from_vapour_pressure(vp, p) + q = thermo.array.mixing_ratio_from_vapour_pressure(vp, p) np.testing.assert_allclose(q, v_ref) @@ -144,9 +144,9 @@ def test_saturation_vapour_pressure(): ref_file = "sat_vp.csv" phases = ["mixed", "water", "ice"] - # o = {"t": thermo.celsius_to_kelvin(np.linspace(-40.0, 56.0, 49))} + # o = {"t": thermo.array.celsius_to_kelvin(np.linspace(-40.0, 56.0, 49))} # for phase in ["mixed", "water", "ice"]: - # o[phase] = thermo.saturation_vapour_pressure(o["t"], phase=phase) + # o[phase] = thermo.array.saturation_vapour_pressure(o["t"], phase=phase) # save_test_reference(ref_file, o) d = np.genfromtxt( @@ -156,7 +156,7 @@ def test_saturation_vapour_pressure(): ) for phase in phases: - svp = thermo.saturation_vapour_pressure(d["t"], phase=phase) + svp = thermo.array.saturation_vapour_pressure(d["t"], phase=phase) np.testing.assert_allclose(svp, d[phase]) # scalar value @@ -167,7 +167,7 @@ def test_saturation_vapour_pressure(): "ice": 3.685208149695831139e02, } for phase, v in v_ref.items(): - svp = thermo.saturation_vapour_pressure(t, phase=phase) + svp = thermo.array.saturation_vapour_pressure(t, phase=phase) np.testing.assert_allclose(svp, v) @@ -175,14 +175,14 @@ def test_saturation_mixing_ratio(): ref_file = "sat_mr.csv" phases = ["mixed", "water", "ice"] - # t = thermo.celsius_to_kelvin(np.linspace(-40.0, 56.0, 25)) + # t = thermo.array.celsius_to_kelvin(np.linspace(-40.0, 56.0, 25)) # p = [1000, 950, 850, 700] # t_num = len(t) # t = np.repeat(t, repeats=len(p)) # p = np.array(p * t_num) * 100.0 # o = {"t": t, "p": p} # for phase in ["mixed", "water", "ice"]: - # o[phase] = thermo.saturation_mixing_ratio(t, p, phase=phase) + # o[phase] = thermo.array.saturation_mixing_ratio(t, p, phase=phase) # save_test_reference(ref_file, o) d = np.genfromtxt( @@ -192,7 +192,7 @@ def test_saturation_mixing_ratio(): ) for phase in phases: - mr = thermo.saturation_mixing_ratio(d["t"], d["p"], phase=phase) + mr = thermo.array.saturation_mixing_ratio(d["t"], d["p"], phase=phase) np.testing.assert_allclose(mr, d[phase]) @@ -200,14 +200,14 @@ def test_saturation_specific_humidity(): ref_file = "sat_q.csv" phases = ["mixed", "water", "ice"] - # t = thermo.celsius_to_kelvin(np.linspace(-40.0, 56.0, 25)) + # t = thermo.array.celsius_to_kelvin(np.linspace(-40.0, 56.0, 25)) # p = [1000, 950, 850, 700] # t_num = len(t) # t = np.repeat(t, repeats=len(p)) # p = np.array(p * t_num) * 100.0 # o = {"t": t, "p": p} # for phase in ["mixed", "water", "ice"]: - # o[phase] = thermo.saturation_specific_humidity(t, p, phase=phase) + # o[phase] = thermo.array.saturation_specific_humidity(t, p, phase=phase) # save_test_reference(ref_file, o) d = np.genfromtxt( @@ -217,7 +217,7 @@ def test_saturation_specific_humidity(): ) for phase in phases: - mr = thermo.saturation_specific_humidity(d["t"], d["p"], phase=phase) + mr = thermo.array.saturation_specific_humidity(d["t"], d["p"], phase=phase) np.testing.assert_allclose(mr, d[phase]) @@ -225,9 +225,9 @@ def test_saturation_vapour_pressure_slope(): ref_file = "sat_vp_slope.csv" phases = ["mixed", "water", "ice"] - # o = {"t": thermo.celsius_to_kelvin(np.linspace(-40.0, 56.0, 49))} + # o = {"t": thermo.array.celsius_to_kelvin(np.linspace(-40.0, 56.0, 49))} # for phase in ["mixed", "water", "ice"]: - # o[phase] = thermo.saturation_vapour_pressure_slope(o["t"], phase=phase) + # o[phase] = thermo.array.saturation_vapour_pressure_slope(o["t"], phase=phase) # save_test_reference(ref_file, o) d = np.genfromtxt( @@ -237,7 +237,7 @@ def test_saturation_vapour_pressure_slope(): ) for phase in phases: - svp = thermo.saturation_vapour_pressure_slope(d["t"], phase=phase) + svp = thermo.array.saturation_vapour_pressure_slope(d["t"], phase=phase) np.testing.assert_allclose(svp, d[phase]) @@ -245,14 +245,14 @@ def test_saturation_mixing_ratio_slope(): ref_file = "sat_mr_slope.csv" phases = ["mixed", "water", "ice"] - # t = thermo.celsius_to_kelvin(np.linspace(-40.0, 56.0, 25)) + # t = thermo.array.celsius_to_kelvin(np.linspace(-40.0, 56.0, 25)) # p = [1000, 950, 850, 700] # t_num = len(t) # t = np.repeat(t, repeats=len(p)) # p = np.array(p * t_num) * 100.0 # o = {"t": t, "p": p} # for phase in ["mixed", "water", "ice"]: - # o[phase] = thermo.saturation_mixing_ratio_slope(t, p, phase=phase) + # o[phase] = thermo.array.saturation_mixing_ratio_slope(t, p, phase=phase) # save_test_reference(ref_file, o) d = np.genfromtxt( @@ -262,13 +262,13 @@ def test_saturation_mixing_ratio_slope(): ) for phase in phases: - svp = thermo.saturation_mixing_ratio_slope(d["t"], d["p"], phase=phase) + svp = thermo.array.saturation_mixing_ratio_slope(d["t"], d["p"], phase=phase) np.testing.assert_allclose(svp, d[phase]) v_ref = np.array([np.nan]) - t = thermo.celsius_to_kelvin(np.array([200])) + t = thermo.array.celsius_to_kelvin(np.array([200])) p = np.array([1000]) - svp = thermo.saturation_mixing_ratio_slope(t, p, phase="mixed") + svp = thermo.array.saturation_mixing_ratio_slope(t, p, phase="mixed") np.testing.assert_allclose(svp, v_ref) # numbers @@ -276,7 +276,7 @@ def test_saturation_mixing_ratio_slope(): p = [1e5, 1e5] v_ref = [0.0005189819, np.nan] for i in range(len(t)): - svp = thermo.saturation_mixing_ratio_slope(t[i], p[i], phase="mixed") + svp = thermo.array.saturation_mixing_ratio_slope(t[i], p[i], phase="mixed") np.testing.assert_allclose(svp, v_ref[i]) @@ -284,14 +284,14 @@ def test_saturation_specific_humidity_slope(): ref_file = "sat_q_slope.csv" phases = ["mixed", "water", "ice"] - # t = thermo.celsius_to_kelvin(np.linspace(-40.0, 56.0, 25)) + # t = thermo.array.celsius_to_kelvin(np.linspace(-40.0, 56.0, 25)) # p = [1000, 950, 850, 700] # t_num = len(t) # t = np.repeat(t, repeats=len(p)) # p = np.array(p * t_num) * 100.0 # o = {"t": t, "p": p} # for phase in ["mixed", "water", "ice"]: - # o[phase] = thermo.saturation_specific_humidity_slope(t, p, phase=phase) + # o[phase] = thermo.array.saturation_specific_humidity_slope(t, p, phase=phase) # save_test_reference(ref_file, o) d = np.genfromtxt( @@ -301,13 +301,15 @@ def test_saturation_specific_humidity_slope(): ) for phase in phases: - svp = thermo.saturation_specific_humidity_slope(d["t"], d["p"], phase=phase) + svp = thermo.array.saturation_specific_humidity_slope( + d["t"], d["p"], phase=phase + ) np.testing.assert_allclose(svp, d[phase]) v_ref = np.array([np.nan]) - t = thermo.celsius_to_kelvin(np.array([200])) + t = thermo.array.celsius_to_kelvin(np.array([200])) p = np.array([1000]) - svp = thermo.saturation_specific_humidity_slope(t, p, phase="mixed") + svp = thermo.array.saturation_specific_humidity_slope(t, p, phase="mixed") np.testing.assert_allclose(svp, v_ref) # numbers @@ -315,7 +317,7 @@ def test_saturation_specific_humidity_slope(): p = [1e5, 1e5] v_ref = [0.0005111349, np.nan] for i in range(len(t)): - svp = thermo.saturation_specific_humidity_slope(t[i], p[i], phase="mixed") + svp = thermo.array.saturation_specific_humidity_slope(t[i], p[i], phase="mixed") np.testing.assert_allclose(svp, v_ref[i]) @@ -327,13 +329,13 @@ def test_temperature_from_saturation_vapour_pressure(): names=True, ) - t = thermo.temperature_from_saturation_vapour_pressure(d["water"]) + t = thermo.array.temperature_from_saturation_vapour_pressure(d["water"]) np.testing.assert_allclose(t, d["t"]) def test_relative_humidity_from_dewpoint(): - t = thermo.celsius_to_kelvin(np.array([20.0, 20, 0, 35, 5, -15, 25])) - td = thermo.celsius_to_kelvin(np.array([20.0, 10, -10, 32, -15, -24, -3])) + t = thermo.array.celsius_to_kelvin(np.array([20.0, 20, 0, 35, 5, -15, 25])) + td = thermo.array.celsius_to_kelvin(np.array([20.0, 10, -10, 32, -15, -24, -3])) # reference was tested with an online relhum calculator at: # https://bmcnoldy.rsmas.miami.edu/Humidity.html v_ref = np.array( @@ -347,12 +349,12 @@ def test_relative_humidity_from_dewpoint(): 15.4779832381, ] ) - r = thermo.relative_humidity_from_dewpoint(t, td) + r = thermo.array.relative_humidity_from_dewpoint(t, td) np.testing.assert_allclose(r, v_ref, rtol=1e-05) def test_relative_humidity_from_specific_humidity(): - t = thermo.celsius_to_kelvin( + t = thermo.array.celsius_to_kelvin( np.array([-29.2884, -14.4118, -5.9235, 9.72339, 18.4514]) ) p = np.array([300, 400, 500, 700, 850]) * 100.0 @@ -374,12 +376,12 @@ def test_relative_humidity_from_specific_humidity(): 73.41420898756694, ] ) - r = thermo.relative_humidity_from_specific_humidity(t, q, p) + r = thermo.array.relative_humidity_from_specific_humidity(t, q, p) np.testing.assert_allclose(r, v_ref) def test_specific_humidity_from_dewpoint(): - td = thermo.celsius_to_kelvin( + td = thermo.array.celsius_to_kelvin( np.array([21.78907, 19.90885, 16.50236, 7.104064, -0.3548709, -16.37916]) ) p = np.array([967.5085, 936.3775, 872.248, 756.1647, 649.157, 422.4207]) * 100 @@ -393,12 +395,12 @@ def test_specific_humidity_from_dewpoint(): 0.0025150791, ] ) - q = thermo.specific_humidity_from_dewpoint(td, p) + q = thermo.array.specific_humidity_from_dewpoint(td, p) np.testing.assert_allclose(q, v_ref, rtol=1e-05) def test_specific_humidity_from_relative_humidity(): - t = thermo.celsius_to_kelvin( + t = thermo.array.celsius_to_kelvin( np.array([-29.2884, -14.4118, -5.9235, 9.72339, 18.4514]) ) p = np.array([300, 400, 500, 700, 850]) * 100.0 @@ -420,12 +422,12 @@ def test_specific_humidity_from_relative_humidity(): 0.0114808182580539, ] ) - q = thermo.specific_humidity_from_relative_humidity(t, r, p) + q = thermo.array.specific_humidity_from_relative_humidity(t, r, p) np.testing.assert_allclose(q, v_ref) def test_dewpoint_from_relative_humidity(): - t = thermo.celsius_to_kelvin(np.array([20.0, 20, 0, 35, 5, -15, 25])) + t = thermo.array.celsius_to_kelvin(np.array([20.0, 20, 0, 35, 5, -15, 25])) r = np.array( [ 100.0000000000, @@ -437,10 +439,10 @@ def test_dewpoint_from_relative_humidity(): 15.4779832381, ] ) - v_ref = thermo.celsius_to_kelvin(np.array([20.0, 10, -10, 32, -15, -24, -3])) + v_ref = thermo.array.celsius_to_kelvin(np.array([20.0, 10, -10, 32, -15, -24, -3])) # reference was tested with an online relhum calculator at: # https://bmcnoldy.rsmas.miami.edu/Humidity.html - td = thermo.dewpoint_from_relative_humidity(t, r) + td = thermo.array.dewpoint_from_relative_humidity(t, r) np.testing.assert_allclose(td, v_ref) @@ -456,10 +458,10 @@ def test_dewpoint_from_specific_humidity(): 0.0025150791, ] ) - v_ref = thermo.celsius_to_kelvin( + v_ref = thermo.array.celsius_to_kelvin( np.array([21.78907, 19.90885, 16.50236, 7.104064, -0.3548709, -16.37916]) ) - td = thermo.dewpoint_from_specific_humidity(q, p) + td = thermo.array.dewpoint_from_specific_humidity(q, p) np.testing.assert_allclose(td, v_ref) @@ -468,7 +470,7 @@ def test_virtual_temperature(): # w = np.array([0.02, 0.03]) q = np.array([0.0196078431, 0.0291262136]) v_ref = np.array([289.8130240470, 298.5937453245]) - tv = thermo.virtual_temperature(t, q) + tv = thermo.array.virtual_temperature(t, q) np.testing.assert_allclose(tv, v_ref) @@ -478,7 +480,7 @@ def test_virtual_potential_temperature_temperature(): q = np.array([0.0196078431, 0.0291262136]) p = np.array([100300.0, 95000.0]) v_ref = np.array([289.5651110613, 303.0015650834]) - tv = thermo.virtual_potential_temperature(t, q, p) + tv = thermo.array.virtual_potential_temperature(t, q, p) np.testing.assert_allclose(tv, v_ref) @@ -486,7 +488,7 @@ def test_potential_temperature(): t = np.array([252.16, 298.16]) p = np.array([72350, 100500]) v_ref = np.array([276.588026, 297.735455]) - th = thermo.potential_temperature(t, p) + th = thermo.array.potential_temperature(t, p) np.testing.assert_allclose(th, v_ref) @@ -494,7 +496,7 @@ def test_temperature_from_potential_temperature(): p = np.array([72350, 100500]) th = np.array([276.588026, 297.735455]) v_ref = np.array([252.16, 298.16]) - t = thermo.temperature_from_potential_temperature(th, p) + t = thermo.array.temperature_from_potential_temperature(th, p) np.testing.assert_allclose(t, v_ref) @@ -503,17 +505,17 @@ def test_temperature_on_dry_adibat(): p_def = np.array([72350, 100500]) p = np.array([700, 500]) * 100 v_ref = np.array([249.792414, 244.246863]) - t = thermo.temperature_on_dry_adiabat(p, t_def, p_def) + t = thermo.array.temperature_on_dry_adiabat(p, t_def, p_def) np.testing.assert_allclose(t, v_ref) # cross checking - th1 = thermo.potential_temperature(t_def, p_def) - th2 = thermo.potential_temperature(t, p) + th1 = thermo.array.potential_temperature(t_def, p_def) + th2 = thermo.array.potential_temperature(t, p) np.testing.assert_allclose(th1, th2) # multiple values along a single adiabat v_ref = np.array([249.792414, 226.898581]) - t = thermo.temperature_on_dry_adiabat(p, t_def[0], p_def[0]) + t = thermo.array.temperature_on_dry_adiabat(p, t_def[0], p_def[0]) np.testing.assert_allclose(t, v_ref) @@ -522,17 +524,17 @@ def test_pressure_on_dry_adibat(): p_def = np.array([72350, 100500]) t = np.array([249.792414, 244.246863]) v_ref = np.array([700, 500]) * 100 - p = thermo.pressure_on_dry_adiabat(t, t_def, p_def) + p = thermo.array.pressure_on_dry_adiabat(t, t_def, p_def) np.testing.assert_allclose(p, v_ref) # cross checking - th1 = thermo.potential_temperature(t_def, p_def) - th2 = thermo.potential_temperature(t, p) + th1 = thermo.array.potential_temperature(t_def, p_def) + th2 = thermo.array.potential_temperature(t, p) np.testing.assert_allclose(th1, th2) # multiple values along a single adiabat v_ref = np.array([70000, 64709.699161]) - p = thermo.pressure_on_dry_adiabat(t, t_def[0], p_def[0]) + p = thermo.array.pressure_on_dry_adiabat(t, t_def[0], p_def[0]) np.testing.assert_allclose(p, v_ref) @@ -544,18 +546,18 @@ def test_lcl(): # davies t_ref = np.array([268.706024, 298.200936, 270.517934, 303.138144]) p_ref = np.array([79081.766347, 94862.350635, 57999.83367, 112654.210439]) - t_lcl = thermo.lcl_temperature(t, td, method="davies") + t_lcl = thermo.array.lcl_temperature(t, td, method="davies") np.testing.assert_allclose(t_lcl, t_ref) - t_lcl, p_lcl = thermo.lcl(t, td, p, method="davies") + t_lcl, p_lcl = thermo.array.lcl(t, td, p, method="davies") np.testing.assert_allclose(t_lcl, t_ref) np.testing.assert_allclose(p_lcl, p_ref) # bolton t_ref = np.array([268.683018, 298.182282, 270.531264, 303.199544]) p_ref = np.array([79058.068785, 94841.581142, 58009.838027, 112734.100243]) - t_lcl = thermo.lcl_temperature(t, td, method="bolton") + t_lcl = thermo.array.lcl_temperature(t, td, method="bolton") np.testing.assert_allclose(t_lcl, t_ref) - t_lcl, p_lcl = thermo.lcl(t, td, p, method="bolton") + t_lcl, p_lcl = thermo.array.lcl(t, td, p, method="bolton") np.testing.assert_allclose(t_lcl, t_ref) np.testing.assert_allclose(p_lcl, p_ref) @@ -568,8 +570,8 @@ def test_ept(): # o = {} # for m in methods: - # o[f"{m}_td"] = thermo.ept_from_dewpoint(data.t, data.td, data.p, method=m) - # o[f"{m}_q"] = thermo.ept_from_specific_humidity( + # o[f"{m}_td"] = thermo.array.ept_from_dewpoint(data.t, data.td, data.p, method=m) + # o[f"{m}_q"] = thermo.array.ept_from_specific_humidity( # data.t, data.q, data.p, method=m # ) # save_test_reference(ref_file, o) @@ -581,9 +583,9 @@ def test_ept(): ) for m in methods: - pt = thermo.ept_from_dewpoint(data.t, data.td, data.p, method=m) + pt = thermo.array.ept_from_dewpoint(data.t, data.td, data.p, method=m) np.testing.assert_allclose(pt, ref[m + "_td"], err_msg=f"method={m}") - pt = thermo.ept_from_specific_humidity(data.t, data.q, data.p, method=m) + pt = thermo.array.ept_from_specific_humidity(data.t, data.q, data.p, method=m) np.testing.assert_allclose(pt, ref[m + "_q"], err_msg=f"method={m}") @@ -595,7 +597,7 @@ def test_saturation_ept(): # o = {} # for m in methods: - # o[m] = thermo.saturation_ept(data.t, data.p, method=m) + # o[m] = thermo.array.saturation_ept(data.t, data.p, method=m) # save_test_reference(ref_file, o) ref = np.genfromtxt( @@ -605,7 +607,7 @@ def test_saturation_ept(): ) for m in methods: - pt = thermo.saturation_ept(data.t, data.p, method=m) + pt = thermo.array.saturation_ept(data.t, data.p, method=m) np.testing.assert_allclose(pt, ref[m], err_msg=f"method={m}") @@ -619,7 +621,7 @@ def test_temperature_on_moist_adiabat(): # o = {"ept": np.repeat(ept, repeats=len(p)), "p": np.array(p.tolist() * len(ept))} # for m_ept in ept_methods: # for m_t in t_methods: - # o[f"{m_ept}_{m_t}"] = thermo.temperature_on_moist_adiabat( + # o[f"{m_ept}_{m_t}"] = thermo.array.temperature_on_moist_adiabat( # o["ept"], o["p"], ept_method=m_ept, t_method=m_t # ) # save_test_reference(ref_file, o) @@ -632,7 +634,7 @@ def test_temperature_on_moist_adiabat(): for m_ept in ept_methods: for m_t in t_methods: - pt = thermo.thermo.temperature_on_moist_adiabat( + pt = thermo.array.temperature_on_moist_adiabat( ref["ept"], ref["p"], ept_method=m_ept, t_method=m_t ) np.testing.assert_allclose( @@ -650,10 +652,10 @@ def test_wet_bulb_temperature(): # o = {} # for m_ept in ept_methods: # for m_t in t_methods: - # o[f"{m_ept}_{m_t}_td"] = thermo.wet_bulb_temperature_from_dewpoint( + # o[f"{m_ept}_{m_t}_td"] = thermo.array.wet_bulb_temperature_from_dewpoint( # data.t, data.td, data.p, ept_method=m_ept, t_method=m_t # ) - # o[f"{m_ept}_{m_t}_q"] = thermo.wet_bulb_temperature_from_specific_humidity( + # o[f"{m_ept}_{m_t}_q"] = thermo.array.wet_bulb_temperature_from_specific_humidity( # data.t, data.q, data.p, ept_method=m_ept, t_method=m_t # ) # save_test_reference(ref_file, o) @@ -666,7 +668,7 @@ def test_wet_bulb_temperature(): for m_ept in ept_methods: for m_t in t_methods: - pt = thermo.wet_bulb_temperature_from_dewpoint( + pt = thermo.array.wet_bulb_temperature_from_dewpoint( data.t, data.td, data.p, ept_method=m_ept, t_method=m_t ) np.testing.assert_allclose( @@ -676,7 +678,7 @@ def test_wet_bulb_temperature(): atol=0, err_msg=f"method={m_ept}_{m_t}_td", ) - pt = thermo.wet_bulb_temperature_from_specific_humidity( + pt = thermo.array.wet_bulb_temperature_from_specific_humidity( data.t, data.q, data.p, ept_method=m_ept, t_method=m_t ) np.testing.assert_allclose( @@ -700,12 +702,12 @@ def test_wet_bulb_potential_temperature(): # for m_t in t_methods: # o[ # f"{m_ept}_{m_t}_td" - # ] = thermo.wet_bulb_potential_temperature_from_dewpoint( + # ] = thermo.array.wet_bulb_potential_temperature_from_dewpoint( # data.t, data.td, data.p, ept_method=m_ept, t_method=m_t # ) # o[ # f"{m_ept}_{m_t}_q" - # ] = thermo.wet_bulb_potential_temperature_from_specific_humidity( + # ] = thermo.array.wet_bulb_potential_temperature_from_specific_humidity( # data.t, data.q, data.p, ept_method=m_ept, t_method=m_t # ) # save_test_reference(ref_file, o) @@ -718,7 +720,7 @@ def test_wet_bulb_potential_temperature(): for m_ept in ept_methods: for m_t in t_methods: - pt = thermo.wet_bulb_potential_temperature_from_dewpoint( + pt = thermo.array.wet_bulb_potential_temperature_from_dewpoint( data.t, data.td, data.p, ept_method=m_ept, t_method=m_t ) np.testing.assert_allclose( @@ -728,7 +730,7 @@ def test_wet_bulb_potential_temperature(): atol=0, err_msg=f"method={m_ept}_{m_t}_td", ) - pt = thermo.wet_bulb_potential_temperature_from_specific_humidity( + pt = thermo.array.wet_bulb_potential_temperature_from_specific_humidity( data.t, data.q, data.p, ept_method=m_ept, t_method=m_t ) np.testing.assert_allclose(