Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

pycama / src / temis_color_tables.py @ 816:d52976b6ccfc

History | View | Annotate | Download (11.4 KB)

1
#!/usr/bin/env python3
2

    
3
import numpy as np
4
from matplotlib import pyplot as plt
5
from matplotlib.colors import LinearSegmentedColormap
6
from matplotlib import cm
7

    
8
# As used on the poster (2017).
9
colormaps_names = set(plt.colormaps())
10

    
11
if 'no2_special' not in colormaps_names:
12
    segmentdata = [(0.0, 0.0, 190/255), # dark-blue
13
                   (0.0, 1.0, 1.0), # cyan
14
                   (0.0, 1.0, 0.0), # green
15
                   (1.0, 1.0, 0.0), # yellow
16
                   (1.0, 0.0, 0.0), # red
17
                   (120/255, 30/255, 30/255)] # magenta
18

    
19
    colormap = LinearSegmentedColormap.from_list('no2_special',
20
                                                 segmentdata,
21
                                                 N=(len(segmentdata)-1)*32,
22
                                                 gamma=1.0)
23
    cm.register_cmap(cmap=colormap)
24
    # range: 0 to 1e16 molecules/cm**2
25

    
26
if 'ozone_special' not in colormaps_names:
27
    segmentdata = [(0.0, 0.0, 0.0), # black
28
                   (0.0, 0.0, 1.0), # blue
29
                   (0.0, 1.0, 1.0), # cyan
30
                   (0.0, 1.0, 0.0), # green
31
                   (1.0, 1.0, 0.0), # yellow
32
                   (1.0, 0.0, 0.0), # red
33
                   (1.0, 0.0, 1.0), # magenta
34
                   (1.0, 1.0, 1.0)] # white
35

    
36
    colormap = LinearSegmentedColormap.from_list('ozone_special',
37
                                                 segmentdata,
38
                                                 N=(len(segmentdata)-1)*32,
39
                                                 gamma=1.8)
40

    
41
    cm.register_cmap(cmap=colormap)
42

    
43
if 'WN_colors' not in colormaps_names:
44
    RGB = np.asarray([(143,133,186),
45
           ( 79, 72,149),
46
           (  0, 57,128),
47
           (  0, 84,157),
48
           (  0,112,184),
49
           (  0,139,208),
50
           (  0,158,205),
51
           (  1,168,186),
52
           ( 45,183,185),
53
           (  0,153,161),
54
           (  0,125,143),
55
           (  0,113,109),
56
           (  1, 89, 47),
57
           (  0,109, 51),
58
           ( 40,154, 67),
59
           (118,184, 86),
60
           (149,195,107),
61
           (175,203, 82),
62
           (197,213, 80),
63
           (222,219,  0),
64
           (241,229, 31),
65
           (255,240, 63),
66
           (255,244,129),
67
           (255,246,177),
68
           (255,241,196),
69
           (255,231,171),
70
           (253,213,144),
71
           (250,193,114),
72
           (247,170, 66),
73
           (239,127,  1),
74
           (235,105,  9),
75
           (232, 79, 19),
76
           (228, 46, 24),
77
           (227,  0, 27),
78
           (209,  0, 24),
79
           (189, 10, 29),
80
           (152, 27, 33),
81
           (102, 38, 36),
82
           ( 80, 41, 36),
83
           ( 80, 41, 36) ])
84

    
85
    scale = np.linspace(0, 1, num=RGB.shape[0])
86

    
87
    cdict = {k: [tuple(s) for s in list(np.transpose(v))]
88
                for k, v in zip(['red', 'green', 'blue'],
89
                    [[scale, RGB[:, j]/255, RGB[:, j]/255] for j in range(3)])}
90
    gamma=1.6
91

    
92
    # Make custom color map with gradients between steunkleuren
93
    colormap = LinearSegmentedColormap('WN_colors', cdict, gamma=gamma)
94

    
95
    cm.register_cmap(cmap=colormap)
