-
Notifications
You must be signed in to change notification settings - Fork 415
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
LFC calc: if EL is above top of sounding, use top of sounding as EL #3132
Conversation
hmm. This was somewhat of a quick fix for an exception getting raised when I threw a particular dataset at I think crashing is clearly the wrong behavior, but so is providing an LFC based on interpolated data. I'm going to think about this some more |
The scenario you're describing fits that of the May 3rd sounding we have in the test data ( |
the "sounding" that caused the crash in my case was very much an edge case... from metpy import calc as mpcalc
import numpy as np
from metpy.units import units
level = np.array([733.0, 732.0, 731.0, 730.0]) * units.hPa
temp = np.array([16.740580530590336, 16.645407342070797, 16.550234153551262, 16.39797906332763]) * units.degC
dew = np.array([-1.5180807300997776, -1.3453806517560651, -1.1726805734123527, -1.0063032908045617]) * units.degC
# this will cause a traceback
mpcalc.surface_based_cape_cin(levels, temp, dew) The traceback is: Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/stgardner4/Downloads/metpy/src/metpy/xarray.py", line 1328, in wrapper
result = func(*bound_args.args, **bound_args.kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/stgardner4/Downloads/metpy/src/metpy/units.py", line 325, in wrapper
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/home/stgardner4/Downloads/metpy/src/metpy/calc/thermo.py", line 2865, in surface_based_cape_cin
return cape_cin(p, t, td, profile)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/stgardner4/Downloads/metpy/src/metpy/xarray.py", line 1328, in wrapper
result = func(*bound_args.args, **bound_args.kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/stgardner4/Downloads/metpy/src/metpy/units.py", line 325, in wrapper
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/home/stgardner4/Downloads/metpy/src/metpy/calc/thermo.py", line 2363, in cape_cin
lfc_pressure, _ = lfc(pressure, temperature, dewpoint,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/stgardner4/Downloads/metpy/src/metpy/xarray.py", line 1328, in wrapper
result = func(*bound_args.args, **bound_args.kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/stgardner4/Downloads/metpy/src/metpy/units.py", line 325, in wrapper
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/home/stgardner4/Downloads/metpy/src/metpy/calc/thermo.py", line 722, in lfc
if np.min(el_pressure) > this_lcl[0]:
^^^^^^^^^^^^^^^^^^^
File "<__array_function__ internals>", line 200, in amin
File "/opt/mamba/envs/HDWX/lib/python3.11/site-packages/pint/facets/numpy/quantity.py", line 66, in __array_function__
return numpy_wrap("function", func, args, kwargs, types)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/mamba/envs/HDWX/lib/python3.11/site-packages/pint/facets/numpy/numpy_func.py", line 1034, in numpy_wrap
return handled[name](*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/mamba/envs/HDWX/lib/python3.11/site-packages/pint/facets/numpy/numpy_func.py", line 828, in implementation
ret = func(*bound_args.args, **bound_args.kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<__array_function__ internals>", line 200, in amin
File "/opt/mamba/envs/HDWX/lib/python3.11/site-packages/numpy/core/fromnumeric.py", line 2946, in amin
return _wrapreduction(a, np.minimum, 'min', axis, None, out,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/mamba/envs/HDWX/lib/python3.11/site-packages/numpy/core/fromnumeric.py", line 86, in _wrapreduction
return ufunc.reduce(obj, axis, dtype, out, **passkwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: zero-size array to reduction operation minimum which has no identity There is a point to this, I promise... I'm searching for the bottom and top of the effective inflow layer of an ACARS profile: This led me to investigate why el_pressure was empty... which led to my fix of just checking "if it's empty use the top pressure available". This (correctly) returns 0 J/kg CAPE and CIN, but internally, uses an LFC of 556 hPa, and if the user asks for the LFC, that's what it returns. I don't see how that's possible, given that is above the provided environmental profile. >>> mpcalc.lfc(level, temp, dew)
<stdin>:1: UserWarning: Interpolation point out of data bounds encountered
(<Quantity(556.424774, 'hectopascal')>, <Quantity(-5.21169013, 'degree_Celsius')>) I haven't had time to look into why this happens and probably won't until next week... This might be better suited for an issue instead of a draft PR. |
I cannot reproduce this now, so I'll close this and if it comes back up I'll do a better job of recording what happened. |
If attempting to calculate the LFC of a partial sounding, particularly one where the data is cut off below the EL, calculating the LFC or CAPE causes a value error. This commit uses the top of the sounding as the EL if the EL is absent (for the LFC calculation only).
This may or may not be a fix for the issue described in #2315, I'm not sure.