Unidata / MetPy

MetPy is a collection of tools in Python for reading, visualizing and performing calculations with weather data.
https://unidata.github.io/MetPy/
BSD 3-Clause "New" or "Revised" License
1.23k stars 408 forks source link

In calculating CAPE value, why is the minus sign in the formula not reflected in the code? #3544

Open hechentao opened 1 month ago

hechentao commented 1 month ago

What went wrong?

CAPE formula: $\text{CAPE} = -Rd \int{LFC}^{EL} (T{{v}{parcel}} - T{{v}{env}}) d\text{ln}(p)$ And in the code:

  # Difference between the parcel path and measured temperature profiles
  y = (parcel_profile - temperature).to(units.degK)

  # Estimate zero crossings
  x, y = _find_append_zero_crossings(np.copy(pressure), y)

  # CAPE
  # Only use data between the LFC and EL for calculation
  p_mask = _less_or_close(x.m, lfc_pressure) & _greater_or_close(x.m, el_pressure)
  x_clipped = x[p_mask].magnitude
  y_clipped = y[p_mask].magnitude
  cape = (mpconsts.Rd
          * units.Quantity(np.trapz(y_clipped, np.log(x_clipped)), 'K')).to(units('J/kg'))

I didn't find anything about negative signs. Did I not understand this code thoroughly myself?

Operating System

Windows

Version

1.6.2

Python Version

3.8.19

Code to Reproduce

None

Errors, Traceback, and Logs

No response

DWesl commented 4 weeks ago

$-\int_{LFC}^{EL} (Tp - T{env}) d\log p = \int_{EL}^{LFC} (Tp - T{env}) d\log p$ Does anything check whether the pressures are increasing and reverse them (and the data) if not?

DWesl commented 4 weeks ago

in _find_append_zero_crossings: https://github.com/Unidata/MetPy/blob/d27e97cfd211acbfcf0190bb82992443859ac19a/src/metpy/calc/thermo.py#L2509-L2512