A time ago I wrote this script, using pil and colorsys to convert the colors:
# pd[x, y][3] = Alpha Code van de current Pixel. Alpha = 0, dan is pixel transparant.
if pd[x, y][3] == 0:
continue
#label
if pd[x,y][0] < 10 and pd[x,y][1] < 10 and pd[x,y][2] < 10:
pd[x,y] = (0,0,0,0)
if pd[x,y][0] > 250 and pd[x,y][1] > 250 and pd[x,y][2] > 250:
pd[x,y] = (0,0,0,0)
# A is niet 0, 1 maar 0 tot 255.
#middle high precip
if pd[x,y][1] == 255 and pd[x,y][0] > 100:
pd[x,y] = (255,127,1,240)
if pd[x, y][2] == 255:
#low intense
pd[x, y] = (10,100,0,240)
#high precip
if pd[x,y][0] > 190 and pd[x,y][1] > 150 and pd[x,y][2] == 0:
pd[x,y] = (252,6,1,240)
#somewhat higher then middle but lower than middle high precip
if pd[x,y][1] == 255 and pd[x,y][0] < 55 and pd[x,y][2] < 155:
pd[x,y] = (250,250,0,240)
#middle intense
if pd[x,y][1] >= 75 and pd[x,y][2] >= 100:
pd[x,y] = (5,200,5,240)
#Extreme precip
if pd[x,y][0] >= 150 and pd[x,y][1] < 150 and pd[x,y][2] == 0:
pd[x,y] = (255,0,255,240)
Back then it gave a good result, but now I want to make it more smooth. In some of my other script i've got this:
def make_colormap(seq):
"""Return a LinearSegmentedColormap
seq: a sequence of floats and RGB-tuples. The floats should be increasing
and in the interval (0,1).
"""
seq = [(None,) * 3, 0.0] + list(seq) + [1.0, (None,) * 3]
cdict = {'red': [], 'green': [], 'blue': []}
for i, item in enumerate(seq):
if isinstance(item, float):
r1, g1, b1 = seq[i - 1]
r2, g2, b2 = seq[i + 1]
cdict['red'].append([item, r1, r2])
cdict['green'].append([item, g1, g2])
cdict['blue'].append([item, b1, b2])
return mcolors.LinearSegmentedColormap('CustomMap', cdict)
c = mcolors.ColorConverter().to_rgb
rvb = make_colormap(
[c('blue') , c('cyan'), 0.2 ,c('green'), c('yellow'), 0.4, c('orange'), c('red'), 0.8 , c('darkred'), c('violet')])
Can I use that CMAP to convert the colors of my original script with the colors used in the CMap, and how do I do this? Thanks in advance!