def __init__(self, 
                 map = None,
                 layout = None,
                 model = None,
                 color = None,
                 models = None,
                 normalize = None,
                 gamma = 1.,
                 gamma_func = None,
                 **kwargs):
        alpha = kwargs.get('alpha', None)
        super(ColorMap, self).__init__(**kwargs)
        self._gamma = kwargs.get('gamma', 1.)

        assert layout is not None
        layout = layout.upper()

        ncoord = layout.count('X')
        assert ncoord in (0,1,4), "can 0,1, or 4 coordinates"
        ipos = layout.find('X')
        if ncoord == 0 :    
            if map.ndim == 1:
                n = map.size
            else:
                n = map.shape[0]
            coord = np.arange(n).reshape((1, ncoord))
            ncoord = 1
        else:
            n = map.shape[0]
            coord = np.ndarray((n, ncoord))
            for i in xrange(ncoord):
                coord[:,i] = map[:,ipos]
                ipos = layout.find('X', ipos + 1)
        if coord.dtype is not np.float64:
            coord = np.array(coord, dtype = np.float64)
        for j in xrange(ncoord):
            ii = coord[:,j] >= 0
            i, = np.where(ii)
            coord[ii,j] -= coord[i[0],j]
            coord[ii,j] /= coord[ii,j].max()

        assert layout.count('A') < 2, "can have only one alpha value"
        ipos = layout.find('A')
        if ipos >= 0:
            alpha = map[:,ipos]
        else:   
            if alpha == None:
                alpha = 1.
            alpha = np.tile(alpha, n)
        
        assert layout.count('N') < 2, "can have only one normalization value"
        ipos = layout.find('N')
        if ipos >= 0:
            normal = map[:,ipos]
        else:   
            if normalize == -1:
                normalize = None
            normal = np.tile(normalize, n)
        norm = np.empty_like(normal, dtype = np.object)
        for i,x in enumerate(normal):
            if x == 1:
                x == True
            elif x == 0:
                x = False
            else:
                x = None
            norm[i] = x
        normal = norm

        assert layout.count('M') < 2, "can have only one model value"
        ipos = layout.find('M')
        if ipos >= 0:
            model = map[:,ipos]
        else:   
            if model == None:
                model = 0
            model = np.tile(model, n)

        # models is converted to array of color objects
        if models == None:
            models = ['RGB', 'HSV', 'HSL', 'HSI']
        models = np.array(models).reshape(-1)
        m = np.empty_like(model, dtype = np.object)
        for i,x in enumerate(model):
            if not isinstance(x, str):
                x = models[x]
            m[i] = _color_models[x.upper()]
        model = m

        nc = layout.count('C')
        assert nc in (1,3), "Color has to be C or CCC"
        if nc == 0:
            if color == None:
                color = 0.
            if len(color) == 1:
                color = np.array([mx.gray(color) for mx in model])
            elif len(color) == 3:
                color = np.tile(color, (3,1))
            else:
                raise AttributeError("Wrong format in 'color' keyword.")
        if nc == 1:
            ipos = layout.find('C')
            c = map[:,ipos]
            color = np.array([mx.gray(cx) for (mx, cx) in zip(model, c)])
        else:
            color = np.ndarray((n,3))
            ipos = -1
            for i in xrange(3):
                ipos = layout.find('C', ipos + 1)
                color[:,i] = map[:,ipos]
        # normalize
        # 1) auto-detect
        d = dict()
        for i in xrange(n):
            if normal[i] is None:
                m = model[i]
                c = color[i]
                try:
                    limits = d[m]
                    limits[:,0] = np.minimum(limit[:,0],c)
                    limits[:,1] = np.maximum(limit[:,1],c)
                except:
                    limits = np.tile(c,(2,1)).transpose()
                d[m] = limits
        for m,l in d.items():    
            d[m] = not m.is_normal(l)
        # 2) do normalization
        for i in xrange(n):
            m = model[i]
            if normal[i] is None:
                normal[i] = d[m]
            if normal[i]:
                color[i,:] = m.normalize(color[i,:])
                
        # combine color and alpha
        color = np.hstack((color, alpha.reshape(-1,1)))

        # ADD/TREAT 'invalid' colors [bad [, lower, upper]]
        ii = coord[:, 0] < 0
        im,= np.where(ii)
        assert im.size in (0,1,3), "Only [bad [, lower, upper]] allowed for 'invalid' colors"
        if im.size > 0:
            i = im[0]
            self._rgba_bad = np.hstack((model[i](color[i,0:3]),color[i,3]))
            if im.size > 1:
                i = im[1]
                self._rgba_lower = np.hstack((model[i](color[i,0:3]),color[i,3]))
                i = im[2]
                self._rgba_upper = np.hstack((model[i](color[i,0:3]),color[i,3]))
            jj = np.logical_not(ii)
            map   = map  [:,jj]
            color = color[:,jj]
            model = model[:,jj]
            coord = coord[:,jj]
            
        # convert to N x 4 array for gamma
        ng = layout.count('G')
        assert nc in (1,3), "Gamma has to be G, GG, GGG, or GGGG"
        if ng == 0:
            gamma = np.tile(1., (n,4))    
        if ng == 1:
            ipos = layout.find('G')
            g = map[:,ipos]
            gamma = np.tile(g,(4,1)).transpose()
        if ng == 2:
            ipos = layout.find('G')
            g = map[:,ipos]
            gamma = np.tile(g,(4,1)).transpose()
            ipos = layout.find('G', ipos+1)
            g = map[:,ipos]
            gamma[:,3] = g
        if ng == 3:
            gamma = np.ndarray((n,4), dtype = map.dtype)
            ipos = -1
            for i in xrange(3):
                ipos = layout.find('G', ipos + 1)
                gamma[:,i] = map[:,ipos]
            gamma[:,3] = np.tile(1., n)    
        if ng == 4:
            gamma = np.ndarray((n,4), dtype = map.dtype)
            ipos = -1
            for i in xrange(4):
                ipos = layout.find('G', ipos + 1)
                gamma[:,i] = map[:,ipos]        

        # translate to functions
        if gamma_func == None:
            gamma_func = lambda x, gamma: np.power(x, gamma)
        assert isinstance(gamma_func, types.FunctionType), (
            "gamma_func needs to be a function")
        if gamma.dtype == np.object:
            g = gamma
        else:
            g = np.empty_like(gamma, dtype = object)
        identiy = lambda x: x
        for i,f in enumerate(gamma.flat):
            if not isinstance(f, types.FunctionType):
                if f is None:
                    g.flat[i] = identity 
                else:
                    g.flat[i] = partial(gamma_func, gamma = f)    
        gamma = g

        # save setup
        self.n = n
        self.gamma = gamma
        self.color = color
        self.model = model
        self.coord = coord
        self.ncoord = ncoord
Write a 16-bit value to the specified register.
dataset/ETHPy150Open yhat/ggplot/ggplot/utils/color.py/ColorMap.__init__--crossover with--dataset/ETHPy150Open adafruit/Adafruit_Python_GPIO/Adafruit_GPIO/I2C.py/Device.write16