Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update CCL/EL/LFC docstring to reflect that pressure should be monotonically decreasing #3114

Merged
merged 3 commits into from
Jul 20, 2023
Merged
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
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 @@ -1166,6 +1167,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 @@ -1174,11 +1182,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