summaryrefslogtreecommitdiff
path: root/silx/gui/plot/_utils/test/testColormap.py
blob: d77fa6586b94af53e6cadaa118b9cdd25cdc05d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
# coding: utf-8
# /*##########################################################################
#
# Copyright (c) 2017 European Synchrotron Radiation Facility
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
# ###########################################################################*/

import logging
import time
import unittest

import numpy
from PyMca5 import spslut

from silx.image.colormap import dataToRGBAColormap

_logger = logging.getLogger(__name__)

# TODOs:
# what to do with max < min: as SPS LUT or also invert outside boundaries?
# test usedMin and usedMax
# benchmark


# common ######################################################################

class _TestColormap(unittest.TestCase):
    # Array data types to test
    FLOATING_DTYPES = numpy.float16, numpy.float32, numpy.float64
    SIGNED_DTYPES = FLOATING_DTYPES + (numpy.int8, numpy.int16,
                                       numpy.int32, numpy.int64)
    UNSIGNED_DTYPES = numpy.uint8, numpy.uint16, numpy.uint32, numpy.uint64
    DTYPES = SIGNED_DTYPES + UNSIGNED_DTYPES

    # Array sizes to test
    SIZES = 2, 10, 256, 1024  # , 2048, 4096

    # Colormaps definitions
    _LUT_RED_256 = numpy.zeros((256, 4), dtype=numpy.uint8)
    _LUT_RED_256[:, 0] = numpy.arange(256, dtype=numpy.uint8)
    _LUT_RED_256[:, 3] = 255

    _LUT_RGB_3 = numpy.array(((255, 0, 0, 255),
                              (0, 255, 0, 255),
                              (0, 0, 255, 255)), dtype=numpy.uint8)

    _LUT_RGB_768 = numpy.zeros((768, 4), dtype=numpy.uint8)
    _LUT_RGB_768[0:256, 0] = numpy.arange(256, dtype=numpy.uint8)
    _LUT_RGB_768[256:512, 1] = numpy.arange(256, dtype=numpy.uint8)
    _LUT_RGB_768[512:768, 1] = numpy.arange(256, dtype=numpy.uint8)
    _LUT_RGB_768[:, 3] = 255

    COLORMAPS = {
        'red 256': _LUT_RED_256,
        'rgb 3': _LUT_RGB_3,
        'rgb 768': _LUT_RGB_768,
    }

    @staticmethod
    def _log(*args):
        """Logging used by test for debugging."""
        _logger.debug(str(args))

    @staticmethod
    def buildControlPixmap(data, colormap, start=None, end=None,
                           isLog10=False):
        """Generate a pixmap used to test C pixmap."""
        if isLog10:  # Convert to log
            if start is None:
                posValue = data[numpy.nonzero(data > 0)]
                if posValue.size != 0:
                    start = numpy.nanmin(posValue)
                else:
                    start = 0.

            if end is None:
                end = numpy.nanmax(data)

            start = 0. if start <= 0. else numpy.log10(start,
                                                       dtype=numpy.float64)
            end = 0. if end <= 0. else numpy.log10(end,
                                                   dtype=numpy.float64)

            data = numpy.log10(data, dtype=numpy.float64)
        else:
            if start is None:
                start = numpy.nanmin(data)
            if end is None:
                end = numpy.nanmax(data)

        start, end = float(start), float(end)
        min_, max_ = min(start, end), max(start, end)

        if start == end:
            indices = numpy.asarray((len(colormap) - 1) * (data >= max_),
                                    dtype=numpy.int)
        else:
            clipData = numpy.clip(data, min_, max_)  # Clip first avoid overflow
            scale = len(colormap) / (end - start)
            normData = scale * (numpy.asarray(clipData, numpy.float64) - start)

            # Clip again to makes sure <= len(colormap) - 1
            indices = numpy.asarray(numpy.clip(normData,
                                               0, len(colormap) - 1),
                                    dtype=numpy.uint32)

        pixmap = numpy.take(colormap, indices, axis=0)
        pixmap.shape = data.shape + (4,)
        return numpy.ascontiguousarray(pixmap)

    @staticmethod
    def buildSPSLUTRedPixmap(data, start=None, end=None, isLog10=False):
        """Generate a pixmap with SPS LUT.
        Only supports red colormap with 256 colors.
        """
        colormap = spslut.RED
        mapping = spslut.LOG if isLog10 else spslut.LINEAR

        if start is None and end is None:
            autoScale = 1
            start, end = 0, 1
        else:
            autoScale = 0
            if start is None:
                start = data.min()
            if end is None:
                end = data.max()

        pixmap, size, minMax = spslut.transform(data,
                                                (1, 0),
                                                (mapping, 3.0),
                                                'RGBX',
                                                colormap,
                                                autoScale,
                                                (start, end),
                                                (0, 255),
                                                1)
        pixmap.shape = data.shape[0], data.shape[1], 4

        return pixmap

    def _testColormap(self, data, colormap, start, end, control=None,
                      isLog10=False, nanColor=None):
        """Test pixmap built with C code against SPS LUT if possible,
        else against Python control code."""
        startTime = time.time()
        pixmap = dataToRGBAColormap(data,
                                    colormap,
                                    start,
                                    end,
                                    isLog10,
                                    nanColor)
        duration = time.time() - startTime

        # Compare with result
        controlType = 'array'
        if control is None:
            startTime = time.time()

            # Compare with SPS LUT if possible
            if (colormap.shape == self.COLORMAPS['red 256'].shape and
                    numpy.all(numpy.equal(colormap, self.COLORMAPS['red 256'])) and
                    data.size % 2 == 0 and
                    data.dtype in (numpy.float32, numpy.float64)):
                # Only works with red colormap and even size
                # as it needs 2D data
                if len(data.shape) == 1:
                    data.shape = data.size // 2, -1
                    pixmap.shape = data.shape + (4,)
                control = self.buildSPSLUTRedPixmap(data, start, end, isLog10)
                controlType = 'SPS LUT'

            # Compare with python test implementation
            else:
                control = self.buildControlPixmap(data, colormap, start, end,
                                                  isLog10)
                controlType = 'Python control code'

            controlDuration = time.time() - startTime
            if duration >= controlDuration:
                self._log('duration', duration, 'control', controlDuration)
            # Allows duration to be 20% over SPS LUT duration
            # self.assertTrue(duration < 1.2 * controlDuration)

        difference = numpy.fabs(numpy.asarray(pixmap, dtype=numpy.float64) -
                                numpy.asarray(control, dtype=numpy.float64))
        if numpy.any(difference != 0.0):
            self._log('control', controlType)
            self._log('data', data)
            self._log('pixmap', pixmap)
            self._log('control', control)
            self._log('errors', numpy.ravel(difference))
            self._log('errors', difference[difference != 0])
            self._log('in pixmap', pixmap[difference != 0])
            self._log('in control', control[difference != 0])
            self._log('Max error', difference.max())

        # Allows a difference of 1 per channel
        self.assertTrue(numpy.all(difference <= 1.0))

        return duration


