Skip to content

Commit

Permalink
Ensure that most "Colour" honours float precision change.
Browse files Browse the repository at this point in the history
  • Loading branch information
KelSolaar committed May 23, 2020
1 parent f737edf commit c3245b1
Show file tree
Hide file tree
Showing 37 changed files with 524 additions and 224 deletions.
7 changes: 4 additions & 3 deletions colour/adaptation/fairchild1990.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

from colour.algebra import spow
from colour.adaptation import VON_KRIES_CAT
from colour.utilities import (as_float_array, dot_vector, from_range_100,
from colour.utilities import (as_float_array, dot_vector, from_range_100, ones,
row_as_diagonal, to_domain_100, tsplit, tstack)

__author__ = 'Colour Developers'
Expand Down Expand Up @@ -231,14 +231,15 @@ def degrees_of_adaptation(LMS, Y_n, v=1 / 3, discount_illuminant=False):

LMS = as_float_array(LMS)
if discount_illuminant:
return np.ones(LMS.shape)
return ones(LMS.shape)

Y_n = as_float_array(Y_n)
v = as_float_array(v)

L, M, S = tsplit(LMS)

LMS_E = dot_vector(VON_KRIES_CAT, np.ones(LMS.shape)) # E illuminant.
# E illuminant.
LMS_E = dot_vector(VON_KRIES_CAT, ones(LMS.shape))
L_E, M_E, S_E = tsplit(LMS_E)

Ye_n = spow(Y_n, v)
Expand Down
6 changes: 3 additions & 3 deletions colour/algebra/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
import numpy as np
from collections import namedtuple

from colour.utilities import (CaseInsensitiveMapping, as_float_array, tsplit,
tstack)
from colour.utilities import (CaseInsensitiveMapping, as_float_array, ones,
tsplit, tstack)

__author__ = 'Colour Developers'
__copyright__ = 'Copyright (C) 2013-2020 - Colour Developers'
Expand Down Expand Up @@ -492,7 +492,7 @@ def ellipse_fitting_Halir1998(a):
# Quadratic part of the design matrix.
D1 = tstack([x ** 2, x * y, y ** 2])
# Linear part of the design matrix.
D2 = tstack([x, y, np.ones(x.shape)])
D2 = tstack([x, y, ones(x.shape)])

D1_T = np.transpose(D1)
D2_T = np.transpose(D2)
Expand Down
6 changes: 3 additions & 3 deletions colour/appearance/cam16.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
viewing_condition_dependent_parameters)
from colour.utilities import (CaseInsensitiveMapping, as_float_array,
as_namedtuple, dot_vector, from_range_100,
from_range_degrees, to_domain_100,
from_range_degrees, ones, to_domain_100,
to_domain_degrees, tsplit)

__author__ = 'Colour Developers'
Expand Down Expand Up @@ -244,7 +244,7 @@ def XYZ_to_CAM16(XYZ,

# Computing degree of adaptation :math:`D`.
D = (np.clip(degree_of_adaptation(surround.F, L_A), 0, 1)
if not discount_illuminant else np.ones(L_A.shape))
if not discount_illuminant else ones(L_A.shape))

n, F_L, N_bb, N_cb, z = tsplit(
viewing_condition_dependent_parameters(Y_b, Y_w, L_A))
Expand Down Expand Up @@ -419,7 +419,7 @@ def CAM16_to_XYZ(CAM16_specification,

# Computing degree of adaptation :math:`D`.
D = (np.clip(degree_of_adaptation(surround.F, L_A), 0, 1)
if not discount_illuminant else np.ones(L_A.shape))
if not discount_illuminant else ones(L_A.shape))

