Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@
('py:class', r'.*TraitType'),
('py:class', r'.*object providing a view on.*'), # Python dict docstring
('py:class', r'None. .*'), # Python dict docstring
('py:class', r'.*D\[k\].*'), # Python dict docstring
('py:class', r'.*D\[k\].*'), # Python dict docstring,
('py:class', r"({'liquid'|'solid'|'auto'})")
]

show_warning_types = True
Expand Down
287 changes: 219 additions & 68 deletions src/metpy/calc/thermo.py

Large diffs are not rendered by default.

33 changes: 33 additions & 0 deletions src/metpy/cbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,37 @@ def broadcast_indices(indices, shape, axis):
return tuple(ret)


def validate_choice(options, /, **kwargs):
r"""Confirm that a choice is contained within a set of options.

Parameters
----------
options : iterable

\*\*kwargs
Function kwarg names (keys) and their passed-in values (values) for validation

Raises
------
ValueError
If the choice is not contained within any of these options, present valid options

Examples
--------
>>> from metpy.cbook import validate_choice
>>> def try_wrong_choice(color=None):
... validate_choice({'blue', 'green', 'yellow'}, color=color)
>>> try_wrong_choice(color='red') # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
ValueError: 'red' is not a valid option for color.
Valid options are 'yellow', 'green', 'blue'.
"""
for kw, choice in kwargs.items():
if choice not in options:
raise ValueError(
f'{choice!r} is not a valid option for {kw}. '
f'Valid options are {", ".join(map(repr, options))}.'
)


__all__ = ('Registry', 'broadcast_indices', 'get_test_data')
10 changes: 5 additions & 5 deletions tests/calc/test_indices.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def test_precipitable_water():
"""Test precipitable water with observed sounding."""
data = get_upper_air_data(datetime(2016, 5, 22, 0), 'DDC')
pw = precipitable_water(data['pressure'], data['dewpoint'], top=400 * units.hPa)
truth = 22.60430651 * units.millimeters
truth = 22.58809193 * units.millimeters
assert_array_almost_equal(pw, truth, 4)


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


Expand All @@ -43,7 +43,7 @@ def test_precipitable_water_bound_error():
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,
-86.5, -88.1]) * units.degC
pw = precipitable_water(pressure, dewpoint)
truth = 89.86846252697836 * units('millimeters')
truth = 89.78451311253484 * units('millimeters')
assert_almost_equal(pw, truth, 5)


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


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


Expand Down
Loading