# TestColormap ################################################################

class TestColormap(_TestColormap):
    """Test common limit case for colormap in C with both linear and log mode.

    Test with different: data types, sizes, colormaps (with different sizes),
    mapping range.
    """

    def testNoData(self):
        """Test pixmap generation with empty data."""
        self._log("TestColormap.testNoData")
        cmapName = 'red 256'
        colormap = self.COLORMAPS[cmapName]

        for dtype in self.DTYPES:
            for isLog10 in (False, True):
                data = numpy.array((), dtype=dtype)
                result = numpy.array((), dtype=numpy.uint8)
                result.shape = 0, 4
                duration = self._testColormap(data, colormap,
                                              None, None, result, isLog10)
                self._log('No data', 'red 256', dtype, len(data), (None, None),
                          'isLog10:', isLog10, duration)

    def testNaN(self):
        """Test pixmap generation with NaN values and no NaN color."""
        self._log("TestColormap.testNaN")
        cmapName = 'red 256'
        colormap = self.COLORMAPS[cmapName]

        for dtype in self.FLOATING_DTYPES:
            for isLog10 in (False, True):
                # All NaNs
                data = numpy.array((float('nan'),) * 4, dtype=dtype)
                result = numpy.array(((0, 0, 0, 255),
                                      (0, 0, 0, 255),
                                      (0, 0, 0, 255),
                                      (0, 0, 0, 255)), dtype=numpy.uint8)
                duration = self._testColormap(data, colormap,
                                              None, None, result, isLog10)
                self._log('All NaNs', 'red 256', dtype, len(data),
                          (None, None), 'isLog10:', isLog10, duration)

                # Some NaNs
                data = numpy.array((1., float('nan'), 0., float('nan')),
                                   dtype=dtype)
                result = numpy.array(((255, 0, 0, 255),
                                      (0, 0, 0, 255),
                                      (0, 0, 0, 255),
                                      (0, 0, 0, 255)), dtype=numpy.uint8)
                duration = self._testColormap(data, colormap,
                                              None, None, result, isLog10)
                self._log('Some NaNs', 'red 256', dtype, len(data),
                          (None, None), 'isLog10:', isLog10, duration)

    def testNaNWithColor(self):
        """Test pixmap generation with NaN values with a NaN color."""
        self._log("TestColormap.testNaNWithColor")
        cmapName = 'red 256'
        colormap = self.COLORMAPS[cmapName]

        for dtype in self.FLOATING_DTYPES:
            for isLog10 in (False, True):
                # All NaNs
                data = numpy.array((float('nan'),) * 4, dtype=dtype)
                result = numpy.array(((128, 128, 128, 255),
                                      (128, 128, 128, 255),
                                      (128, 128, 128, 255),
                                      (128, 128, 128, 255)), dtype=numpy.uint8)
                duration = self._testColormap(data, colormap,
                                              None, None, result, isLog10,
                                              nanColor=(128, 128, 128, 255))
                self._log('All NaNs', 'red 256', dtype, len(data),
                          (None, None), 'isLog10:', isLog10, duration)

                # Some NaNs
                data = numpy.array((1., float('nan'), 0., float('nan')),
                                   dtype=dtype)
                result = numpy.array(((255, 0, 0, 255),
                                      (128, 128, 128, 255),
                                      (0, 0, 0, 255),
                                      (128, 128, 128, 255)), dtype=numpy.uint8)
                duration = self._testColormap(data, colormap,
                                              None, None, result, isLog10,
                                              nanColor=(128, 128, 128, 255))
                self._log('Some NaNs', 'red 256', dtype, len(data),
                          (None, None), 'isLog10:', isLog10, duration)


