From 1da4336ad841fafd5b2f9c7feb74f85dc67fc7de Mon Sep 17 00:00:00 2001 From: Haoyu Zhuang Date: Thu, 13 Jul 2023 10:15:19 +0800 Subject: [PATCH 1/3] Update CCL/EL/LFC docstring --- src/metpy/calc/thermo.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/metpy/calc/thermo.py b/src/metpy/calc/thermo.py index 327aff534c1..8679626b51f 100644 --- a/src/metpy/calc/thermo.py +++ b/src/metpy/calc/thermo.py @@ -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` @@ -547,6 +547,7 @@ def ccl(pressure, temperature, dewpoint, height=None, mixed_layer_depth=None, wh >>> ccl_p, t_c (, ) """ + _check_pressure_error(pressure) pressure, temperature, dewpoint = _remove_nans(pressure, temperature, dewpoint) # If the mixed layer is not defined, take the starting dewpoint to be the @@ -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` @@ -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` @@ -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. @@ -1166,6 +1167,15 @@ 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): + msg = """ + Pressure increases between at least two points in your sounding. + Using scipy.signal.medfilt may fix this.""" + raise InvalidSoundingError(msg) + + def _parcel_profile_helper(pressure, temperature, dewpoint): """Help calculate parcel profiles. @@ -1174,11 +1184,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) From a077b064992c04ec77e5c17c2d58e70f8a44c941 Mon Sep 17 00:00:00 2001 From: Haoyu Zhuang Date: Thu, 13 Jul 2023 10:35:46 +0800 Subject: [PATCH 2/3] Fix CCL test error --- src/metpy/calc/thermo.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/metpy/calc/thermo.py b/src/metpy/calc/thermo.py index 8679626b51f..82072b3bedf 100644 --- a/src/metpy/calc/thermo.py +++ b/src/metpy/calc/thermo.py @@ -547,8 +547,8 @@ def ccl(pressure, temperature, dewpoint, height=None, mixed_layer_depth=None, wh >>> ccl_p, t_c (, ) """ - _check_pressure_error(pressure) 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. From 5a9e6b2f68a6bae6ae206b0845d55cd0c56c6cfb Mon Sep 17 00:00:00 2001 From: Richard Zhuang <38182337+Z-Richard@users.noreply.github.com> Date: Tue, 18 Jul 2023 16:35:41 +0800 Subject: [PATCH 3/3] Avoid msg in the code Co-authored-by: Ryan May --- src/metpy/calc/thermo.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/metpy/calc/thermo.py b/src/metpy/calc/thermo.py index 82072b3bedf..b704c1427ba 100644 --- a/src/metpy/calc/thermo.py +++ b/src/metpy/calc/thermo.py @@ -1170,10 +1170,8 @@ def _check_pressure(pressure): def _check_pressure_error(pressure): """Raise an `InvalidSoundingError` if _check_pressure returns False.""" 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) + 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):