Skip to content

Commit

Permalink
move dt defs out of moist_lapse
Browse files Browse the repository at this point in the history
  • Loading branch information
Osamu Miyawaki committed Nov 7, 2023
1 parent d833572 commit 7683cb2
Showing 1 changed file with 39 additions and 13 deletions.
52 changes: 39 additions & 13 deletions src/metpy/calc/thermo.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,23 @@ def dry_lapse(pressure, temperature, reference_pressure=None, vertical_dim=0):


def dt_standard(p, t, params):
r"""
Computes the AMS moist adiabatic lapse rate in pressure coordinates.

Check failure on line 259 in src/metpy/calc/thermo.py

View workflow job for this annotation

GitHub Actions / Flake8

[flake8] reported by reviewdog 🐶 D401 First line of docstring should be in imperative mood: "Computes the AMS moist adiabatic lapse rate in pressure coordinates." Raw Output: src/metpy/calc/thermo.py:259:5: D401 First line of docstring should be in imperative mood: "Computes the AMS moist adiabatic lapse rate in pressure coordinates."
Parameters
----------
p : `float`
pressure [Pa]
t : `float`
temperature [K]
Returns
-------
dT/dp : `float`
lapse rate in pressure coordinates
"""
rs = saturation_mixing_ratio._nounit(p, t)
frac = (
(mpconsts.nounit.Rd * t + mpconsts.nounit.Lv * rs)
Expand Down Expand Up @@ -329,6 +346,24 @@ def dt_r14(p, t, params):
return frac / p


def select_dt(lapse_type):
if lapse_type == 'standard':
dt = dt_standard

Check failure on line 351 in src/metpy/calc/thermo.py

View workflow job for this annotation

GitHub Actions / Flake8

[flake8] reported by reviewdog 🐶 D103 Missing docstring in public function Raw Output: src/metpy/calc/thermo.py:351:5: D103 Missing docstring in public function
elif lapse_type == 'pseudoadiabatic':
dt = dt_pseudoadiabatic
elif lapse_type == 'reversible':
dt = dt_reversible
elif lapse_type == 'so13':
dt = dt_so13
elif lapse_type == 'r14':
dt = dt_r14
else:
raise ValueError('Specified lapse_type is not supported. '
'Choose from standard, pseudoadiabatic, reversible, '
'so13, or r14.')
return dt


@exporter.export
@preprocess_and_wrap(
wrap_like='temperature',
Expand Down Expand Up @@ -425,24 +460,15 @@ def moist_lapse(pressure, temperature, reference_pressure=None,
if reference_pressure is None:
reference_pressure = pressure[0]

if lapse_type == 'standard':
dt = dt_standard
elif lapse_type == 'pseudoadiabatic':
dt = dt_pseudoadiabatic
elif lapse_type == 'reversible':
dt = dt_reversible
dt = select_dt(lapse_type) # Define dt based on lapse_type

# Define or update params where needed
if lapse_type == 'reversible':
# total water at LCL = rs
params = {'rt': saturation_mixing_ratio._nounit(reference_pressure, temperature)}
elif lapse_type == 'so13':
dt = dt_so13
params.update({'h0': mpconsts.nounit.Rd * temperature[0] / mpconsts.nounit.g,
'p0': pressure[0]})
elif lapse_type == 'r14':
dt = dt_r14
else:
raise ValueError('Specified lapse_type is not supported. '
'Choose from standard, pseudoadiabatic, reversible, '
'so13, or r14.')

if np.isnan(reference_pressure) or np.all(np.isnan(temperature)):
return np.full((temperature.size, pressure.size), np.nan)
Expand Down

0 comments on commit 7683cb2

Please sign in to comment.