Skip to content

Commit

Permalink
Update CCL/EL/LFC docstring to reflect that pressure should be monoto…
Browse files Browse the repository at this point in the history
…nically decreasing (#3114)

* Update CCL/EL/LFC docstring

* Fix CCL test error

* Avoid msg in the code

Co-authored-by: Ryan May <[email protected]>

---------

Co-authored-by: Ryan May <[email protected]>
  • Loading branch information
Z-Richard and dopplershift authored Jul 20, 2023
1 parent efc00e6 commit d9bfba6
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/metpy/calc/thermo.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ def ccl(pressure, temperature, dewpoint, height=None, mixed_layer_depth=None, wh
Parameters
----------
pressure : `pint.Quantity`
Atmospheric pressure profile
Atmospheric pressure profile. This array must be from high to low pressure.
temperature : `pint.Quantity`
Temperature at the levels given by `pressure`
Expand Down Expand Up @@ -548,6 +548,7 @@ def ccl(pressure, temperature, dewpoint, height=None, mixed_layer_depth=None, wh
(<Quantity(758.348093, 'millibar')>, <Quantity(38.4336274, 'degree_Celsius')>)
"""
pressure, temperature, dewpoint = _remove_nans(pressure, temperature, dewpoint)
_check_pressure_error(pressure)

# If the mixed layer is not defined, take the starting dewpoint to be the
# first element of the dewpoint array and calculate the corresponding mixing ratio.
Expand Down Expand Up @@ -598,7 +599,7 @@ def lfc(pressure, temperature, dewpoint, parcel_temperature_profile=None, dewpoi
Parameters
----------
pressure : `pint.Quantity`
Atmospheric pressure
Atmospheric pressure profile. This array must be from high to low pressure.
temperature : `pint.Quantity`
Temperature at the levels given by `pressure`
Expand Down Expand Up @@ -814,7 +815,7 @@ def el(pressure, temperature, dewpoint, parcel_temperature_profile=None, which='
Parameters
----------
pressure : `pint.Quantity`
Atmospheric pressure profile
Atmospheric pressure profile. This array must be from high to low pressure.
temperature : `pint.Quantity`
Temperature at the levels given by `pressure`
Expand All @@ -827,7 +828,7 @@ def el(pressure, temperature, dewpoint, parcel_temperature_profile=None, which='
surface parcel profile.
which: str, optional
Pick which LFC to return. Options are 'top', 'bottom', 'wide', 'most_cape', and 'all'.
Pick which EL to return. Options are 'top', 'bottom', 'wide', 'most_cape', and 'all'.
'top' returns the lowest-pressure EL, default.
'bottom' returns the highest-pressure EL.
'wide' returns the EL whose corresponding LFC is farthest away.
Expand Down Expand Up @@ -1160,6 +1161,13 @@ def _check_pressure(pressure):
return np.all(pressure[:-1] >= pressure[1:])


def _check_pressure_error(pressure):
"""Raise an `InvalidSoundingError` if _check_pressure returns False."""
if not _check_pressure(pressure):
raise InvalidSoundingError('Pressure increases between at least two points in '
'your sounding. Using scipy.signal.medfilt may fix this.')


def _parcel_profile_helper(pressure, temperature, dewpoint):
"""Help calculate parcel profiles.
Expand All @@ -1168,11 +1176,7 @@ def _parcel_profile_helper(pressure, temperature, dewpoint):
"""
# Check that pressure does not increase.
if not _check_pressure(pressure):
msg = """
Pressure increases between at least two points in your sounding.
Using scipy.signal.medfilt may fix this."""
raise InvalidSoundingError(msg)
_check_pressure_error(pressure)

# Find the LCL
press_lcl, temp_lcl = lcl(pressure[0], temperature, dewpoint)
Expand Down

0 comments on commit d9bfba6

Please sign in to comment.