import pandas as pd
from pathlib import Path
from IPython.display import display
print('All libraries successfully imported!')
All libraries successfully imported!
computer_path = '/export/miro/ndeffense/LBRAT2104/'
color_map_path = f'{computer_path}data/COLOR_MAP/'
Path(color_map_path).mkdir(parents=True, exist_ok=True)
field_name = 'grp_A'
field_code = 'grp_A_nb'
filename_csv = f'{color_map_path}color_map_{field_name}.csv'
filename_clr = f'{color_map_path}color_map_{field_name}.clr'
df = pd.read_csv(filename_csv, sep=';', usecols=[field_name,'R','G','B','T',field_code])
df.dropna(how='all', inplace=True)
df = df.astype({'R': 'int32', 'G': 'int32', 'B': 'int32', 'T': 'int32', field_code : 'int32'})
display(df)
grp_A_nb | R | G | B | T | grp_A | |
---|---|---|---|---|---|---|
0 | 111 | 229 | 141 | 140 | 255 | Wheat |
1 | 112 | 230 | 152 | 0 | 255 | Maize |
2 | 113 | 254 | 254 | 0 | 255 | Rice |
3 | 114 | 252 | 139 | 7 | 255 | Sorghum |
4 | 115 | 108 | 158 | 217 | 255 | Barley |
5 | 116 | 183 | 148 | 64 | 255 | Rye |
6 | 117 | 95 | 196 | 204 | 255 | Oats |
7 | 118 | 255 | 255 | 153 | 255 | Millets |
8 | 119 | 104 | 204 | 178 | 255 | Other cereals |
9 | 121 | 133 | 1 | 123 | 255 | Leafy or stem vegetables |
10 | 122 | 247 | 71 | 119 | 255 | Fruit-bearing vegetables |
11 | 123 | 149 | 84 | 97 | 255 | Root, bulb or tuberous vegetables |
12 | 124 | 216 | 248 | 255 | 255 | Mushrooms and truffles |
13 | 141 | 253 | 254 | 199 | 255 | Soya beans |
14 | 142 | 215 | 158 | 158 | 255 | Groundnuts |
15 | 143 | 120 | 101 | 146 | 255 | Other oilseed crops |
16 | 151 | 107 | 68 | 11 | 255 | Potatoes |
17 | 152 | 35 | 240 | 155 | 255 | Sweet potatoes |
18 | 153 | 108 | 79 | 79 | 255 | Cassava |
19 | 154 | 244 | 8 | 183 | 255 | Yams |
20 | 161 | 234 | 110 | 58 | 255 | Spice crops |
21 | 162 | 239 | 200 | 195 | 255 | Hops |
22 | 17 | 130 | 196 | 248 | 255 | Leguminous crops |
23 | 181 | 151 | 113 | 209 | 255 | Sugar beet |
24 | 182 | 8 | 112 | 3 | 255 | Sugar cane |
25 | 3 | 137 | 188 | 31 | 255 | Grassland and meadows |
26 | 192 | 102 | 0 | 51 | 255 | Fibre crops |
27 | 1931 | 255 | 190 | 255 | 255 | Medicinal, aromatic, pesticidal or similar crops |
28 | 1941 | 255 | 253 | 56 | 255 | Flowers crops |
29 | 1991 | 172 | 103 | 42 | 255 | Tobacco |
30 | 21 | 204 | 151 | 5 | 255 | Fruits trees |
31 | 22 | 212 | 202 | 254 | 255 | Vineyards |
32 | 23 | 10 | 111 | 77 | 255 | Olive groves |
33 | 24 | 19 | 166 | 22 | 255 | Trees |
34 | 291 | 51 | 255 | 255 | 255 | Succulent plant |
35 | 5 | 102 | 102 | 0 | 255 | Shrub land |
36 | 6 | 14 | 119 | 16 | 255 | Forest |
37 | 7 | 180 | 180 | 180 | 255 | Bare soil |
38 | 8 | 244 | 12 | 26 | 255 | Build-up surface |
39 | 9 | 9 | 57 | 197 | 255 | Water bodies |
f = open(filename_clr, "w")
f.write(df.to_string(index=False, header=False))
f.close()