我从noaa下载了数据,我想使用函数vertical_velocity=metpy.calcmpcalc.vertical_velocity(omega,压力,温度)来计算垂直速度。但是当我处理变量的单位时,出现了一些问题。
import xarray as xr
import metpy.calc as mpcalc
omega=xr.open_dataset('D:\data_english\jwk\omega.mon.mean.nc')
temperature=xr.open_dataset('D:\data_english\jwk\air.mon.mean.nc')
height=xr.open_dataset('D:\data_english\jwk\hgt.mon.mean.nc')
pressure=mpcalc.height_to_pressure_std(height['hgt'])
verticalwind=mpcalc.vertical_velocity(omega['omega'], pressure, temperature['air'])
Traceback (most recent call last):
File "<ipython-input-194-da22b63a1943>", line 1, in <module>
verticalwind=mpcalc.vertical_velocity(omega['omega'], pressure, temperature['air'])
File "D:anacondalibsite-packagesmetpyxarray.py", line 1199, in wrapper
_mutate_arguments(bound_args, xr.DataArray, lambda arg, _: arg.metpy.unit_array)
File "D:anacondalibsite-packagesmetpyxarray.py", line 1233, in _mutate_arguments
bound_args.arguments[arg_name] = mutate_arg(arg_val, arg_name)
File "D:anacondalibsite-packagesmetpyxarray.py", line 1199, in <lambda>
_mutate_arguments(bound_args, xr.DataArray, lambda arg, _: arg.metpy.unit_array)
File "D:anacondalibsite-packagesmetpyxarray.py", line 157, in unit_array
return units.Quantity(self._data_array.data, self.units)
File "D:anacondalibsite-packagesmetpyxarray.py", line 134, in units
return units.parse_units(self._data_array.attrs.get('units', 'dimensionless'))
File "D:anacondalibsite-packagespintregistry.py", line 1084, in parse_units
units = self._parse_units(input_string, as_delta)
File "D:anacondalibsite-packagespintregistry.py", line 1298, in _parse_units
return super()._parse_units(input_string, as_delta)
File "D:anacondalibsite-packagespintregistry.py", line 1112, in _parse_units
cname = self.get_name(name)
File "D:anacondalibsite-packagespintregistry.py", line 636, in get_name
raise UndefinedUnitError(name_or_alias)
UndefinedUnitError: 'Pascal' is not defined in the unit registry
**欧米茄、高度和温度的单位分别为"帕斯卡/秒"、"米"one_answers"摄氏度"。通过函数mpcalc计算变压力。Height_to_pressure_std,这个函数没有给出压力的单位。但是压力的取值范围是1000到0,所以我认为它的单位是hpa。
错误报告"'Pascal'未在单元注册表中定义"。也许"帕斯卡/秒"不是默认的单位?但是我怎么知道哪些单位是在单位注册表中定义的呢?有人能帮我吗?谢谢!* *
这是一个问题,MetPy使用的单元库(Pint)没有与netCDF气候和预测约定使用的元数据UDUnits格式相同的大写/大小写敏感性规则。修复这个问题在MetPy的待办事项列表中,但是遇到了一些障碍。
现在的解决办法是把你的单位改成Pint能理解的东西,比如:
omega['omega'].attrs['units'] = 'pascal / s'