96

    
97
if 'no2_total_column' not in colormaps_names:
98
    RGB = np.asarray([(255, 255, 255), 
99
            (252, 254, 255), 
100
            (250, 253, 255), 
101
            (247, 252, 254), 
102
            (244, 251, 254), 
103
            (242, 250, 254), 
104
            (239, 249, 254), 
105
            (234, 247, 253), 
106
            (231, 246, 253), 
107
            (229, 245, 253), 
108
            (226, 244, 253), 
109
            (223, 243, 252), 
110
            (221, 242, 252), 
111
            (218, 241, 252), 
112
            (213, 239, 252), 
113
            (210, 238, 251), 
114
            (207, 237, 251), 
115
            (205, 236, 251), 
116
            (202, 235, 251), 
117
            (199, 234, 250), 
118
            (197, 233, 250), 
119
            (191, 231, 250), 
120
            (189, 230, 250), 
121
            (186, 229, 249), 
122
            (183, 228, 249), 
123
            (181, 227, 249), 
124
            (178, 226, 249), 
125
            (176, 225, 249), 
126
            (170, 223, 248), 
127
            (168, 222, 248), 
128
            (165, 221, 248), 
129
            (162, 220, 247), 
130
            (157, 218, 247), 
131
            (155, 216, 246), 
132
            (152, 214, 245), 
133
            (148, 210, 242), 
134
            (146, 208, 241), 
135
            (143, 206, 240), 
136
            (141, 204, 238), 
137
            (139, 202, 237), 
138
            (136, 200, 236), 
139
            (134, 197, 235), 
140
            (129, 193, 232), 
141
            (127, 191, 231), 
142
            (125, 189, 230), 
143
            (123, 187, 229), 
144
            (120, 185, 228), 
145
            (118, 183, 226), 
146
            (116, 181, 225), 
147
            (111, 177, 223), 
148
            (109, 175, 221), 
149
            (106, 173, 220), 
150
            (104, 171, 219), 
151
            (102, 169, 218), 
152
            (100, 167, 217), 
153
            (97, 165, 215), 
154
            (93, 160, 213), 
155
            (90, 158, 212), 
156
            (88, 156, 211), 
157
            (86, 154, 209), 
158
            (83, 152, 208), 
159
            (81, 150, 207), 
160
            (79, 148, 206), 
161
            (72, 142, 202), 
162
            (72, 144, 195), 
163
            (72, 145, 191), 
164
            (72, 146, 188), 
165
            (72, 147, 184), 
166
            (72, 148, 181), 
167
            (72, 150, 173), 
168
            (72, 151, 170), 
169
            (72, 153, 166), 
170
            (72, 154, 163), 
171
            (72, 155, 159), 
172
            (72, 156, 156), 
173
            (72, 157, 152), 
174
            (72, 159, 145), 
175
            (72, 160, 141), 
176
            (72, 161, 138), 
177
            (73, 162, 134), 
178
            (73, 163, 131), 
179
            (73, 164, 127), 
180
            (73, 165, 124), 
181
            (73, 167, 116), 
182
            (73, 168, 113), 
183
            (73, 169, 109), 
184
            (73, 170, 106), 
185
            (73, 172, 102), 
186
            (73, 173, 99), 
187
            (73, 174, 95), 
188
            (73, 176, 88), 
189
            (73, 177, 84), 
190
            (73, 178, 81), 
191
            (73, 179, 77), 
192
            (73, 181, 70), 
193
            (78, 182, 71), 
194
            (83, 184, 71), 
195
            (92, 187, 72), 
196
            (97, 188, 73), 
197
            (102, 189, 74), 
198
            (106, 191, 74), 
199
            (111, 192, 75), 
200
            (116, 193, 75), 
201
            (121, 195, 76), 
202
            (130, 198, 77), 
203
            (135, 199, 78), 
204
            (140, 200, 78), 
205
            (145, 202, 79), 
206
            (150, 203, 80), 
207
            (154, 204, 80), 
208
            (159, 206, 81), 
209
            (169, 209, 82), 
210
            (173, 210, 82), 
211
            (178, 211, 83), 
212
            (183, 213, 84), 
213
            (188, 214, 84), 
214
            (193, 215, 85), 
215
            (197, 217, 85), 
216
            (207, 220, 87), 
217
            (212, 221, 87), 
218
            (217, 222, 88), 
219
            (221, 224, 88), 
220
            (226, 225, 89), 
221
            (231, 226, 90), 
222
            (236, 228, 90), 
223
            (245, 231, 91), 
224
            (250, 232, 92), 
225
            (250, 229, 91), 
226
            (250, 222, 88), 
227
            (249, 218, 86), 
228
            (249, 215, 85), 
229
            (249, 208, 82), 
230
            (249, 205, 81), 
231
            (249, 201, 80), 
232
            (249, 198, 78), 
233
            (249, 195, 77), 
234
            (248, 191, 75), 
235
            (248, 188, 74), 
236
            (248, 181, 71), 
237
            (248, 178, 70), 
238
            (248, 174, 69), 
239
            (248, 171, 67), 
240
            (247, 167, 66), 
241
            (247, 164, 64), 
242
            (247, 160, 63), 
243
            (247, 154, 60), 
244
            (247, 150, 59), 
245
            (247, 147, 58), 
246
            (246, 143, 56), 
247
            (246, 140, 55), 
248
            (246, 137, 53), 
249
            (246, 133, 52), 
250
            (246, 126, 49), 
251
            (246, 123, 48), 
252
            (246, 120, 47), 
253
            (245, 116, 45), 
254
            (245, 113, 44), 
255
            (245, 106, 41), 
256
            (244, 104, 41), 
257
            (242, 100, 41), 
258
            (241, 98, 41), 
259
            (240, 96, 41), 
260
            (239, 94, 41), 
261
            (239, 92, 41), 
262
            (238, 90, 41), 
263
            (237, 88, 41), 
264
            (235, 84, 41), 
265
            (234, 82, 41), 
266
            (233, 80, 41), 
267
            (232, 78, 41), 
268
            (231, 76, 41), 
269
            (230, 74, 41), 
270
            (229, 72, 41), 
271
            (228, 67, 40), 
272
            (227, 65, 40), 
273
            (226, 63, 40), 
274
            (225, 61, 40), 
275
            (224, 58, 39), 
276
            (223, 55, 38), 
277
            (222, 53, 37), 
278
            (220, 47, 35), 
279
            (219, 44, 34), 
280
            (218, 41, 33), 
281
            (217, 38, 32), 
282
            (217, 35, 31), 
283
            (216, 33, 30), 
284
            (215, 30, 29), 
285
            (213, 25, 25), 
286
            (211, 23, 23), 
287
            (209, 21, 21), 
288
            (204, 18, 18), 
289
            (202, 16, 16), 
290
            (200, 15, 15), 
291
            (196, 12, 12), 
292
            (193, 11, 11), 
293
            (191, 10, 10), 
294
            (188, 8, 8), 
295
            (186, 7, 7), 
296
            (184, 6, 6), 
297
            (181, 6, 6), 
298
            (176, 4, 4), 
299
            (173, 3, 3), 
300
            (171, 3, 3), 
301
            (168, 2, 2), 
302
            (165, 1, 1), 
303
            (163, 1, 1), 
304
            (160, 1, 1), 
305
            (155, 0, 0), 
306
            (152, 0, 0), 
307
            (149, 0, 0), 
308
            (146, 0, 0), 
309
            (143, 0, 0), 
310
            (141, 0, 0), 
311
            (138, 0, 0), 
312
            (132, 0, 0), 
313
            (129, 0, 0), 
314
            (126, 0, 0), 
315
            (122, 0, 0), 
316
            (119, 0, 0), 
317
            (115, 0, 0), 
318
            (111, 0, 0), 
319
            (106, 0, 0), 
320
            (103, 0, 0), 
321
            (101, 0, 0), 
322
            (98, 0, 0), 
323
            (94, 0, 0), 
324
            (90, 0, 0), 
325
            (89, 0, 0), 
326
            (82, 0, 0), 
327
            (78, 0, 0), 
328
            (77, 0, 0), 
329
            (73, 0, 0), 
330
            (71, 0, 0), 
331
            (66, 0, 0), 
332
            (64, 0, 0), 
333
            (59, 0, 0), 
334
            (54, 0, 0), 
335
            (52, 0, 0), 
336
            (50, 0, 0), 
337
            (47, 0, 0), 
338
            (44, 0, 0), 
339
            (40, 0, 0), 
340
            (36, 0, 0), 
341
            (32, 0, 0), 
342
            (29, 0, 0), 
343
            (26, 0, 0), 
344
            (24, 0, 0), 
345
            (21, 0, 0), 
346
            (19, 0, 0), 
347
            (17, 0, 0), 
348
            (14, 0, 0), 
349
            (11, 0, 0), 
350
            (8, 0, 0), 
351
            (5, 0, 0), 
352
            (3, 0, 0), 
353
            (1, 0, 0)])