# TestLinearColormap ##########################################################

class TestLinearColormap(_TestColormap):
    """Test fill pixmap with colormap in C with linear mode.

    Test with different: data types, sizes, colormaps (with different sizes),
    mapping range.
    """

    # Colormap ranges to map
    RANGES = (None, None), (1, 10)

    def test1DData(self):
        """Test pixmap generation for 1D data of different size and types."""
        self._log("TestLinearColormap.test1DData")
        for cmapName, colormap in self.COLORMAPS.items():
            for size in self.SIZES:
                for dtype in self.DTYPES:
                    for start, end in self.RANGES:
                        # Increasing values
                        data = numpy.arange(size, dtype=dtype)
                        duration = self._testColormap(data, colormap,
                                                      start, end)

                        self._log('1D', cmapName, dtype, size, (start, end),
                                  duration)

                        # Reverse order
                        data = data[::-1]
                        duration = self._testColormap(data, colormap,
                                                      start, end)

                        self._log('1D', cmapName, dtype, size, (start, end),
                                  duration)

    def test2DData(self):
        """Test pixmap generation for 2D data of different size and types."""
        self._log("TestLinearColormap.test2DData")
        for cmapName, colormap in self.COLORMAPS.items():
            for size in self.SIZES:
                for dtype in self.DTYPES:
                    for start, end in self.RANGES:
                        # Increasing values
                        data = numpy.arange(size * size, dtype=dtype)
                        data = numpy.nan_to_num(data)
                        data.shape = size, size
                        duration = self._testColormap(data, colormap,
                                                      start, end)

                        self._log('2D', cmapName, dtype, size, (start, end),
                                  duration)

                        # Reverse order
                        data = data[::-1, ::-1]
                        duration = self._testColormap(data, colormap,
                                                      start, end)

                        self._log('2D', cmapName, dtype, size, (start, end),
                                  duration)

    def testInf(self):
        """Test pixmap generation with Inf values."""
        self._log("TestLinearColormap.testInf")

        for dtype in self.FLOATING_DTYPES:
            # All positive Inf
            data = numpy.array((float('inf'),) * 4, dtype=dtype)
            result = numpy.array(((255, 0, 0, 255),
                                  (255, 0, 0, 255),
                                  (255, 0, 0, 255),
                                  (255, 0, 0, 255)), dtype=numpy.uint8)
            duration = self._testColormap(data, self.COLORMAPS['red 256'],
                                          None, None, result)
            self._log('All +Inf', 'red 256', dtype, len(data), (None, None),
                      duration)

            # All negative Inf
            data = numpy.array((float('-inf'),) * 4, dtype=dtype)
            result = numpy.array(((255, 0, 0, 255),
                                  (255, 0, 0, 255),
                                  (255, 0, 0, 255),
                                  (255, 0, 0, 255)), dtype=numpy.uint8)
            duration = self._testColormap(data, self.COLORMAPS['red 256'],
                                          None, None, result)
            self._log('All -Inf', 'red 256', dtype, len(data), (None, None),
                      duration)

            # All +/-Inf
            data = numpy.array((float('inf'), float('-inf'),
                                float('-inf'), float('inf')), dtype=dtype)
            result = numpy.array(((255, 0, 0, 255),
                                  (0, 0, 0, 255),
                                  (0, 0, 0, 255),
                                  (255, 0, 0, 255)), dtype=numpy.uint8)
            duration = self._testColormap(data, self.COLORMAPS['red 256'],
                                          None, None, result)
            self._log('All +/-Inf', 'red 256', dtype, len(data), (None, None),
                      duration)

            # Some +/-Inf
            data = numpy.array((float('inf'), 0., float('-inf'), -10.),
                               dtype=dtype)
            result = numpy.array(((255, 0, 0, 255),
                                  (0, 0, 0, 255),
                                  (0, 0, 0, 255),
                                  (0, 0, 0, 255)), dtype=numpy.uint8)
            duration = self._testColormap(data, self.COLORMAPS['red 256'],
                                          None, None,
                                          result)  # Seg Fault with SPS
            self._log('Some +/-Inf', 'red 256', dtype, len(data), (None, None),
                      duration)

    @unittest.skip("Not for reproductible tests")
    def test1DDataRandom(self):
        """Test pixmap generation for 1D data of different size and types."""
        self._log("TestLinearColormap.test1DDataRandom")
        for cmapName, colormap in self.COLORMAPS.items():
            for size in self.SIZES:
                for dtype in self.DTYPES:
                    for start, end in self.RANGES:
                        try:
                            dtypeMax = numpy.iinfo(dtype).max
                        except ValueError:
                            dtypeMax = numpy.finfo(dtype).max
                        data = numpy.asarray(numpy.random.rand(size) * dtypeMax,
                                             dtype=dtype)
                        duration = self._testColormap(data, colormap,
                                                      start, end)

                        self._log('1D Random', cmapName, dtype, size,
                                  (start, end), duration)


