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

[python #FFD-695288]: Metpy Issues Producing Advanced Sounding



Greetings!

Regarding the calculation of specific humidity, two items:

1. When calculating by hand, don't forget to convert the mixing ratio to be 
unitless [otherwise, what are the correct units for 1?], so the calculation 
should be 0.014 / (1 + 0.014) = 0.0138 -> 13.8 g/kg specific humidity.
2. Your calculation of dewpoint should be: dew = 
mpcalc.dewpoint_from_specific_humidity(press, cel, sph)  [note the last 
argument]

With that said, you still do end up with warnings about the exceedingly high 
relative humidity even when the code is correct. This is because the current 
calculation path ends up going through saturation_vapor_pressure (from 
saturation_mixing_ratio). The *empirical* Bolton (1980) formula gives a 
saturation vapor pressure of 5 x 10^-29 at -38C (this is assumed relative to a 
plane of liquid water)--which also gives a saturation mixing ratio of 
3x10^-30--which is so far below your observed value of 14 (?) that relative 
humidity is by definition huge here. I think one problem is that at 10 hPa and 
-38C, we're getting outside the range where the Bolton (1980) fit is good; 
liquid water is unlikely to be present and calculations should maybe be done 
relative to ice (which MetPy doesn't *yet* support). Also, I'm a little 
surprised of an "observed" 14 g/kg mixing ratio at that height/temperature.

To avoid the warning, I'd recommend use this to calculate the dewpoint from 
your mixing ratio values, which calculates the ambient water vapor pressure 
directly from pressure/mixing ratio and uses that to back out dewpoint:

    dew = mpcalc.dewpoint(mpcalc.vapor_pressure(press, mix))

Note that `dewpoint()` calculation is still assuming the Bolton (1980) 
empirical relationship (and all the problems relative to your conditions), but 
will avoid the warnings and any potential numerical problems from going through 
such absurd values for RH, mixing ratio, etc.

The second problem is that your data are going from low pressure to high 
pressure (or top of the atmosphere to bottom). As noted in the `parcel_profile` 
documentation:

  
https://unidata.github.io/MetPy/latest/api/generated/metpy.calc.parcel_profile.html

  "pressure (pint.Quantity) – Atmospheric pressure level(s) of interest. This 
array must be from high to low pressure."

If I change two lines in your script to flip the order of the pressure (and use 
the correct indices for the surface temperature/dewpoint):

    prof = mpcalc.parcel_profile(press[::-1], cel[-1], dew[-1])
    skew.plot(press[::-1], prof, 'k', linewidth=2)

Everything works and I get a sensible plot.

Cheers!

Ryan


> Hello,
> 
> I am attempting to use metpy to produce a skew-T diagram with a text file 
> that I have. This file includes pressure (hPa), theta (K) and mixing ratio 
> (g/kg). I have been able to calculate the temperature in deg. C. but also 
> need the dewpoint temperature. To calculate this, I plan on using the mixing 
> ratio and the function from metpy mpcalc.specific_humidity_from_mixing_ratio. 
> From my understanding in the documentation, this function needs the mixing 
> ratio (g/kg). As I have all of this, I plug it in but I am confused with the 
> value I am getting back for the specific humidity. If the equation for spec. 
> hum. = mixing ratio/(mixing ratio +1), and I have a constant mixing ratio of 
> 14, I would expect a value of around 0.93. Although, using the metpy 
> function, I am getting a value of 13.8 instead.
> 
> I suppose I am just confused as to what metpy is giving me versus what I 
> think is the correct specific humidity calculation. Not sure if this is a 
> unit conversion issue or not, but I have implemented the units function that 
> metpy provides to help avoid any issues. Overall, I was hoping that I could 
> just a short explanation/some help into how to best handle these functions 
> within metpy, or help me figure out where Im going wrong. I have tried to use 
> the value of 13.8 that the metpy function returns to calculate my dewpoint, 
> but then run into errors that my relative humidity is over 100%.
> 
> ??????Also, whenever I try to plot the skew-T, along with the parcel path, I 
> get an error that says my pressure increases in at least two points on my 
> sounding which is confusing to me because I have checked that it is monotonic 
> the whole way. Im not sure what I am missing or not understanding, but I have 
> tried to follow the advanced sounding example on metpy as close as possible. 
> I have attached a jupyter notebook sample of my code, as well as a small .txt 
> file with my data inside.
> 
> I greatly appreciate any and all help!!


Ticket Details
===================
Ticket ID: FFD-695288
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.