354
    scale = np.linspace(0, 1, num=RGB.shape[0])
355

    
356
    cdict = {k: [tuple(s) for s in list(np.transpose(v))]
357
                for k, v in zip(['red', 'green', 'blue'],
358
                    [[scale, RGB[:, j]/255, RGB[:, j]/255] for j in range(3)])}
359

    
360
    gamma=1.6
361

    
362
    # Make custom color map with gradients between steunkleuren
363
    colormap = LinearSegmentedColormap('no2_total_column', cdict, gamma=gamma)
364

    
365
    cm.register_cmap(cmap=colormap)
366

    
367

    
368
if __name__ == "__main__":
369
    import numpy as np
370
    import matplotlib.pyplot as plt
371
    gradient = np.linspace(0, 1, 1024)
372
    gradient = np.vstack((gradient, gradient))
373
    def plot_color_gradients():
374
        fig, axes = plt.subplots(nrows=3)
375
        fig.subplots_adjust(top=0.95, bottom=0.01, left=0.2, right=0.99)
376
        axes[0].set_title('special color tables (ozone, no2, W-N)', fontsize=14)
377
        for ax, name in zip(axes, ('no2_special', 'ozone_special', 'WN_colors')):
378
            ax.imshow(gradient, aspect='auto', cmap=plt.get_cmap(name))
379
            pos = list(ax.get_position().bounds)
380
            x_text = pos[0] - 0.01
381
            y_text = pos[1] + pos[3]/2.
382
            fig.text(x_text, y_text, name, va='center', ha='right', fontsize=10)
383
            for ax in axes:
384
                ax.set_axis_off()
385

    
386
    plot_color_gradients()
387
    plt.show()