Find the badge color based on the thresholds.
553355
def badge_color(self):
        """"""
        # If no thresholds were passed then return the default color
        if not self.thresholds:
            return self.default_color

        if self.value_type == str:
            if self.value in self.thresholds:
                return self.thresholds[self.value]
            else:
                return self.default_color

        # Convert the threshold dictionary into a sorted list of lists
        threshold_list = [[self.value_type(i[0]), i[1]] for i in self.thresholds.items()]
        threshold_list.sort(key=lambda x: x[0])

        color = None

        for threshold, color in threshold_list:
            if float(self.value) < float(threshold):
                return color

        # If we drop out the top of the range then return the last max color
        if color and self.use_max_when_value_exceeds:
            return color
        else:
            return self.default_color
491329
def match_color_index(self, color):
        
        from jcvi.utils.webcolors import color_diff
        if isinstance(color, int):
            return color
        if color:
            if isinstance(color, six.string_types):
                rgb = map(int, color.split(','))
            else:
                rgb = color.Get()
            logging.disable(logging.DEBUG)
            distances = [color_diff(rgb, x) for x in self.xlwt_colors]
            logging.disable(logging.NOTSET)
            result = distances.index(min(distances))
            self.unused_colors.discard(self.xlwt_colors[result])
            return result
211643
def get_color_dist(c1, c2):
    
    return tuple(abs(v1 - v2) for v1, v2 in itertools.izip(c1, c2))
823451
def calculate_colorbar(self):
        
        self._base._process_values()
        self._base._find_range()
        X, Y = self._base._mesh()
        C = self._base._values[:, np.newaxis]
        return X, Y, C
103266
def calculate_colors(self, values):
        """"""
        # set domain if it is not set
        _flattenedList = list(flatten(values))
        if not self.is_domain_set:
            self.set_domain(_flattenedList)

        _flattenedColors = range(len(_flattenedList))
        for count, value in enumerate(_flattenedList):
            _flattenedColors[count] = self.calculate_color(value)

        return unflatten(values, iter(_flattenedColors))
315701
def rgb(self, color_tuple):
        """"""
        # Check bounds
        self.color = tuple(map(self._apply_float_bounds, color_tuple[:3]))

        # Include alpha if necessary
        if len(color_tuple) > 3:
            self.alpha = self._apply_float_bounds(color_tuple[3])
101086
def step(colors, x, controls=None):
    x = x.ravel()
    """"""
    assert (controls[0], controls[-1]) == (0., 1.)
    ncolors = len(colors)
    assert ncolors == len(controls) - 1
    assert ncolors >= 2
    x_step = _find_controls(x, controls, ncolors-1)
    return colors[x_step, ...]
425461
def get_visible_color(color):
    """"""
    if isinstance(color, (str, type(""))):
        try:
            return getattr(_Visible, str('{}'.format(color)))
        except AttributeError:
            raise ValueError("incorrect color: {!r}".format(color))
    elif isinstance(color, tuple):
        return (0x80 ^ color[0], 0x80 ^ color[1], 0x80 ^ color[2])
    elif isinstance(color, int):
        if 0 <= color <= 0x07:
            index = color
            return 0xFF if index == 0 else 0xE8
        elif 0x08 <= color <= 0x0F:
            index = color - 0x08
            return 0xFF if index == 0 else 0xE8
        elif 0x10 <= color <= 0xE7:
            index = color - 0x10
            if 0 <= index % 36 < 18:
                return 0xFF
            else:
                return 0x10
        elif 0xE8 <= color <= 0xFF:
            index = color - 0x0E8
            return 0xFF if 0 <= index < 12 else 0xE8
    else:
        raise ValueError("incorrect color: {!r}".format(color))
1016341
def _get_result_color(self, time_taken):
        """"""
        time_taken_ms = time_taken * 1000
        if time_taken_ms <= self.timer_ok:
            color = 'green'
        elif time_taken_ms <= self.timer_warning:
            color = 'yellow'
        else:
            color = 'red'

        return color
947672
def hue(p):
    
    min_c = min(p)
    max_c = max(p)
    d = float(max_c - min_c)
    if d == 0:
        return 0

    if max_c == p[0]:
        h = (p[1] - p[2]) / d
    elif max_c == p[1]:
        h = 2 + (p[2] - p[0]) / d
    else:
        h = 4 + (p[0] - p[1]) / d
    h *= 60
    if h < 0:
        h += 360
    return h
391705
def color_interp(data):
    """"""
    from rasterio.enums import ColorInterp as ci
    modes = {'L': [ci.gray],
             'LA': [ci.gray, ci.alpha],
             'YCbCr': [ci.Y, ci.Cb, ci.Cr],
             'YCbCrA': [ci.Y, ci.Cb, ci.Cr, ci.alpha]}

    try:
        mode = ''.join(data['bands'].values)
        return modes[mode]
    except KeyError:
        colors = {'R': ci.red,
                  'G': ci.green,
                  'B': ci.blue,
                  'A': ci.alpha,
                  'C': ci.cyan,
                  'M': ci.magenta,
                  'Y': ci.yellow,
                  'H': ci.hue,
                  'S': ci.saturation,
                  'L': ci.lightness,
                  'K': ci.black,
                  }
        return [colors[band] for band in data['bands'].values]
1099088
def help(cls):
        """"""
        print("for named colors use :")
        for c in sorted(list(cls.colors.items())):
            print("{:10} {}".format(*c))
408219
def get_per_object_threshold(method, image, threshold, mask=None, labels=None,
                             threshold_range_min = None,
                             threshold_range_max = None,
                             **kwargs):
    
    if labels is None:
        labels = np.ones(image.shape,int)
        if not mask is None:
            labels[np.logical_not(mask)] = 0 
    label_extents = scipy.ndimage.find_objects(labels,np.max(labels))
    local_threshold = np.ones(image.shape,image.dtype)
    for i, extent in enumerate(label_extents, start=1):
        label_mask = labels[extent]==i
        if not mask is None:
            label_mask = np.logical_and(mask[extent], label_mask)
        values = image[extent]
        per_object_threshold = get_global_threshold(
            method, values, mask = label_mask, **kwargs)
        local_threshold[extent][label_mask] = per_object_threshold
    return local_threshold
108822
def get_brightness(self):
        """"""
        self.get_status()
        try:
            self.brightness = self.data['color'].split(';')[-1]
        except TypeError:
            self.brightness = 0

        return self.brightness
997182
def color(self, c=False):
        
        if c is False:
            return np.array(self.GetProperty().GetColor())
        elif c is None:
            self.GetMapper().ScalarVisibilityOn()
            return self
        else:
            self.GetMapper().ScalarVisibilityOff()
            self.GetProperty().SetColor(colors.getColor(c))
            return self
523826
def get_color(self, color):
        '''
        
        '''
        if color is None:
            color = self.counter
        if isinstance(color, str):
            color = CNAMES[color]
        self.counter = color + 1
        color %= len(COLORS)
        return color
1126948
private function findColor()
    {
        $code = $this->verifyCode;
        $this->verifyCode = '';

        $color = array_values($this->fontColor);
        $rand = rand(0, count($color) - 1);
        foreach ($this->fontColor as $k => $v) {
            if ($v == $this->fontColor[$rand]) {
                $this->verifyCode .= $code[$k];
            }
        }
        $this->tips = $this->baseColor[$color[$rand]]['tips'];
    }