n, F_L, N_bb, N_cb, z = tsplit(
viewing_condition_dependent_parameters(Y_b, Y_w, L_A))
Expand Down
14 changes: 7 additions & 7 deletions colour/appearance/ciecam02.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
from colour.constants import EPSILON
from colour.utilities import (
CaseInsensitiveMapping, as_float_array, as_int_array, as_namedtuple,
as_float, from_range_degrees, dot_matrix, dot_vector, from_range_100,
to_domain_100, to_domain_degrees, tsplit, tstack)
as_float, from_range_degrees, dot_matrix, dot_vector, from_range_100, ones,
to_domain_100, to_domain_degrees, tsplit, tstack, zeros)

__author__ = 'Colour Developers'
__copyright__ = 'Copyright (C) 2013-2020 - Colour Developers'
Expand Down Expand Up @@ -265,7 +265,7 @@ def XYZ_to_CIECAM02(XYZ,

# Computing degree of adaptation :math:`D`.
D = (degree_of_adaptation(surround.F, L_A)
if not discount_illuminant else np.ones(L_A.shape))
if not discount_illuminant else ones(L_A.shape))

# Computing full chromatic adaptation.
RGB_c = full_chromatic_adaptation_forward(RGB, RGB_w, Y_w, D)
Expand Down Expand Up @@ -437,7 +437,7 @@ def CIECAM02_to_XYZ(CIECAM02_specification,

# Computing degree of adaptation :math:`D`.
D = (degree_of_adaptation(surround.F, L_A)
if not discount_illuminant else np.ones(L_A.shape))
if not discount_illuminant else ones(L_A.shape))

# Computing full chromatic adaptation.
RGB_wc = full_chromatic_adaptation_forward(RGB_w, RGB_w, Y_w, D)
Expand Down Expand Up @@ -900,8 +900,8 @@ def opponent_colour_dimensions_inverse(P_n, h):
P_5 = P_1 / cos_hr
n = P_2 * (2 + P_3) * (460 / 1403)

a = np.zeros(hr.shape)
b = np.zeros(hr.shape)
a = zeros(hr.shape)
b = zeros(hr.shape)

