Beispiel #1
0
    def test_rgb_to_rgb_percent(self):
        """
        Test conversion from integer RGB triplet to percent RGB
        triplet.
        """
        test_pairs = (((255, 255, 255), (u'100%', u'100%', u'100%')),
                      ((0, 0, 128), (u'0%', u'0%', u'50%')),
                      ((218, 165, 32), (u'85.49%', u'64.71%', u'12.5%')))

        for triplet, percent_triplet in test_pairs:
            self.assertEqual(percent_triplet,
                             webcolors.rgb_to_rgb_percent(triplet))
Beispiel #2
0
    def test_rgb_to_rgb_percent(self):
        """
        Test conversion from integer RGB triplet to percent RGB
        triplet.
        """
        test_pairs = (((255, 255, 255), (u'100%', u'100%', u'100%')),
                      ((0, 0, 128), (u'0%', u'0%', u'50%')),
                      ((218, 165, 32), (u'85.49%', u'64.71%', u'12.5%')))

        for triplet, percent_triplet in test_pairs:
            self.assertEqual(percent_triplet,
                             webcolors.rgb_to_rgb_percent(triplet))
    def test_rgb_to_rgb_percent(self):
        """
        Test conversion from integer RGB triplet to percent RGB
        triplet.

        """
        test_pairs = (
            ((255, 255, 255), ("100%", "100%", "100%")),
            ((0, 0, 128), ("0%", "0%", "50%")),
            ((218, 165, 32), ("85.49%", "64.71%", "12.5%")),
        )

        for triplet, percent_triplet in test_pairs:
            result = webcolors.rgb_to_rgb_percent(triplet)
            assert isinstance(result, webcolors.PercentRGB)
            assert percent_triplet == result
    def test_rgb_to_rgb_percent(self):
        """
        Test conversion from integer RGB triplet to percent RGB
        triplet.

        """
        test_pairs = (
            ((255, 255, 255), (u'100%', u'100%', u'100%')),
            ((0, 0, 128), (u'0%', u'0%', u'50%')),
            ((218, 165, 32), (u'85.49%', u'64.71%', u'12.5%'))
        )

        for triplet, percent_triplet in test_pairs:
            result = webcolors.rgb_to_rgb_percent(triplet)
            assert isinstance(result, webcolors.PercentRGB)
            assert percent_triplet == result
Beispiel #5
0
    def generateLegendFig(self, legenddict):

        # First process the data: the goal is to
        # create several lists to be used while
        # generating figures.

        alllevels = []
        alllevellabel = []
        alllevelrgbs = []
        alltitle = [
            'Runoff (mm)', 'Erosion (ton/ha)', 'Total N (kg/ha)',
            'Total P (kg/ha)'
        ]

        for k1, v1 in legenddict.items():

            levels = []
            levellabel = []
            levelrgbs = []

            for k2, v2 in v1.items():
                levels.append(k1.replace('level', ''))

                if k1 == 'runoff':
                    levellabel.append('%i to %i' %
                                      (int(v2["min"]), int(v2["max"])))

                else:
                    levellabel.append('%3.2f to %3.2f' %
                                      (v2["min"], v2["max"]))

                rgbfloat = None
                rgbfloat = webcolors.rgb_to_rgb_percent(
                    (v2["RGB1"], v2["RGB2"], v2["RGB3"]))

                a = float(rgbfloat[0].replace('%', '')) / 100.0
                b = float(rgbfloat[1].replace('%', '')) / 100.0
                c = float(rgbfloat[2].replace('%', '')) / 100.0

                levelrgbs.append((a, b, c))

            alllevels.append(levels)
            alllevellabel.append(levellabel)
            alllevelrgbs.append(levelrgbs)

        return alllevels, alllevellabel, alllevelrgbs, alltitle
Beispiel #6
0
def rgb_to_percent(rgb_str):
    color = webcolors.rgb_to_rgb_percent(map(int, rgb_str.split()))
    return [float(i.strip('%'))/100.0 for i in color]
Beispiel #7
0
 def test_triplet_conversion(self):
     for int_triplet in int_colors():
         self.assertEqual(
             int_triplet,
             webcolors.rgb_percent_to_rgb(
                 webcolors.rgb_to_rgb_percent(int_triplet)))
Beispiel #8
0
unique_arrays = unique_rgb(rug_small)

#herrschner color name conversions
unique_herrschners = []
for unique_array in unique_arrays:
    unique_herrschners = np.append(
        unique_herrschners, closest_herrschners_name(unique_array.tolist()))
unique_herrschners = np.unique(unique_herrschners)
df = pd.DataFrame(unique_herrschners)
df.to_csv(github_filepath + '/pixelate/data/' + rug_name + '/colors.csv')

## plot all herrschners colors in image
color_plts = []
for unique_herrschner in unique_herrschners:
    color_plts.append(
        webcolors.rgb_to_rgb_percent(herrschners_name[unique_herrschner]))

color_flts = []
for color_plt in color_plts:
    color_flts.append(
        tuple(
            float("." + x.replace(".", "").replace("%", "").zfill(4))
            for x in color_plt))

fig = plt.figure()
ax = fig.add_subplot(111)

ratio = 1.0 / 3.0
count = math.ceil(math.sqrt(len(color_flts)))
x_count = count * ratio
y_count = count / ratio
def rgb_to_percent(rgb_list):
    # print(rgb_list)
    color = webcolors.rgb_to_rgb_percent(rgb_list)

    return [float(i.strip('%')) / 100.0 for i in color]
Beispiel #10
0
 def test_triplet_conversion(self):
     for int_triplet in int_colors():
         conversion = webcolors.rgb_percent_to_rgb(
             webcolors.rgb_to_rgb_percent(int_triplet))
         assert int_triplet == conversion
Beispiel #11
0
 def test_triplet_conversion(self):
     for int_triplet in int_colors():
         conversion = webcolors.rgb_percent_to_rgb(
             webcolors.rgb_to_rgb_percent(int_triplet)
         )
         assert int_triplet == conversion
Beispiel #12
0
 def rgb_print(self, rgb_str, str, end=' '):
     #print(str)
     color = webcolors.rgb_to_rgb_percent(map(int,rgb_str.split()))
     console.set_color(*[float(i.strip('%'))/100.0 for i in color])
     print(str, end=end)
     console.set_color()
herrschners_name = {}
for rgb, name in names_and_rgbs:
    herrschners_name[name] = rgb

#write dict to import later
with open(GITHUB_FILEPATH + '/pixelate/data/herrschners_name.csv',
          'w',
          newline='') as csv_file:
    writer = csv.writer(csv_file)
    for key, value in herrschners_name.items():
        writer.writerow([key, value])

## plot all herrchners colors
color_plts = []
for rgb in rgbs:
    color_plts.append(webcolors.rgb_to_rgb_percent(rgb))

color_flts = []
for color_plt in color_plts:
    color_flts.append(
        tuple(
            float("." + x.replace(".", "").replace("%", "").zfill(4))
            for x in color_plt))

fig = plt.figure()
ax = fig.add_subplot(111)

ratio = float(1.0 / 3.0)
count = math.ceil(math.sqrt(len(color_flts)))
x_count = count * ratio
y_count = count / ratio
Beispiel #14
0
 def test_triplet_conversion(self):
     for int_triplet in int_colors():
         self.assertEqual(int_triplet,
                          webcolors.rgb_percent_to_rgb(
                              webcolors.rgb_to_rgb_percent(int_triplet)))