[Pyaos] CAPE and CIN calculation in Python

Hello Marry,

I am highly interested in getting “wrf_cape_3d” wrapped to be accessible in Python. So far, that’s how I calculate CAPE and CIN for my WRF outputs. wrf_cape_3d is more robust comparing to the function in the SkewT script. For some reason, I have no luck getting wrf_cape_2d working properly as it throws a NaN error.


On Mon, Mar 31, 2014 at 2:25 PM, Mary Haley <haley@…157…> wrote:

Hi all,

I’ve been following this thread somewhat peripherally.

I’ve slowly started creating Python wrappers of some of the WRF Fortran calculation functions (not the graphical ones) that are used in NCL.

You can see the list of the NCL ones at:


So far I’ve only wrapped these six: wrf_avo, wrf_tk, wrf_td, wrf_slp, wrf_rh, wrf_dbz.

Would the wrf_cape_2d and wrf_cape_3d routines be of interest? These are specific to WRF data. I believe these are the same ones that Wanli is referring to.

We also have the ones that we use for the basic Skew-T code in NCL, that Gökhan has been corresponding with Dennis on.

I could wrap these as well. These routines are not advertised in NCL, but they are used by the Skew-T examples you see at:



On Mar 31, 2014, at 11:41 AM, Wanli Wu <wu80012@…287…> wrote:


Another good example of Skew-T with all Parcel stability info including CIN, CAPE is produced through RIP4 (see this example:http://www.mmm.ucar.edu/mm5/WRF_post/RIP4/pages/rip_sample_cgm030_gif.htm). If this one can be duplicated with python, it’d great for the community.

Wanli Wu

Pyaos mailing list


On Mon, Mar 31, 2014 at 7:49 AM, Gökhan Sever <gokhansever@…287…> wrote:

Hi James,

I have managed to run CLIMT’s thermodyn.py . Most of the functions I tested from within the Driver.f90 works fine except the CAPE and CIN routines. I sent an e-mail to the author regarding this but nothing back from him so far. Would you give a test if I send you a simple sounding data? My system is Window 7 (x64) and using Python(XY). f2py uses the gfortran provided in MinGW32 folder.

Could you provide an example (with some test data) for Kerry Emanuel’s code? That code has definitely more functions than I need but it might be a valuable source.

As for the NCL, it is easy to interface to a WRF output, it also includes a SkewT/LogP [https://www.ncl.ucar.edu/Applications/skewt.shtml], but the CAPE estimation in this script is very sensitive to the number of data-points, which I have bitten a couple of times. Dennis Shea has provided some CAPE calculation routines coded in fortran. [Check under http://www.cgd.ucar.edu/~shea/ for the files starting with cape*]. Yet I have no luck wrapping them via f2py.

Pyaos mailing list



On Sat, Mar 29, 2014 at 7:11 PM, James Boyle <jsboyle314@…287…> wrote:

I have used the CAPE and CIN from ClMT - a bit of overkill but many useful functions:

I have also wrapped using f2py the the Fortran CAPE and CIN of Kerry Emanuel ( a prestigious source) in his convect code:


If you prowl about in the NCL source distribution, you will find the fortran that the NCL skew - T uses.

If you ask, Dennis Shea of NCAR might break the code out for you. It is trivial to wrap using f2py ( f77).

On Mar 29, 2014, at 3:32 PM, Gökhan Sever <gokhansever@…287…> wrote:


Lately, I am working on plotting sounding profiles on a SkewT/LogP diagram. The SkewT package which is located at https://github.com/tchubb/SkewT has a nice feature to lift a parcel on dry/moist adiabats. This is very useful to demonstrate the regions of CIN and CAPE overlaid with the full sounding.

However, the package misses these diagnostic calculations. This is the only step holding me back to use Python only (migrating from NCL) for my plotting tasks. I am aware that these calculations are usually performed in fortran. Are there any routines wrapped in Python to calculate CAPE and CIN parameters? Any suggestions or comments would be really appreciated.


Matplotlib-users mailing list