Open eliteuser26 opened 4 years ago
I can confirm on my system with this:
from datetime import datetime
import metpy.calc as mpcalc
from metpy.units import pandas_dataframe_to_unit_arrays
from siphon.simplewebservice.wyoming import WyomingUpperAir
df = WyomingUpperAir.request_data(datetime(2020, 3, 13, 12), 'BUF')
data = pandas_dataframe_to_unit_arrays(df)
mpcalc.surface_based_cape_cin(data['pressure'], data['temperature'], data['dewpoint'])
gives on current metpy master:
(-192.87189038978863 <Unit('joule / kilogram')>,
-5.391129989300722 <Unit('joule / kilogram')>)
It is one of those rare cases where the value for Cape is negative. Normally it is giving the proper positive value as intended. This seems to occur when the parcel profile is very close to the measured temperatures in the lower atmosphere.
Found another case of negative Cape value for Detroit DTX on April 1st at 12 UTC. This isn't an April fool's joke. The calculated Cape value is -27 J/kg. It seems to occur when the parcel profile is crisscrossing the measured temperature profile.
I've been throwing my entire RAOB archive through MetPy's sounding functions and did a quick check for negative sbcape for the past few days and behold
station | valid | sbcape_jkg |
---|---|---|
KDTX | 2020-04-01 12:00:00+00 | -27.533386 |
KXMR | 2020-04-01 00:00:00+00 | -30.603716 |
KKPP | 2020-03-31 12:00:00+00 | -95.12861 |
KMFL | 2020-03-31 12:00:00+00 | -390.22668 |
KCUN | 2020-03-31 00:00:00+00 | -179.90114 |
KDDC | 2020-03-31 00:00:00+00 | -81.269775 |
KJAX | 2020-03-31 00:00:00+00 | -21.090246 |
KJSJ | 2020-03-31 00:00:00+00 | -233.70105 |
KCUN | 2020-03-30 12:00:00+00 | -263.11 |
KJSJ | 2020-03-30 12:00:00+00 | -397.9066 |
KMFL | 2020-03-30 12:00:00+00 | -190.04387 |
KSDQ | 2020-03-30 12:00:00+00 | -131.27994 |
KSLE | 2020-03-30 12:00:00+00 | -121.92557 |
KXKF | 2020-03-30 12:00:00+00 | -352.6673 |
KBDI | 2020-03-29 12:00:00+00 | -266.86176 |
KBMX | 2020-03-29 12:00:00+00 | -22.72841 |
KPIT | 2020-03-29 12:00:00+00 | -12.695718 |
KTLH | 2020-03-29 12:00:00+00 | -401.89224 |
KBMX | 2020-03-28 12:00:00+00 | -671.2816 |
KFFC | 2020-03-28 12:00:00+00 | -775.76196 |
KJAN | 2020-03-28 12:00:00+00 | -427.56732 |
Overall, 435 out of 22,553 soundings with negative sbcape this year :)
Well, I'm not thrilled, but at least that's not an overwhelming amount. Thanks for doing that test @akrherz !
I haven't checked other sites as I am only using 3 locations for my website which are closest to my position. It tries to calculate the area between the parcel profile and the measured temperatures. However it seems to combine both CAPE and CIN values together to calculate the resulting value. When the profile and measured temperatures are close together it can't determine the LFC along the profile.
Still seeing more negative Cape values from Buffalo when lifted parcel line is very close to the environmental values. This can be fixed easily in the Metpy code by assigning zero for negative values. Same type of code as for CIN but reversed.
This can also occur when there are 2 areas of CIN and 2 areas of Cape in the same profile. In this case it will be calculated as a negative values if CIN values are larger than Cape values.
Last time we dug into that code, I didn't think it should be able to return negative values. Setting anything <0 to 0 sounds like a workaround for conditions that break internal assumptions--I'd much rather fix the code itself, assuming my understanding is correct.
After thinking about it and looking at the parcel path I would agree with you. The same would apply for positive CIN. I was thinking about looking at the code and results to find out why this is happening. In those cases I found that they were multiple areas of Cape and CIN very close to the environmental profile. Otherwise all other cases are being calculated correctly.
The calculation of the CAPE and CIN areas was done from the Buffalo sounding on March 13, 2020 at 12 UTC with this method in Metpy:
cape_value, cin_value = mpcalc.cape_cin(p, T, Td, parcel_path)
Here are the values which resulted from this method:
CAPE: -192.87189038978863 J/kg CIN: -4.246779773060985 J/kg
This is the sample code used to calculate these values above: