Пример #1
0
    def setUp(self):
        """
        Initialises common tests attributes.
        """

        self._labels = ('x_bar', 'y_bar', 'z_bar')

        self._multi_spd = MultiSpectralPowerDistribution(
            CIE_1931_2_DEGREE_STANDARD_OBSERVER,
            name='Observer',
            labels=self._labels)

        spd = SpectralPowerDistribution(SAMPLE_SPD_DATA)
        domain = spd.domain
        range_ = tstack([spd.values, spd.values, spd.values])
        self._sample_multi_spd = MultiSpectralPowerDistribution(
            range_, domain, name='Sample Observer', labels=self._labels)

        spd = SpectralPowerDistribution(NON_UNIFORM_SAMPLE_SPD_DATA)
        domain = spd.domain
        range_ = tstack([spd.values, spd.values, spd.values])
        self._non_uniform_sample_multi_spd = MultiSpectralPowerDistribution(
            range_,
            domain,
            name='Non Uniform Sample Observer',
            strict_name='Strict Non Uniform Sample Observer',
            labels=self._labels,
            strict_labels=('Strict x_bar', 'Strict  y_bar', 'Strict  z_bar'))

        self._phi = (1 + np.sqrt(5)) / 2
Пример #2
0
    def setUp(self):
        """
        Initialises common tests attributes.
        """

        self._spd = SpectralPowerDistribution(SAMPLE_SPD_DATA, name='Sample')

        self._non_uniform_spd = SpectralPowerDistribution(
            NON_UNIFORM_SAMPLE_SPD_DATA,
            name='Non Uniform Sample',
            strict_name='Strict Non Uniform Sample')

        self._phi = (1 + np.sqrt(5)) / 2
Пример #3
0
    def test_extrapolate(self):
        """
        Tests :func:`colour.colorimetry.spectrum.\
SpectralPowerDistribution.extrapolate` method.
        """

        data = dict(zip(range(25, 35), [0] * 5 + [1] * 5))
        spd = SpectralPowerDistribution(data)
        spd.extrapolate(SpectralShape(10, 50))

        self.assertAlmostEqual(spd[10], 0, places=7)
        self.assertAlmostEqual(spd[50], 1, places=7)

        spd = SpectralPowerDistribution(
            np.linspace(0, 1, 10), np.linspace(25, 35, 10))
        spd.extrapolate(
            SpectralShape(10, 50),
            extrapolator_args={
                'method': 'Linear',
                'left': None,
                'right': None
            })

        self.assertAlmostEqual(spd[10], -1.5000000000000004, places=7)
        self.assertAlmostEqual(spd[50], 2.4999999999999964, places=7)
Пример #4
0
    }
}

filter_warnings(True)
"""
Filtering warnings issued by Smits (1999) non-uniform wavelengths distribution.
Using `np.linspace(380, 720, 10)` does not solve the issue:

>>> colour.utilities.interval(np.linspace(380, 720, 10))
array([ 37.77777778,  37.77777778,  37.77777778])
"""

