Precipitable Water is Nan
Hey there !
I a am using metpy 0.12.0 and I found precipitable water equals to Nan while studying an upper-air observed profile (mpcalc.precipitable_water(Td, P) yields to nan mm). However
mpcalc.precipitable_water(Td, P, bottom=P[0], top=P[-3]) returns a true value of precipitable water.
Last 3 elements of P and Td seems correct.
I have no clue about what happens.
Thanks for your help ! Matthieu, user and huge fan of Metpy !
Enclosed is the vertical profile, p_niv is in Pa, t and td are in K, H which stands for altitude is in m, FF and DD are in m/s and degree.
@sorelm-mf, looking at your example data file, there are lots of pressure values repeated in it. Running with current main branch metpy, yields the following warning and NaN:
one_dimension.py:157: RuntimeWarning: invalid value encountered in true_divide
var_interp = var[below] + (var[above] - var[below]) * ((x_array - xp[below])
nan millimeter
Using a simple pandas utility to take the first entry of any redundant pressure levels, we get a result of:
15.48365948834233 millimeter
The code
import pandas as pd
from metpy.units import units
from metpy.calc import precipitable_water
df = pd.read_csv("RS_Bdx.txt")
df = df.groupby("p_niv").first().reset_index()
print(precipitable_water(units("pascal") * df['p_niv'].values, units('degK') * df['td'].values))
I'm still wondering if we could have better behavior here, or at least how we compare to np.interp. Would be good to ensure we're at least matching their behavior in this case.
Would be a good time for us to wade into the waters of using Hypothesis for testing (#743).