Skip to content

Commit

Permalink
Deprecate tmpk_out in favor of temperature_out in `isentropic_int…
Browse files Browse the repository at this point in the history
…erpolation`
  • Loading branch information
zbruick committed Aug 16, 2019
1 parent 2e1ed32 commit 5b22457
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
21 changes: 19 additions & 2 deletions metpy/calc/tests/test_thermo.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
virtual_potential_temperature, virtual_temperature,
wet_bulb_temperature)
from metpy.calc.thermo import _find_append_zero_crossings
from metpy.deprecation import MetpyDeprecationWarning
from metpy.testing import assert_almost_equal, assert_array_almost_equal, assert_nan
from metpy.units import units

Expand Down Expand Up @@ -824,7 +825,23 @@ def test_isentropic_pressure_tmp_out():
tmp[3, :] = 288.
tmpk = tmp * units.kelvin
isentlev = [296.] * units.kelvin
isentprs = isentropic_interpolation(isentlev, lev, tmpk, tmpk_out=True)
isentprs = isentropic_interpolation(isentlev, lev, tmpk, temperature_out=True)
truetmp = 296. * units.kelvin
assert_almost_equal(isentprs[1], truetmp, 3)


def test_isentropic_pressure_tmpk_out_deprecation():
"""Test deprecation warning of `tmpk_out`."""
lev = [100000., 95000., 90000., 85000.] * units.Pa
tmp = np.ones((4, 5, 5))
tmp[0, :] = 296.
tmp[1, :] = 292.
tmp[2, :] = 290.
tmp[3, :] = 288.
tmpk = tmp * units.kelvin
isentlev = [296.] * units.kelvin
with pytest.warns(MetpyDeprecationWarning):
isentprs = isentropic_interpolation(isentlev, lev, tmpk, tmpk_out=True)
truetmp = 296. * units.kelvin
assert_almost_equal(isentprs[1], truetmp, 3)

Expand Down Expand Up @@ -896,7 +913,7 @@ def test_isentropic_pressure_tmp_out_interp():
tmp[3, :] = 288.
tmpk = tmp * units.kelvin
isentlev = [296., 297.] * units.kelvin
isentprs = isentropic_interpolation(isentlev, lev, tmpk, tmpk_out=True)
isentprs = isentropic_interpolation(isentlev, lev, tmpk, temperature_out=True)
truetmp = 291.4579 * units.kelvin
assert_almost_equal(isentprs[1][1], truetmp, 3)

Expand Down
17 changes: 13 additions & 4 deletions metpy/calc/thermo.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
find_intersections, first_derivative, get_layer)
from .. import constants as mpconsts
from ..cbook import broadcast_indices
from ..deprecation import metpyDeprecation
from ..interpolate.one_dimension import interpolate_1d
from ..package_tools import Exporter
from ..units import atleast_1d, check_units, concatenate, units
Expand Down Expand Up @@ -1571,7 +1572,7 @@ def isentropic_interpolation(theta_levels, pressure, temperature, *args, **kwarg
----------------
axis : int, optional
The axis corresponding to the vertical in the temperature array, defaults to 0.
tmpk_out : bool, optional
temperature_out : bool, optional
If true, will calculate temperature and output as the last item in the output list.
Defaults to False.
max_iters : int, optional
Expand All @@ -1591,6 +1592,9 @@ def isentropic_interpolation(theta_levels, pressure, temperature, *args, **kwarg
[Ziv1994]_. Any additional arguments are assumed to vary linearly with temperature and will
be linearly interpolated to the new isentropic levels.
`isentropic_interpolation` previously accepted `tmpk_out` as an argument. That has been
deprecated in 0.11 in favor of `temperature_out` and support will end in 1.0.
See Also
--------
potential_temperature
Expand All @@ -1608,7 +1612,12 @@ def _isen_iter(iter_log_p, isentlevs_nd, ka, a, b, pok):

# Change when Python 2.7 no longer supported
# Pull out keyword arguments
tmpk_out = kwargs.pop('tmpk_out', False)
temperature_out = kwargs.get('tmpk_out')
if temperature_out:
warnings.warn('The use of "tmpk_out" has been deprecated in favor of'
'"temperature_out",', metpyDeprecation)
if temperature_out is None:
temperature_out = kwargs.pop('temperature_out', False)
max_iters = kwargs.pop('max_iters', 50)
eps = kwargs.pop('eps', 1e-6)
axis = kwargs.pop('axis', 0)
Expand Down Expand Up @@ -1687,8 +1696,8 @@ def _isen_iter(iter_log_p, isentlevs_nd, ka, a, b, pok):
# create list for storing output data
ret = [isentprs * units.hPa]

# if tmpk_out = true, calculate temperature and output as last item in list
if tmpk_out:
# if temperature_out = true, calculate temperature and output as last item in list
if temperature_out:
ret.append((isentlevs_nd / ((mpconsts.P0.m / isentprs) ** ka)) * units.kelvin)

# do an interpolation for each additional argument
Expand Down

0 comments on commit 5b22457

Please sign in to comment.