b = np.where(
np.isfinite(P_1) * np.abs(sin_hr) >= np.abs(cos_hr),
Expand Down Expand Up @@ -1456,7 +1456,7 @@ def P(N_c, N_cb, e_t, t, A, N_bb):

P_1 = ((50000 / 13) * N_c * N_cb * e_t) / t
P_2 = A / N_bb + 0.305
P_3 = np.ones(P_1.shape) * (21 / 20)
P_3 = ones(P_1.shape) * (21 / 20)

P_n = tstack([P_1, P_2, P_3])

Expand Down
12 changes: 6 additions & 6 deletions colour/appearance/hunt.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
from collections import namedtuple

from colour.algebra import spow
from colour.utilities import (CaseInsensitiveMapping, as_float_array,
dot_vector, from_range_degrees, to_domain_100,
tsplit, tstack, usage_warning)
from colour.utilities import (
CaseInsensitiveMapping, as_float_array, dot_vector, from_range_degrees,
ones, to_domain_100, tsplit, tstack, usage_warning, zeros)

__author__ = 'Colour Developers'
__copyright__ = 'Copyright (C) 2013-2020 - Colour Developers'
Expand Down Expand Up @@ -325,7 +325,7 @@ def XYZ_to_Hunt(XYZ,
>>> XYZ_b = np.array([95.05, 100.00, 108.88])
>>> L_A = 318.31
>>> surround = HUNT_VIEWING_CONDITIONS['Normal Scenes']
>>> CCT_w = 6504.0
>>> CCT_w = 6504
>>> XYZ_to_Hunt(XYZ, XYZ_w, XYZ_b, L_A, surround, CCT_w=CCT_w)
... # doctest: +ELLIPSIS
Hunt_Specification(J=30.0462678..., C=0.1210508..., h=269.2737594..., \
Expand Down Expand Up @@ -662,14 +662,14 @@ def chromatic_adaptation(XYZ,
L_A_p = spow(L_A, 1 / 3)
F_rgb = ((1 + L_A_p + h_rgb) / (1 + L_A_p + (1 / h_rgb)))
else:
F_rgb = np.ones(h_rgb.shape)
F_rgb = ones(h_rgb.shape)

# Computing Helson-Judd effect parameters.
if helson_judd_effect:
D_rgb = (f_n((Y_b / Y_w) * F_L * F_rgb[..., 1]) - f_n(
(Y_b / Y_w) * F_L * F_rgb))
else:
D_rgb = np.zeros(F_rgb.shape)
D_rgb = zeros(F_rgb.shape)

# Computing cone bleach factors.
B_rgb = (10 ** 7) / ((10 ** 7) + 5 * L_A[..., np.newaxis] * (rgb_w / 100))
Expand Down
20 changes: 10 additions & 10 deletions colour/characterisation/correction.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@

from colour.algebra import least_square_mapping_MoorePenrose
from colour.utilities import (CaseInsensitiveMapping, as_float_array, as_int,
closest, filter_kwargs, tsplit, tstack)
closest, filter_kwargs, ones, tsplit, tstack)

__author__ = 'Colour Developers'
__copyright__ = 'Copyright (C) 2013-2020 - Colour Developers'
Expand Down Expand Up @@ -119,7 +119,7 @@ def augmented_matrix_Cheung2004(RGB, terms=3):
"""

R, G, B = tsplit(RGB)
ones = np.ones(R.shape)
tail = ones(R.shape)

existing_terms = np.array([3, 5, 7, 8, 10, 11, 14, 16, 17, 19, 20, 22])
closest_terms = as_int(closest(existing_terms, terms))
Expand All @@ -132,23 +132,23 @@ def augmented_matrix_Cheung2004(RGB, terms=3):
if terms == 3:
return RGB
elif terms == 5:
return tstack([R, G, B, R * G * B, ones])
return tstack([R, G, B, R * G * B, tail])
elif terms == 7:
return tstack([R, G, B, R * G, R * B, G * B, ones])
return tstack([R, G, B, R * G, R * B, G * B, tail])
elif terms == 8:
return tstack([R, G, B, R * G, R * B, G * B, R * G * B, ones])
return tstack([R, G, B, R * G, R * B, G * B, R * G * B, tail])
elif terms == 10:
return tstack(
[R, G, B, R * G, R * B, G * B, R ** 2, G ** 2, B ** 2, ones])
[R, G, B, R * G, R * B, G * B, R ** 2, G ** 2, B ** 2, tail])
elif terms == 11:
return tstack([
R, G, B, R * G, R * B, G * B, R ** 2, G ** 2, B ** 2, R * G * B,
ones
tail
])
elif terms == 14:
return tstack([
R, G, B, R * G, R * B, G * B, R ** 2, G ** 2, B ** 2, R * G * B, R
** 3, G ** 3, B ** 3, ones
** 3, G ** 3, B ** 3, tail
])
elif terms == 16:
return tstack([
Expand All @@ -158,7 +158,7 @@ def augmented_matrix_Cheung2004(RGB, terms=3):
elif terms == 17:
return tstack([
R, G, B, R * G, R * B, G * B, R ** 2, G ** 2, B ** 2, R * G * B,
R ** 2 * G, G ** 2 * B, B ** 2 * R, R ** 3, G ** 3, B ** 3, ones
R ** 2 * G, G ** 2 * B, B ** 2 * R, R ** 3, G ** 3, B ** 3, tail
])
elif terms == 19:
return tstack([
Expand All @@ -170,7 +170,7 @@ def augmented_matrix_Cheung2004(RGB, terms=3):
return tstack([
R, G, B, R * G, R * B, G * B, R ** 2, G ** 2, B ** 2, R * G * B,
R ** 2 * G, G ** 2 * B, B ** 2 * R, R ** 2 * B, G ** 2 * R,
B ** 2 * G, R ** 3, G ** 3, B ** 3, ones
B ** 2 * G, R ** 3, G ** 3, B ** 3, tail
])
elif terms == 22:
return tstack([
Expand Down
6 changes: 3 additions & 3 deletions colour/colorimetry/generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

from colour.constants import DEFAULT_FLOAT_DTYPE
from colour.colorimetry import (DEFAULT_SPECTRAL_SHAPE, SpectralDistribution)
from colour.utilities import CaseInsensitiveMapping, as_float_array
from colour.utilities import CaseInsensitiveMapping, as_float_array, full, ones

__author__ = 'Colour Developers'
__copyright__ = 'Copyright (C) 2013-2020 - Colour Developers'
Expand Down Expand Up @@ -90,7 +90,7 @@ def sd_constant(k, shape=DEFAULT_SPECTRAL_SHAPE, dtype=None):
dtype = DEFAULT_FLOAT_DTYPE

wavelengths = shape.range(dtype)
values = np.full(len(wavelengths), k, dtype)
values = full(len(wavelengths), k, dtype)

name = '{0} Constant'.format(k)
return SpectralDistribution(values, wavelengths, name=name, dtype=dtype)
Expand Down Expand Up @@ -485,7 +485,7 @@ def sd_multi_leds_Ohno2005(peak_wavelengths,
peak_wavelengths = as_float_array(peak_wavelengths)
fwhm = np.resize(fwhm, peak_wavelengths.shape)
if peak_power_ratios is None:
peak_power_ratios = np.ones(peak_wavelengths.shape)
peak_power_ratios = ones(peak_wavelengths.shape)
else:
peak_power_ratios = np.resize(peak_power_ratios,
peak_wavelengths.shape)
Expand Down
5 changes: 3 additions & 2 deletions colour/colorimetry/photometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

from colour.colorimetry import PHOTOPIC_LEFS
from colour.constants import K_M
from colour.utilities import as_float

__author__ = 'Colour Developers'
__copyright__ = 'Copyright (C) 2013-2020 - Colour Developers'
Expand Down Expand Up @@ -75,7 +76,7 @@ def luminous_flux(sd,

flux = K_m * np.trapz(sd.values, sd.wavelengths)

return flux
return as_float(flux)


def luminous_efficiency(
Expand Down Expand Up @@ -155,4 +156,4 @@ def luminous_efficacy(

efficacy = K_M * luminous_efficiency(sd, lef)

return efficacy
return as_float(efficacy)
1 change: 1 addition & 0 deletions colour/colorimetry/tristimulus.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ def sd_to_XYZ_integration(
S = illuminant.values
x_bar, y_bar, z_bar = tsplit(cmfs.values)
R = sd.values

dw = cmfs.shape.interval

k = 100 / (np.sum(y_bar * S) * dw) if k is None else k
Expand Down
7 changes: 5 additions & 2 deletions colour/constants/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from __future__ import division, unicode_literals

import os
import numpy as np

from colour.utilities.documentation import DocstringFloat
Expand Down Expand Up @@ -46,14 +47,16 @@
EPSILON : numeric
"""

DEFAULT_FLOAT_DTYPE = np.float_
DEFAULT_FLOAT_DTYPE = np.sctypeDict.get(
os.environ.get('COLOUR_SCIENCE__FLOAT_PRECISION', 'float64'), 'float64')
"""
Default floating point number dtype.
DEFAULT_FLOAT_DTYPE : type
"""

DEFAULT_INT_DTYPE = np.int_
DEFAULT_INT_DTYPE = np.sctypeDict.get(
os.environ.get('COLOUR_SCIENCE__INT_PRECISION', 'int64'), 'int64')
"""
Default integer number dtype.
Expand Down
4 changes: 0 additions & 4 deletions colour/continuous/multi_signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -1318,10 +1318,6 @@ def multi_signals_unpack_data(data=None,
if dtype is None:
dtype = DEFAULT_FLOAT_DTYPE

assert dtype in np.sctypes['float'], (
'"dtype" must be one of the following types: {0}'.format(
np.sctypes['float']))

domain_u, range_u, signals = None, None, None
signals = OrderedDict()
# TODO: Implement support for Signal class passing.
Expand Down
Loading

0 comments on commit c3245b1

Please sign in to comment.