|
From: Eric E. <ems...@ob...> - 2005-01-11 15:27:27
|
HI again,
I have questions of how to generate new LUTs outside matplotlib.
3 main issues:
1/ how to create a new lut in the same way that cm.py/colors.py is doing it
in matplotlib
2/ how to create a new lut which is given by a set of e.g., 256 colours
levels (R, G, B)
but not as a segmented array as in cm/colors
3/ How do you rescale a lut without rescaling the array itself?
(so an equivalent to load/itt log for example in Midas for those who know).
For example I would like to use the jet lut but with a log increase
of the lut so that e.g. displaying the color bar shows it is in ''log''
For 1, I am not so sure what to do, and for 2/ I give below
what I am doing at the moment. To be frank, it looks quite ugly
(mainly because I am a bad programmer and don't know so much about
python/matplotlib).
I got inspired by cm and colors.py and Midas lut
but really this is probably not the way to go.
In order to change the lut I just then do:
lut('mylut')
where 'mylut.lasc' is then the ascii file where the 256 colours are
given in 3 columns
(R G B) of 256 rows
The problem is that since I do not have the corresponding segmented
array for each
lut (and I don't want it to be that way) I need to define a ''dummy'' array.
Then each time I use imshow I must reload the lut (otherwise it uses
this dummy segmented
array which is here a gray lut).
I am not sure this is all clear, but basically what I am trying to do
here is to just
answer questions 1, 2, 3 above and below is an ugly solution for 2 (but
incomplete).
Any help is welcome. Thanks.
Eric
#########################################################################################
"""######################################
# MIDAS-LIKE LUT and ITT ??
######################################"""
_dummy_data = {'red': ((0., 0, 0), (1., 1, 1)),
'green': ((0., 0, 0), (1., 1, 1)),
'blue': ((0., 0, 0), (1., 1, 1))}
class myMidasLut(colors.LinearSegmentedColormap):
""" Definition of luts a la Midas, with R, G, and B levels
"""
def __init__(self, name='grey', alpha=1.0):
self.LUT_PATH = '/softwares/python/pycral/midaslut/'
self._red_lut = arange(256)/255.
self._green_lut = arange(256)/255.
self._blue_lut = arange(256)/255.
self._isinit = True
self.name = name
self.N = 256
cm.datad[name] = _dummy_data
def new(self,name, alpha=1.0):
sname = str(name)
sname = self.LUT_PATH+sname+".lasc"
if os.path.isfile(sname):
f = open(sname)
list = f.readlines()
for i in range(256):
self._red_lut[i] = float(list[i].split()[0])
self._green_lut[i] = float(list[i].split()[1])
self._blue_lut[i] = float(list[i].split()[2])
f.close
self.name = name
else :
print 'ERROR: Lut file', name,'does not exist'
rc('image', cmap=name)
im = gci()
if im is not None:
im.set_cmap(self)
im.set_alpha(alpha)
draw_if_interactive()
cm.datad[name] = _dummy_data
################ Default Lut initialisation ##
pglut = myMidasLut()
################ Function to change the lut ##
def lut (name, alpha=1.0) :
pglut.new(name, alpha)
#########################################################################################
--
===============================================================
Observatoire de Lyon ems...@ob...
9 av. Charles-Andre tel: +33 4 78 86 83 84
69561 Saint-Genis Laval Cedex fax: +33 4 78 86 83 86
France http://www-obs.univ-lyon1.fr/eric.emsellem
===============================================================
|