Metpy.plots.skewT.plot_barbs
抛出此错误:
TypeError: ufunc 'isfinite' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''
当给定3个Numpy数组时:pressure
、u
和v
。
报告此错误消息的其他用户没有使用正确的dtype
或将np
用作变量名。我已经证实,这两种情况都不是我的原因。我还尝试过从u和v数组中删除这些单元。
import numpy as np
import metpy.plots as mpplots
# units comes from another file
pres = np.array([nan, 96950.26215278, 96877.55755208, 96763.37230603, 96652.54882812]) * units.pascal
u = np.array([nan, 0.36735288, 0.44829027, 1.29182593, -0.94374102]) * units.meter / units.second
v = np.array([nan, 4.61110612, 5.74110696, 6.01459714, 5.5652721]) * units.meter / units.second
rotation = 30
fig = mpplots.SkewT(rotation=rotation, aspect=80.5)
fig.ax.yaxis.set_major_locator(ticker.MultipleLocator(5))
fig.plot(pres, temp, 'r', label="Temperature")
fig.plot(pres, t_d, 'g', label="Dewpoint")
fig.ax.set_ylim(np.nanmax(pres.to(units.hPa).magnitude) + 10,
np.nanmin(pres.to(units.hPa).magnitude) - 20)
fig.ax.set_xlim(np.nanmin(t_d.to(units.degC).magnitude) - 5,
np.nanmax(temp.to(units.degC).magnitude) + 10)
fig.plot_dry_adiabats(linewidth=0.5, label="Dry Adiabats")
fig.plot_moist_adiabats(linewidth=0.5, label="Moist Adiabats")
fig.plot_mixing_lines(linewidth=0.5, label="Mixing Ratio")
fig.plot_barbs(np.array(pres.magnitude, dtype='float64') * pres.units,
np.array(u.magnitude, dtype='float64') * u.units,
np.array(v.magnitude, dtype='float64') * v.units)
Traceback (most recent call last):
File "/snap/pycharm-professional/167/helpers/pydev/pydevd.py", line 1415, in _exec
pydev_imports.execfile(file, globals, locals) # execute the script
File "/snap/pycharm-professional/167/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"n", file, 'exec'), glob, loc)
File "/home/.../sample_analysis.py", line 43, in <module>
fig = plotting.plot_skewT(temp=temp, pres=pres, t_d=t_d, u=u, v=v, units=units)
File "/home/.../plotting.py", line 248, in plot_skewT
np.array(v.magnitude, dtype='float64') * v.units)
File "/home/.../miniconda3/envs/Profiles/lib/python3.7/site-packages/metpy/plots/skewt.py", line 440, in plot_barbs
clip_on=True, zorder=2, **kwargs)
File "/home/.../miniconda3/envs/Profiles/lib/python3.7/site-packages/matplotlib/__init__.py", line 1785, in inner
return func(ax, *args, **kwargs)
File "/home/.../miniconda3/envs/Profiles/lib/python3.7/site-packages/matplotlib/axes/_axes.py", line 4874, in barbs
b = mquiver.Barbs(self, *args, **kw)
File "/home/.../miniconda3/envs/Profiles/lib/python3.7/site-packages/matplotlib/quiver.py", line 965, in __init__
self.set_UVC(u, v, c)
File "/home/.../miniconda3/envs/Profiles/lib/python3.7/site-packages/matplotlib/quiver.py", line 1145, in set_UVC
self.u = ma.masked_invalid(U, copy=False).ravel()
File "/home/.../miniconda3/envs/Profiles/lib/python3.7/site-packages/numpy/ma/core.py", line 2366, in masked_invalid
condition = ~(np.isfinite(a))
TypeError: ufunc 'isfinite' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''
Process finished with exit code 1
我能够使用以下功能:
import numpy as np
import metpy.plots as mpplots
from metpy.units import units
pres = np.array([np.nan, 96950.26215278, 96877.55755208, 96763.37230603, 96652.54882812]) * units.pascal
u = np.array([np.nan, 0.36735288, 0.44829027, 1.29182593, -0.94374102]) * units.meter / units.second
v = np.array([np.nan, 4.61110612, 5.74110696, 6.01459714, 5.5652721]) * units.meter / units.second
fig = mpplots.SkewT(rotation=30, aspect=80.5)
fig.plot_dry_adiabats(linewidth=0.5, label="Dry Adiabats")
fig.plot_moist_adiabats(linewidth=0.5, label="Moist Adiabats")
fig.plot_mixing_lines(linewidth=0.5, label="Mixing Ratio")
fig.plot_barbs(pres.astype('float64'), u.astype('float64'), v.astype('float64'))
我怀疑在读取数据的过程中可能需要做一些事情来正确生成nan。