[python #MNH-916116]: Question regarding MetPy: CAPE calculation
- Subject: [python #MNH-916116]: Question regarding MetPy: CAPE calculation
- Date: Fri, 20 Mar 2020 16:38:39 -0600
Apologies on the delayed response, and thank you for the kind words, and
excellent issue report.
So the core of the problem is that there are a couple of points in the sounding
where pressure increases by 0.1 hPa, from 9.8 to 9.9 and from 9.1 to 9.2. While
we know those are not really significant, the integration code has problems
with them. So it's not anything wrong with the data, just that the data are
slightly breaking an assumption of the underlying calculation algorithm. I've
opened an issue on MetPy for further consideration of what me might do to
address this within MetPy as we see more high-resolution soundings like this:
I doubt we'll be resolving this any time soon, though. In the meantime, I was
able to use `scipy.signal.medfilt` (median filter) to smooth out those
smooth_press = scipy.signal.medfilt(press, 5) * units.hPa
# medfilt does not do what we want for the start of the pressure array here
smooth_press[:2] = press[:2]
mpcalc.surface_based_cape_cin(smooth_press, temp, td)
That uses the median to fix the points with the small fluctuations. Given the
1Hz data, I'd expect this to be pretty robust. Let me know if you run into any
problems with this.
Hope this helps!
> I recently came across an issue with my code when calculating CAPE for a
> sounding data set. The code seems to break after the 3rd sounding that it
> reads in and calculates CAPE.
> It yields the following error:
> line 236, in odeint
> raise ValueError("The values in t must be monotonically increasing "
> ValueError: The values in t must be monotonically increasing or
> monotonically decreasing; repeated values are allowed.
> I have played around with a few versions of the sounding to try to
> understand where this error is coming from. The main data set is PECAN
> sounding data, with some of the soundings in this composite being obtained
> from the National Weather Service. To test the data, I read in the data
> from the University of Wyoming website, and was able to be calculated using
> metpy along with a skewT as well.
> Since the error was about values increasing and decreasing monotonically, I
> thought it could be flagging it when the sounding when nearing the
> tropopause. I took the PECAN data set sounding and cut it off at about
> 15/16 km. When I ran my code, it also calculated cape with no problems and
> it's skewT.
> I attached a few files if you would like to see the sounding.
> AQB_fullsounding is the full sounding given in the PECAN dataset,
> ABQ_halfsounding.txt is the PECAN data sounding that I cut off, and
> ABQ_Wyoming is the lower resolution sounding retrieved from University of
> Wyoming. I would really appreciate help or any suggestions on what the
> error could be! I am struggling to determine if there is an issue with the
> campaign sounding data, but the temperature profile looks pretty normal to
> me! Thanks in advance!
Ticket ID: MNH-916116
Department: Support Python
NOTE: All email exchanges with Unidata User Support are recorded in the Unidata
inquiry tracking system and then made publicly available through the web. If
you do not want to have your interactions made available in this way, you must
let us know in each email you send to us.