Skip to content

Commit

Permalink
reduce complexity 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 7683cb2 commit e54881f
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/metpy/calc/thermo.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ 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.
Compute the AMS moist adiabatic lapse rate in pressure coordinates.
Parameters
----------
Expand Down Expand Up @@ -364,6 +364,16 @@ def select_dt(lapse_type):
return dt


def update_params(params, lapse_type, reference_pressure, pressure, temperature):
if lapse_type == 'reversible':
# total water at LCL = rs

Check failure on line 369 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:369:5: D103 Missing docstring in public function
params = {'rt': saturation_mixing_ratio._nounit(reference_pressure, temperature)}
elif lapse_type == 'so13':
params.update({'h0': mpconsts.nounit.Rd * temperature[0] / mpconsts.nounit.g,
'p0': pressure[0]})
return params


@exporter.export
@preprocess_and_wrap(
wrap_like='temperature',
Expand Down Expand Up @@ -463,12 +473,7 @@ def moist_lapse(pressure, temperature, reference_pressure=None,
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':
params.update({'h0': mpconsts.nounit.Rd * temperature[0] / mpconsts.nounit.g,
'p0': pressure[0]})
params = update_params(params, lapse_type, reference_pressure, pressure, temperature)

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 e54881f

Please sign in to comment.