Skip to content

Commit b28b921

Browse files
authored
Merge pull request #3726 from dcamron/analytic-satvap
Ambaum 2020 saturation vapor pressure + phase handling
2 parents 0590946 + 4e7f362 commit b28b921

16 files changed

Lines changed: 501 additions & 273 deletions

docs/conf.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@
108108
('py:class', r'.*TraitType'),
109109
('py:class', r'.*object providing a view on.*'), # Python dict docstring
110110
('py:class', r'None. .*'), # Python dict docstring
111-
('py:class', r'.*D\[k\].*'), # Python dict docstring
111+
('py:class', r'.*D\[k\].*'), # Python dict docstring,
112+
('py:class', r"({'liquid'|'solid'|'auto'})")
112113
]
113114

114115
show_warning_types = True

src/metpy/calc/thermo.py

Lines changed: 219 additions & 68 deletions
Large diffs are not rendered by default.

src/metpy/cbook.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,37 @@ def broadcast_indices(indices, shape, axis):
129129
return tuple(ret)
130130

131131

132+
def validate_choice(options, /, **kwargs):
133+
r"""Confirm that a choice is contained within a set of options.
134+
135+
Parameters
136+
----------
137+
options : iterable
138+
139+
\*\*kwargs
140+
Function kwarg names (keys) and their passed-in values (values) for validation
141+
142+
Raises
143+
------
144+
ValueError
145+
If the choice is not contained within any of these options, present valid options
146+
147+
Examples
148+
--------
149+
>>> from metpy.cbook import validate_choice
150+
>>> def try_wrong_choice(color=None):
151+
... validate_choice({'blue', 'green', 'yellow'}, color=color)
152+
>>> try_wrong_choice(color='red') # doctest: +IGNORE_EXCEPTION_DETAIL
153+
Traceback (most recent call last):
154+
ValueError: 'red' is not a valid option for color.
155+
Valid options are 'yellow', 'green', 'blue'.
156+
"""
157+
for kw, choice in kwargs.items():
158+
if choice not in options:
159+
raise ValueError(
160+
f'{choice!r} is not a valid option for {kw}. '
161+
f'Valid options are {", ".join(map(repr, options))}.'
162+
)
163+
164+
132165
__all__ = ('Registry', 'broadcast_indices', 'get_test_data')

tests/calc/test_indices.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def test_precipitable_water():
2121
"""Test precipitable water with observed sounding."""
2222
data = get_upper_air_data(datetime(2016, 5, 22, 0), 'DDC')
2323
pw = precipitable_water(data['pressure'], data['dewpoint'], top=400 * units.hPa)
24-
truth = 22.60430651 * units.millimeters
24+
truth = 22.58809193 * units.millimeters
2525
assert_array_almost_equal(pw, truth, 4)
2626

2727

@@ -32,7 +32,7 @@ def test_precipitable_water_no_bounds():
3232
pressure = data['pressure']
3333
inds = pressure >= 400 * units.hPa
3434
pw = precipitable_water(pressure[inds], dewpoint[inds])
35-
truth = 22.60430651 * units.millimeters
35+
truth = 22.58809193 * units.millimeters
3636
assert_array_almost_equal(pw, truth, 4)
3737

3838

@@ -43,7 +43,7 @@ def test_precipitable_water_bound_error():
4343
dewpoint = np.array([25.5, 24.1, 23.1, 21.2, 21.1, 19.4, 19.2, 19.2, -87.1, -86.5, -86.5,
4444
-86.5, -88.1]) * units.degC
4545
pw = precipitable_water(pressure, dewpoint)
46-
truth = 89.86846252697836 * units('millimeters')
46+
truth = 89.78451311253484 * units('millimeters')
4747
assert_almost_equal(pw, truth, 5)
4848

4949

@@ -59,7 +59,7 @@ def test_precipitable_water_nans():
5959
-28.3, np.nan, -32.6, np.nan, -33.8, -35., -35.1, -38.1, -40.,
6060
-43.3, -44.6, -46.4, -47., -49.2, -50.7]) * units.degC
6161
pw = precipitable_water(pressure, dewpoint)
62-
truth = 4.003660322395436 * units.mm
62+
truth = 3.997385016573651 * units.mm
6363
assert_almost_equal(pw, truth, 5)
6464

6565

@@ -161,7 +161,7 @@ def test_precipitable_water_xarray():
161161
press = xr.DataArray(data['pressure'].m, attrs={'units': str(data['pressure'].units)})
162162
dewp = xr.DataArray(data['dewpoint'], dims=('press',), coords=(press,))
163163
pw = precipitable_water(press, dewp, top=400 * units.hPa)
164-
truth = 22.60430651 * units.millimeters
164+
truth = 22.58809193 * units.millimeters
165165
assert_almost_equal(pw, truth)
166166

167167

0 commit comments

Comments
 (0)