导入自定义颜色表文件时出现问题



所以,我试图通过metpy函数metpy.plots.ctables.read_colortable导入一个自定义的colortable.tbl文件,用Py ART绘制一些雷达场。

这些是我正在使用的代码:

from metpy.plots import ctables
ctables.registry.add_colortable('zdr_table.tbl','nexrad_zdr')
zdr_cmap = ctables.registry.get_colortable('nexrad_zdr')

问题是,当我尝试这样做时,我会收到以下错误消息:

Traceback (most recent call last):
File "/home/viper/miniconda3/envs/pyart_env/lib/python3.8/site-packages/metpy/plots/ctables.py", line 95, in read_colortable
literal = _parse(line)
File "/home/viper/miniconda3/envs/pyart_env/lib/python3.8/site-packages/metpy/plots/ctables.py", line 67, in _parse
return ast.literal_eval(s)
File "/home/viper/miniconda3/envs/pyart_env/lib/python3.8/ast.py", line 96, in literal_eval
return _convert(node_or_string)
File "/home/viper/miniconda3/envs/pyart_env/lib/python3.8/ast.py", line 95, in _convert
return _convert_signed_num(node)
File "/home/viper/miniconda3/envs/pyart_env/lib/python3.8/ast.py", line 74, in _convert_signed_num
return _convert_num(node)
File "/home/viper/miniconda3/envs/pyart_env/lib/python3.8/ast.py", line 66, in _convert_num
raise ValueError('malformed node or string: ' + repr(node))
ValueError: malformed node or string: <_ast.Name object at 0x7fcf76e35c40>
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "plot_zdr_ppi2.py", line 31, in <module>
ctables.registry.add_colortable('zdr_table.tbl','nexrad_zdr')
File "/home/viper/miniconda3/envs/pyart_env/lib/python3.8/site-packages/metpy/plots/ctables.py", line 187, in add_colortable
self[name] = read_colortable(fobj)
File "/home/viper/miniconda3/envs/pyart_env/lib/python3.8/site-packages/metpy/plots/ctables.py", line 100, in read_colortable
raise RuntimeError('Malformed colortable.')
RuntimeError: Malformed colortable.

我尝试过使用Hex HTML和RGB算术格式,结果都相同。

有什么想法吗?

add_colortable的第一个参数不是文件名,而是类似文件的对象,因此您需要自己调用open()

from metpy.plots import ctables
ctables.registry.add_colortable(open('zdr_table.tbl', 'rt'),'nexrad_zdr')
zdr_cmap = ctables.registry.get_colortable('nexrad_zdr')

相关内容

  • 没有找到相关文章

最新更新