I am using metpy to calculate Brunt-Vaisala frequency and the code is running fine but my array of values is being returned as a bunch of NaN values. I have Pressure and temperature measured at the following elevations: 75m, 1015.09m, 1786.01m, 2607.85m, 2834.74m. Can anyone tell me how I can fix this issue? Maybe my conceptual understanding of Brunt Vaisala is off.
el=np.array([75,1015.09,1786.01,2607.85,2834.74])
pres=np.array([945.79,889.87,810.35,732.69,712.33])
temp=np.array([11.27,8.03,7.8,2.09,0.28])
PT=np.array(temp*(1000/pres)**(.286))
BV=metpy.calc.brunt_vaisala_frequency(el*units.meter,PT*units.kelvin)
Calculating the Brunt-Vaisala frequency requires taking the vertical derivative of potential temperature with respect to height. Since you are passing in a completely uniform array of heights (as
el), the value of the vertical derivative is undefined and returned asnan. This causes the result of the entire calculation to be returned asnanas well.EDIT FOR UPDATED DATA:
The new data you posted have values of potential temperature that decrease with height. This is by definition an unstable profile and the Brunt-Vaisala frequency is undefined in such cases--so for these values MetPy returns nan.
If you want to see the negative values, you can call
metpy.calc.brunt_vaisala_frequency_squared, which avoids the problematic square root.