1

So, I'm trying to import a custom colortable .tbl file via the metpy function metpy.plots.ctables.read_colortable, to plot some radar fields with Py-ART.

These are the codes I'm using:

from metpy.plots import ctables

ctables.registry.add_colortable('zdr_table.tbl','nexrad_zdr')
zdr_cmap = ctables.registry.get_colortable('nexrad_zdr')

The problem is that, when I try doing this I get the following error message:

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.

I've tried to use both Hex HTML and RGB arithmetic formats with the same results.

Any ideas?

Souda
  • 63
  • 4
  • Nobody is going to be able to help with this unless we can see what's in the colortable file you're trying to read in. If it's short, can you include the contents here? Otherwise, can you post it somewhere and include a link in your question? – DopplerShift Mar 26 '20 at 19:30
  • Sorry. This is the content inside the .tbl file: (0.00000, 0.00000, 0.00000) (0.25098, 0.25098, 0.25098) (0.61176, 0.61176, 0.61176) (0.78824, 0.78824, 0.78824) (0.54902, 0.47059, 0.70588) (0.00000, 0.00000, 0.59608) (0.13725, 0.59608, 0.82745) (0.26667, 1.00000, 0.82353) (0.34118, 0.85882, 0.33725) (1.00000, 1.00000, 0.37647) (0.85490, 0.00000, 0.00000) (0.68235, 0.00000, 0.00000) (0.96863, 0.50980, 0.74510) (1.00000, 1.00000, 1.00000) (0.46667, 0.00000, 0.49020) I've tried to use the NWSStormClearReflectivity.tbl file that comes with metpy and got the same error. – Souda Mar 30 '20 at 20:49
  • Or you can download it here: https://drive.google.com/open?id=1jDJMadKBUDkDX6x2ib4V48jYd90Huarf – Souda Mar 30 '20 at 20:53

1 Answers1

0

The first argument to add_colortable is not a filename, but a file-like object, so you need to call open() yourself:

from metpy.plots import ctables

ctables.registry.add_colortable(open('zdr_table.tbl', 'rt'),'nexrad_zdr')
zdr_cmap = ctables.registry.get_colortable('nexrad_zdr')
DopplerShift
  • 5,472
  • 1
  • 21
  • 20