SMITS_1999_SPDS = CaseInsensitiveMapping({
    'white':
        SpectralPowerDistribution(
            SMITS_1999_SPDS_DATA['white'],
            name='white'),
    'cyan':
        SpectralPowerDistribution(
            SMITS_1999_SPDS_DATA['cyan'],
            name='cyan'),
    'magenta':
        SpectralPowerDistribution(
            SMITS_1999_SPDS_DATA['magenta'],
            name='magenta'),
    'yellow':
        SpectralPowerDistribution(
            SMITS_1999_SPDS_DATA['yellow'],
            name='yellow'),
    'red':
        SpectralPowerDistribution(
Пример #5
0
        380.0000: 1.0000,
        417.7778: 1.0000,
        455.5556: 0.8916,
        493.3333: 0.3323,
        531.1111: 0.0000,
        568.8889: 0.0000,
        606.6667: 0.0003,
        644.4444: 0.0369,
        682.2222: 0.0483,
        720.0000: 0.0496
    }
}

SMITS_1999_SPDS = CaseInsensitiveMapping({
    'white':
    SpectralPowerDistribution('white', SMITS_1999_SPDS_DATA.get('white')),
    'cyan':
    SpectralPowerDistribution('cyan', SMITS_1999_SPDS_DATA.get('cyan')),
    'magenta':
    SpectralPowerDistribution('magenta', SMITS_1999_SPDS_DATA.get('magenta')),
    'yellow':
    SpectralPowerDistribution('yellow', SMITS_1999_SPDS_DATA.get('yellow')),
    'red':
    SpectralPowerDistribution('red', SMITS_1999_SPDS_DATA.get('red')),
    'green':
    SpectralPowerDistribution('green', SMITS_1999_SPDS_DATA.get('green')),
    'blue':
    SpectralPowerDistribution('blue', SMITS_1999_SPDS_DATA.get('blue'))
})
"""
Smits (1999) spectral power distributions.
Пример #6
0
        380.0000: 1.0000,
        417.7778: 1.0000,
        455.5556: 0.8916,
        493.3333: 0.3323,
        531.1111: 0.0000,
        568.8889: 0.0000,
        606.6667: 0.0003,
        644.4444: 0.0369,
        682.2222: 0.0483,
        720.0000: 0.0496
    }
}

SMITS_1999_SPDS = CaseInsensitiveMapping({
    'white':
    SpectralPowerDistribution('white', SMITS_1999_SPDS_DATA['white']),
    'cyan':
    SpectralPowerDistribution('cyan', SMITS_1999_SPDS_DATA['cyan']),
    'magenta':
    SpectralPowerDistribution('magenta', SMITS_1999_SPDS_DATA['magenta']),
    'yellow':
    SpectralPowerDistribution('yellow', SMITS_1999_SPDS_DATA['yellow']),
    'red':
    SpectralPowerDistribution('red', SMITS_1999_SPDS_DATA['red']),
    'green':
    SpectralPowerDistribution('green', SMITS_1999_SPDS_DATA['green']),
    'blue':
    SpectralPowerDistribution('blue', SMITS_1999_SPDS_DATA['blue'])
})
"""
*Smits (1999)* spectral power distributions.
Пример #7
0
class TestSpectralPowerDistribution(unittest.TestCase):
    """
    Defines :class:`colour.colorimetry.spectrum.SpectralPowerDistribution`
    class unit tests methods.
    """

    def setUp(self):
        """
        Initialises common tests attributes.
        """

        self._spd = SpectralPowerDistribution(SAMPLE_SPD_DATA, name='Sample')

        self._non_uniform_spd = SpectralPowerDistribution(
            NON_UNIFORM_SAMPLE_SPD_DATA,
            name='Non Uniform Sample',
            strict_name='Strict Non Uniform Sample')

        self._phi = (1 + np.sqrt(5)) / 2

    def test_required_attributes(self):
        """
        Tests presence of required attributes.
        """

        required_attributes = ('strict_name', 'wavelengths', 'values', 'shape')

        for attribute in required_attributes:
            self.assertIn(attribute, dir(SpectralPowerDistribution))

    def test_required_methods(self):
        """
        Tests presence of required methods.
        """

        required_methods = ('__init__', 'extrapolate', 'interpolate', 'align',
                            'trim', 'normalise')

        for method in required_methods:
            self.assertIn(method, dir(SpectralPowerDistribution))

    def test_strict_name(self):
        """
        Tests :attr:`colour.colorimetry.spectrum.\
SpectralPowerDistribution.strict_name` attribute.
        """

        self.assertEqual(self._spd.strict_name, 'Sample')
        self.assertEqual(self._non_uniform_spd.strict_name,
                         'Strict Non Uniform Sample')

    def test_wavelengths(self):
        """
        Tests :attr:`colour.colorimetry.spectrum.\
SpectralPowerDistribution.wavelengths` attribute.
        """

        np.testing.assert_array_equal(self._spd.wavelengths, self._spd.domain)

    def test_values(self):
        """
        Tests :attr:`colour.colorimetry.spectrum.\
SpectralPowerDistribution.values` attribute.
        """

        np.testing.assert_array_equal(self._spd.values, self._spd.range)

    def test_shape(self):
        """
        Tests :attr:`colour.colorimetry.spectrum.\
SpectralPowerDistribution.shape` attribute.
        """

        self.assertEqual(self._spd.shape, SpectralShape(340, 820, 20))

    def test_extrapolate(self):
        """
        Tests :func:`colour.colorimetry.spectrum.\
SpectralPowerDistribution.extrapolate` method.
        """

        data = dict(zip(range(25, 35), [0] * 5 + [1] * 5))
        spd = SpectralPowerDistribution(data)
        spd.extrapolate(SpectralShape(10, 50))

        self.assertAlmostEqual(spd[10], 0, places=7)
        self.assertAlmostEqual(spd[50], 1, places=7)

        spd = SpectralPowerDistribution(
            np.linspace(0, 1, 10), np.linspace(25, 35, 10))
        spd.extrapolate(
            SpectralShape(10, 50),
            extrapolator_args={
                'method': 'Linear',
                'left': None,
                'right': None
            })

        self.assertAlmostEqual(spd[10], -1.5000000000000004, places=7)
        self.assertAlmostEqual(spd[50], 2.4999999999999964, places=7)

    def test_interpolate(self):
        """
        Tests :func:`colour.colorimetry.spectrum.\
SpectralPowerDistribution.interpolate` method.
        """

        np.testing.assert_almost_equal(
            self._spd.copy().interpolate(SpectralShape(interval=1)).values,
            INTERPOLATED_SAMPLE_SPD_DATA,
            decimal=7)

        # TODO: Remove statement whenever we make "Scipy" 0.19.0 the minimum
        # version.
        # Skipping tests because of "Scipy" 0.19.0 interpolation code changes.
        if LooseVersion(scipy.__version__) < LooseVersion('0.19.0'):
            return

        np.testing.assert_allclose(
            self._non_uniform_spd.copy().interpolate(
                SpectralShape(interval=1)).values,
            INTERPOLATED_NON_UNIFORM_SAMPLE_SPD_DATA,
            rtol=0.0000001,
            atol=0.0000001)

    def test_align(self):
        """
        Tests :func:`colour.colorimetry.spectrum.\
SpectralPowerDistribution.align` method.
        """

        shape = SpectralShape(100, 900, 5)
        self.assertEqual(self._spd.copy().align(shape).shape, shape)

        shape = SpectralShape(600, 650, 1)
        self.assertEqual(self._spd.copy().align(shape).shape, shape)

    def test_trim(self):
        """
        Tests :func:`colour.colorimetry.spectrum.\
SpectralPowerDistribution.trim` method.
        """

        shape = SpectralShape(400, 700, 20)
        self.assertEqual(self._spd.copy().trim(shape).shape, shape)

        shape = SpectralShape(200, 900, 1)
        self.assertEqual(self._spd.copy().trim(shape).shape, self._spd.shape)

    def test_normalise(self):
        """
        Tests :func:`colour.colorimetry.spectrum.\
SpectralPowerDistribution.normalise` method.
        """

        np.testing.assert_almost_equal(self._spd.copy().normalise(100).values,
                                       NORMALISED_SAMPLE_SPD_DATA)