[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[python #LKP-606313]: Metpy Cape Cin monotonically increasing



Hello! Thanks for your question.

Without seeing your data, we've seen this issue recently with high resolution 
soundings which can have instances of pressure decreasing as the measurements 
are taken. If this happens then the underlying integration code will fail, as 
it assumes these values of the independent variable to increase/decrease 
monotonically. So, this t is referring to the input variable to this code, not 
necessarily temperature. See this github issue to keep up-to-date or contribute 
to the discussion on the issue as we plan to handle it: 
https://github.com/Unidata/MetPy/issues/1339

In the mean time, we suggest either filtering the data with something like 
SciPy's `scipy.signal.medfilt` median filter 
(https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.medfilt.html)
 or otherwise preprocessing your profile to address any regions of decreasing 
pressure. Here is some example code for using medfilt:

    import metpy.calc as mpcalc
    from metpy.units import units
    from scipy.signal import medfilt

    smooth_pres = medfilt(pres_masked, 5) * units.hPa

    # medfilt may have over-filtered our first few pressures values, so we will 
exclude those
    smooth_press[:2] = press[:2]
    mpcalc.surface_based_cape_cin(smooth_press, temp, td)

I hope this helps! If not, please be sure to reach out again and if you can 
attach or point to the data you are trying to apply these calculations on that 
will help us out. Thanks again for the question.


All the best,

Drew


> Hi,
> I would like to calculate CAPE for numerous vertical profiles that I have.
> I try this:
> 
> a=mpcalc.most_unstable_cape_cin(pres_masked*units.hPa,
> temp_masked*units.degC, dp_masked*units.degC)
> 
> And get the error:
> 
> File
> "/apps/Anaconda/anaconda3/lib/python3.7/site-packages/scipy/integrate/odepack.py",
> line 235, 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.
> 
> 
> Is this saying that the temperature must be monotonically increasing? This
> is real vertical profile and so there is variability, with some values
> increasing. Have you any suggestions on how to get this to work?



Ticket Details
===================
Ticket ID: LKP-606313
Department: Support Python
Priority: Low
Status: Closed
===================
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.