Пример #1
0
    def test___init__(self):
        """
        Tests :func:`colour.algebra.interpolation.KernelInterpolator.__init__`
        method.
        """

        x = y = np.linspace(0, 1, 10)
        nearest_neighbour_interpolator = NearestNeighbourInterpolator(
            x, y, kernel_args={'a': 1})

        self.assertDictEqual(nearest_neighbour_interpolator.kernel_args, {})
Пример #2
0
def XYZ_outer_surface(
    interval=10,
    cmfs=STANDARD_OBSERVERS_CMFS['CIE 1931 2 Degree Standard Observer'],
    illuminant=sd_ones(
        STANDARD_OBSERVERS_CMFS['CIE 1931 2 Degree Standard Observer'].shape)):
    """
    Generates the *CIE XYZ* colourspace outer surface for given colour matching
    functions using multi-spectral conversion of pulse waves to *CIE XYZ*
    tristimulus values.

    Parameters
    ----------
    interval : int, optional
        Wavelength :math:`\\lambda_{i}` range interval used to compute the
        pulse waves.
    cmfs : XYZ_ColourMatchingFunctions, optional
        Standard observer colour matching functions.
    illuminant : SpectralDistribution, optional
        Illuminant spectral distribution.

    Returns
    -------
    ndarray
        Outer surface *CIE XYZ* tristimulus values.

    References
    ----------
    :cite:`Lindbloom2015`, :cite:`Mansencal2018`

    Examples
    --------
    >>> XYZ_outer_surface(84)  # doctest: +ELLIPSIS
    array([[  0.0000000...e+00,   0.0000000...e+00,   0.0000000...e+00],
           [  1.4766924...e-03,   4.1530347...e-05,   6.9884362...e-03],
           [  1.6281275...e-01,   3.7114387...e-02,   9.0151471...e-01],
           [  1.8650894...e-01,   5.6617464...e-01,   9.1355179...e-02],
           [  6.1555347...e-01,   3.8427775...e-01,   4.7422070...e-04],
           [  3.3622045...e-02,   1.2354556...e-02,   0.0000000...e+00],
           [  1.0279500...e-04,   3.7121158...e-05,   0.0000000...e+00],
           [  1.6428945...e-01,   3.7155917...e-02,   9.0850314...e-01],
           [  3.4932169...e-01,   6.0328903...e-01,   9.9286989...e-01],
           [  8.0206241...e-01,   9.5045240...e-01,   9.1829399...e-02],
           [  6.4917552...e-01,   3.9663231...e-01,   4.7422070...e-04],
           [  3.3724840...e-02,   1.2391678...e-02,   0.0000000...e+00],
           [  1.5794874...e-03,   7.8651505...e-05,   6.9884362...e-03],
           [  3.5079839...e-01,   6.0333056...e-01,   9.9985832...e-01],
           [  9.6487517...e-01,   9.8756679...e-01,   9.9334411...e-01],
           [  8.3568446...e-01,   9.6280696...e-01,   9.1829399...e-02],
           [  6.4927831...e-01,   3.9666943...e-01,   4.7422070...e-04],
           [  3.5201532...e-02,   1.2433208...e-02,   6.9884362...e-03],
           [  1.6439224...e-01,   3.7193038...e-02,   9.0850314...e-01],
           [  9.6635186...e-01,   9.8760832...e-01,   1.0003325...e+00],
           [  9.9849722...e-01,   9.9992134...e-01,   9.9334411...e-01],
           [  8.3578726...e-01,   9.6284408...e-01,   9.1829399...e-02],
           [  6.5075501...e-01,   3.9671096...e-01,   7.4626569...e-03],
           [  1.9801429...e-01,   4.9547595...e-02,   9.0850314...e-01],
           [  3.5090118...e-01,   6.0336768...e-01,   9.9985832...e-01],
           [  9.9997391...e-01,   9.9996287...e-01,   1.0003325...e+00],
           [  9.9860001...e-01,   9.9995847...e-01,   9.9334411...e-01],
           [  8.3726395...e-01,   9.6288561...e-01,   9.8817836...e-02],
           [  8.1356776...e-01,   4.3382535...e-01,   9.0897737...e-01],
           [  3.8452323...e-01,   6.1572224...e-01,   9.9985832...e-01],
           [  9.6645466...e-01,   9.8764544...e-01,   1.0003325...e+00],
           [  1.0000767...e+00,   1.0000000...e+00,   1.0003325...e+00]])

    """

    key = (interval, hash(cmfs), hash(illuminant))
    XYZ = _XYZ_OUTER_SURFACE_CACHE.get(key)
    if XYZ is None:
        wavelengths = SpectralShape(DEFAULT_SPECTRAL_SHAPE.start,
                                    DEFAULT_SPECTRAL_SHAPE.end,
                                    interval).range()
        values = []
        domain = DEFAULT_SPECTRAL_SHAPE.range()
        for wave in generate_pulse_waves(len(wavelengths)):
            values.append(
                NearestNeighbourInterpolator(wavelengths, wave)(domain))

        XYZ = multi_sd_to_XYZ_integration(values, DEFAULT_SPECTRAL_SHAPE, cmfs,
                                          illuminant)

        XYZ = XYZ / np.max(XYZ[-1, 1])

        _XYZ_OUTER_SURFACE_CACHE[key] = XYZ

    return XYZ