2021-05-12T09:05 AM
(This post was last modified: 2021-05-12T09:07 AM by Sylvain Herlédan.)
Hi Pete,
My bad, in the version available on our website the converter only supports a few matplotlib colormaps, whereas we support all of them in the development version.
If you feel comfortable with using the undocumented, unsupported dev version you can find it in the attachments, otherwise you can use the workaround I suggested in my previous message by including this code in your reader:
And then pass 'matplotlib_viridis' as first argument to format_colortable.
Cheers,
Sylvain
My bad, in the version available on our website the converter only supports a few matplotlib colormaps, whereas we support all of them in the development version.
If you feel comfortable with using the undocumented, unsupported dev version you can find it in the attachments, otherwise you can use the workaround I suggested in my previous message by including this code in your reader:
Code:
import gdal
import numpy as np
import matplotlib.cm
import syntool_converter.utils.syntoolformat as stfmt
def load_colormap(name):
"""
"""
if name.startswith('matplotlib_'):
_, cmap_name = name.split('_', 1)
colormap = getattr(matplotlib.cm, cmap_name)
nodata_color = (255, 255, 255)
return colormap, nodata_color
return stfmt.load_colormap(name)
def format_colortable(name, vmin=0., vmax=1., vmin_pal=0., vmax_pal=1.,
index_min=0, index_max=254, index_nodata=255):
"""
"""
colormap, nodata_color = load_colormap(name)
norm_min = (vmin - vmin_pal) / float((vmax_pal - vmin_pal))
norm_max = (vmax - vmin_pal) / float((vmax_pal - vmin_pal))
ncols = int(index_max) - int(index_min) + 1
colors = colormap(np.linspace(norm_min, norm_max, num=ncols))
colors = np.round(colors*255)
entries = [(int(c[0]), int(c[1]), int(c[2])) for c in colors]
colortable = gdal.ColorTable()
for index in range(int(index_min), int(index_max)+1):
colortable.SetColorEntry(index, entries[index-int(index_min)])
if index_nodata != None:
colortable.SetColorEntry(index_nodata, nodata_color)
return colortable
And then pass 'matplotlib_viridis' as first argument to format_colortable.
Cheers,
Sylvain