# TestLog10Colormap ###########################################################

class TestLog10Colormap(_TestColormap):
    """Test fill pixmap with colormap in C with log mode.

    Test with different: data types, sizes, colormaps (with different sizes),
    mapping range.
    """
    # Colormap ranges to map
    RANGES = (None, None), (1, 10)  # , (10, 1)

    def test1DDataAllPositive(self):
        """Test pixmap generation for all positive 1D data."""
        self._log("TestLog10Colormap.test1DDataAllPositive")
        for cmapName, colormap in self.COLORMAPS.items():
            for size in self.SIZES:
                for dtype in self.DTYPES:
                    for start, end in self.RANGES:
                        # Increasing values
                        data = numpy.arange(size, dtype=dtype) + 1
                        duration = self._testColormap(data, colormap,
                                                      start, end,
                                                      isLog10=True)

                        self._log('1D', cmapName, dtype, size, (start, end),
                                  duration)

                        # Reverse order
                        data = data[::-1]
                        duration = self._testColormap(data, colormap,
                                                      start, end,
                                                      isLog10=True)

                        self._log('1D', cmapName, dtype, size, (start, end),
                                  duration)

    def test2DDataAllPositive(self):
        """Test pixmap generation for all positive 2D data."""
        self._log("TestLog10Colormap.test2DDataAllPositive")
        for cmapName, colormap in self.COLORMAPS.items():
            for size in self.SIZES:
                for dtype in self.DTYPES:
                    for start, end in self.RANGES:
                        # Increasing values
                        data = numpy.arange(size * size, dtype=dtype) + 1
                        data = numpy.nan_to_num(data)
                        data.shape = size, size
                        duration = self._testColormap(data, colormap,
                                                      start, end,
                                                      isLog10=True)

                        self._log('2D', cmapName, dtype, size, (start, end),
                                  duration)

                        # Reverse order
                        data = data[::-1, ::-1]
                        duration = self._testColormap(data, colormap,
                                                      start, end,
                                                      isLog10=True)

                        self._log('2D', cmapName, dtype, size, (start, end),
                                  duration)

    def testAllNegative(self):
        """Test pixmap generation for all negative 1D data."""
        self._log("TestLog10Colormap.testAllNegative")
        for cmapName, colormap in self.COLORMAPS.items():
            for size in self.SIZES:
                for dtype in self.SIGNED_DTYPES:
                    for start, end in self.RANGES:
                        # Increasing values
                        data = numpy.arange(-size, 0, dtype=dtype)
                        duration = self._testColormap(data, colormap,
                                                      start, end,
                                                      isLog10=True)

                        self._log('1D', cmapName, dtype, size, (start, end),
                                  duration)

                        # Reverse order
                        data = data[::-1]
                        duration = self._testColormap(data, colormap,
                                                      start, end,
                                                      isLog10=True)

                        self._log('1D', cmapName, dtype, size, (start, end),
                                  duration)

    def testCrossingZero(self):
        """Test pixmap generation for 1D data with negative and zero."""
        self._log("TestLog10Colormap.testCrossingZero")
        for cmapName, colormap in self.COLORMAPS.items():
            for size in self.SIZES:
                for dtype in self.SIGNED_DTYPES:
                    for start, end in self.RANGES:
                        # Increasing values
                        data = numpy.arange(-size/2, size/2 + 1, dtype=dtype)
                        duration = self._testColormap(data, colormap,
                                                      start, end,
                                                      isLog10=True)

                        self._log('1D', cmapName, dtype, size, (start, end),
                                  duration)

                        # Reverse order
                        data = data[::-1]
                        duration = self._testColormap(data, colormap,
                                                      start, end,
                                                      isLog10=True)

                        self._log('1D', cmapName, dtype, size, (start, end),
                                  duration)

    @unittest.skip("Not for reproductible tests")
    def test1DDataRandom(self):
        """Test pixmap generation for 1D data of different size and types."""
        self._log("TestLog10Colormap.test1DDataRandom")
        for cmapName, colormap in self.COLORMAPS.items():
            for size in self.SIZES:
                for dtype in self.DTYPES:
                    for start, end in self.RANGES:
                        try:
                            dtypeMax = numpy.iinfo(dtype).max
                            dtypeMin = numpy.iinfo(dtype).min
                        except ValueError:
                            dtypeMax = numpy.finfo(dtype).max
                            dtypeMin = numpy.finfo(dtype).min
                        if dtypeMin < 0:
                            data = numpy.asarray(-dtypeMax/2. +
                                                 numpy.random.rand(size) * dtypeMax,
                                                 dtype=dtype)
                        else:
                            data = numpy.asarray(numpy.random.rand(size) * dtypeMax,
                                                 dtype=dtype)

                        duration = self._testColormap(data, colormap,
                                                      start, end,
                                                      isLog10=True)

                        self._log('1D Random', cmapName, dtype, size,
                                  (start, end), duration)

    def testInf(self):
        """Test pixmap generation with Inf values."""
        self._log("TestLog10Colormap.testInf")

        for dtype in self.FLOATING_DTYPES:
            # All positive Inf
            data = numpy.array((float('inf'),) * 4, dtype=dtype)
            result = numpy.array(((255, 0, 0, 255),
                                  (255, 0, 0, 255),
                                  (255, 0, 0, 255),
                                  (255, 0, 0, 255)), dtype=numpy.uint8)
            duration = self._testColormap(data, self.COLORMAPS['red 256'],
                                          None, None, result, isLog10=True)
            self._log('All +Inf', 'red 256', dtype, len(data), (None, None),
                      duration)

            # All negative Inf
            data = numpy.array((float('-inf'),) * 4, dtype=dtype)
            result = numpy.array(((0, 0, 0, 255),
                                  (0, 0, 0, 255),
                                  (0, 0, 0, 255),
                                  (0, 0, 0, 255)), dtype=numpy.uint8)
            duration = self._testColormap(data, self.COLORMAPS['red 256'],
                                          None, None, result, isLog10=True)
            self._log('All -Inf', 'red 256', dtype, len(data), (None, None),
                      duration)

            # All +/-Inf
            data = numpy.array((float('inf'), float('-inf'),
                                float('-inf'), float('inf')), dtype=dtype)
            result = numpy.array(((255, 0, 0, 255),
                                  (0, 0, 0, 255),
                                  (0, 0, 0, 255),
                                  (255, 0, 0, 255)), dtype=numpy.uint8)
            duration = self._testColormap(data, self.COLORMAPS['red 256'],
                                          None, None, result, isLog10=True)
            self._log('All +/-Inf', 'red 256', dtype, len(data), (None, None),
                      duration)

            # Some +/-Inf
            data = numpy.array((float('inf'), 0., float('-inf'), -10.),
                               dtype=dtype)
            result = numpy.array(((255, 0, 0, 255),
                                  (0, 0, 0, 255),
                                  (0, 0, 0, 255),
                                  (0, 0, 0, 255)), dtype=numpy.uint8)
            duration = self._testColormap(data, self.COLORMAPS['red 256'],
                                          None, None, result, isLog10=True)
            self._log('Some +/-Inf', 'red 256', dtype, len(data), (None, None),
                      duration)


def suite():
    testSuite = unittest.TestSuite()
    for testClass in (TestColormap, TestLinearColormap):  # , TestLog10Colormap):
        testSuite.addTest(
            unittest.defaultTestLoader.loadTestsFromTestCase(testClass))
    return testSuite


if __name__ == '__main__':
    unittest.main(defaultTest='suite')