Skip to content

Commit

Permalink
Code formatting.
Browse files Browse the repository at this point in the history
  • Loading branch information
KelSolaar committed Dec 22, 2024
1 parent 9cff811 commit baf108e
Show file tree
Hide file tree
Showing 47 changed files with 96 additions and 0 deletions.
1 change: 1 addition & 0 deletions colour/adaptation/cmccat2000.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ def chromatic_adaptation_CMCCAT2000(
return chromatic_adaptation_forward_CMCCAT2000(
XYZ, XYZ_w, XYZ_wr, L_A1, L_A2, surround
)

return chromatic_adaptation_inverse_CMCCAT2000(
XYZ, XYZ_w, XYZ_wr, L_A1, L_A2, surround
)
1 change: 1 addition & 0 deletions colour/adaptation/fairchild1990.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ def degrees_of_adaptation(
"""

LMS = as_float_array(LMS)

if discount_illuminant:
return ones(LMS.shape)

Expand Down
1 change: 1 addition & 0 deletions colour/adaptation/fairchild2020.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ def matrix_chromatic_adaptation_vk20(
D = row_as_diagonal(sdiv(1, (D_n * LMS_n + D_r * LMS_r + D_p * LMS_p)))

M_CAT = np.matmul(np.linalg.inv(M), D)

return np.matmul(M_CAT, M)


Expand Down
1 change: 1 addition & 0 deletions colour/adaptation/vonkries.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ def matrix_chromatic_adaptation_VonKries(
D = row_as_diagonal(D)

M_CAT = np.matmul(np.linalg.inv(M), D)

return np.matmul(M_CAT, M)


Expand Down
2 changes: 2 additions & 0 deletions colour/algebra/interpolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1220,8 +1220,10 @@ def _evaluate(self, x: NDArrayFloat) -> NDArrayFloat:
# parts of the linear algebra.

y = r[i] + (a.reshape(5, -1) * X ** np.arange(1, 6).reshape(-1, 1)).sum(axis=0)

if y.size == 1:
return y[0]

return y

def _validate_dimensions(self) -> None:
Expand Down
3 changes: 3 additions & 0 deletions colour/appearance/ciecam02.py
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,7 @@ def post_adaptation_non_linear_response_compression_forward(
F_L = as_float_array(F_L)

F_L_RGB = spow(F_L[..., None] * np.absolute(RGB) / 100, 0.42)

return (400 * np.sign(RGB) * F_L_RGB) / (27.13 + F_L_RGB) + 0.1


Expand Down Expand Up @@ -1154,6 +1155,7 @@ def hue_quadrature(h: ArrayLike) -> NDArrayFloat:
H_ii + ((85.9 * (h - h_ii) / e_ii) / ((h - h_ii) / e_ii + (360 - h) / 0.856)),
H,
)

return as_float(H)


Expand Down Expand Up @@ -1498,6 +1500,7 @@ def chroma_correlate(
n = as_float_array(n)

t = temporary_magnitude_quantity_forward(N_c, N_cb, e_t, a, b, RGB_a)

return spow(t, 0.9) * spow(J / 100, 0.5) * spow(1.64 - 0.29**n, 0.73)


Expand Down
2 changes: 2 additions & 0 deletions colour/appearance/hunt.py
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,7 @@ def hue_angle(C: ArrayLike) -> NDArrayFloat:
C_1, C_2, C_3 = tsplit(C)

hue = (180 * np.arctan2(0.5 * (C_2 - C_3) / 4.5, C_1 - (C_2 / 11)) / np.pi) % 360

return as_float(hue)


Expand Down Expand Up @@ -1284,6 +1285,7 @@ def lightness_correlate(
Q_w = as_float_array(Q_w)

Z = 1 + spow(Y_b / Y_w, 0.5)

return 100 * spow(Q / Q_w, Z)


Expand Down
1 change: 1 addition & 0 deletions colour/blindness/machado2009.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,4 +381,5 @@ def matrix_cvd_Machado2009(
if a == b:
# 1.0 severity CVD matrix, returning directly.
return m1

return m1 + (severity - a) * ((m2 - m1) / (b - a))
1 change: 1 addition & 0 deletions colour/characterisation/aces_it.py
Original file line number Diff line number Diff line change
Expand Up @@ -1142,6 +1142,7 @@ def matrix_idt(

if additional_data:
return M, RGB_w, XYZ, RGB

return M, RGB_w


Expand Down
6 changes: 6 additions & 0 deletions colour/colorimetry/spectrum.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,7 @@ def __eq__(self, other: object) -> bool:

if isinstance(other, SpectralShape):
return np.array_equal(self.wavelengths, other.wavelengths)

return False

def __ne__(self, other: object) -> bool:
Expand Down Expand Up @@ -512,6 +513,7 @@ def range(self, dtype: Type[DTypeFloat] | None = None) -> NDArrayFloat:
dtype = optional(dtype, DTYPE_FLOAT_DEFAULT)

hash_key = hash((self, dtype))

if is_caching_enabled() and hash_key in _CACHE_SHAPE_RANGE:
return _CACHE_SHAPE_RANGE[hash_key].copy()

Expand Down Expand Up @@ -2710,6 +2712,7 @@ def reshape_sd(

if is_caching_enabled() and hash_key in _CACHE_RESHAPED_SDS_AND_MSDS:
reshaped_sd = _CACHE_RESHAPED_SDS_AND_MSDS[hash_key]

return reshaped_sd.copy() if copy else reshaped_sd

function = getattr(sd, method)
Expand Down Expand Up @@ -2825,10 +2828,12 @@ def sds_and_msds_to_sds(

if isinstance(sds, SpectralDistribution):
return sds_and_msds_to_sds([sds])

if isinstance(sds, MultiSpectralDistributions):
sds_converted = sds.to_sds()
else:
sds_converted = []

for sd in sds:
sds_converted += (
sd.to_sds() if isinstance(sd, MultiSpectralDistributions) else [sd]
Expand Down Expand Up @@ -2926,6 +2931,7 @@ def sds_and_msds_to_msds(

if isinstance(sds, SpectralDistribution):
return sds_and_msds_to_msds([sds])

if isinstance(sds, MultiSpectralDistributions):
msds_converted = sds
else:
Expand Down
2 changes: 2 additions & 0 deletions colour/colorimetry/tristimulus_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ def lagrange_coefficients_ASTME2022(
)

hash_key = hash((interval, interval_type))

if is_caching_enabled() and hash_key in _CACHE_LAGRANGE_INTERPOLATING_COEFFICIENTS:
return np.copy(_CACHE_LAGRANGE_INTERPOLATING_COEFFICIENTS[hash_key])

Expand Down Expand Up @@ -393,6 +394,7 @@ def tristimulus_weighting_factors_ASTME2022(
global _CACHE_TRISTIMULUS_WEIGHTING_FACTORS # noqa: PLW0602

hash_key = hash((cmfs, illuminant, shape, k, get_domain_range_scale()))

if is_caching_enabled() and hash_key in _CACHE_TRISTIMULUS_WEIGHTING_FACTORS:
return np.copy(_CACHE_TRISTIMULUS_WEIGHTING_FACTORS[hash_key])

Expand Down
1 change: 1 addition & 0 deletions colour/continuous/multi_signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -1017,6 +1017,7 @@ def __eq__(self, other: object) -> bool:
self.labels == other.labels,
]
)

return False

def __ne__(self, other: object) -> bool:
Expand Down
3 changes: 3 additions & 0 deletions colour/continuous/signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,7 @@ def __getitem__(self, x: ArrayLike | slice) -> NDArrayFloat:

if isinstance(x, slice):
return self._range[x]

return self.function(x)

def __setitem__(self, x: ArrayLike | slice, y: ArrayLike) -> None:
Expand Down Expand Up @@ -886,6 +887,7 @@ def __eq__(self, other: object) -> bool:
repr(self._extrapolator_kwargs) == repr(other.extrapolator_kwargs),
]
)

return False

def __ne__(self, other: object) -> bool:
Expand Down Expand Up @@ -1078,6 +1080,7 @@ def arithmetical_operation(
self.range = ioperator(self._range, a)

return self

return ioperator(self.copy(), a)

@staticmethod
Expand Down
2 changes: 2 additions & 0 deletions colour/io/ctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,10 @@ def process_image_ctl(

if len(shape) == 0:
return as_float(np.squeeze(b)[0])

if shape[-1] == 1:
return np.reshape(b[..., 0], shape)

return np.reshape(b, shape)


Expand Down
1 change: 1 addition & 0 deletions colour/io/fichet2021.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,7 @@ def read_spectral_image_Fichet2021(

if additional_data:
return components, specification

return components


Expand Down
1 change: 1 addition & 0 deletions colour/io/luts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ def read_LUT(
if method == "iridas cube":
function = LUT_READ_METHODS["Resolve Cube"]
return function(path, **filter_kwargs(function, **kwargs))

raise ValueError from error


Expand Down
3 changes: 3 additions & 0 deletions colour/io/luts/lut.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,7 @@ def arithmetical_operation(
self.table = operator(self.table, operand)

return self

return ioperator(self.copy(), a)

@abstractmethod
Expand Down Expand Up @@ -993,6 +994,7 @@ def linear_table(

if len(domain) != 2:
return domain

attest(is_numeric(size), "Linear table size must be a numeric!")

return np.linspace(domain[0], domain[1], as_int_scalar(size))
Expand Down Expand Up @@ -1358,6 +1360,7 @@ def linear_table(

if domain.shape != (2, 3):
return domain

size_array = np.tile(size, 3) if is_numeric(size) else as_int_array(size)

R, G, B = tsplit(domain)
Expand Down
2 changes: 2 additions & 0 deletions colour/io/ocio.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ def process_image_OpenColorIO(a: ArrayLike, *args: Any, **kwargs: Any) -> NDArra

if len(shape) == 0:
return as_float(np.squeeze(b)[0])

if shape[-1] == 1:
return np.reshape(b[..., 0], shape)

return np.reshape(b, shape)
1 change: 1 addition & 0 deletions colour/io/tm2714.py
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,7 @@ def __eq__(self, other: object) -> bool:
self._comments == other.comments,
]
)

return False

def __ne__(self, other: object) -> bool:
Expand Down
5 changes: 5 additions & 0 deletions colour/models/rgb/rgb_colourspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,9 @@ def matrix_RGB_to_XYZ(self) -> NDArrayFloat:
if self._matrix_RGB_to_XYZ is None or self._use_derived_matrix_RGB_to_XYZ:
if self._derived_matrix_RGB_to_XYZ.size == 0:
self._derive_transformation_matrices()

return self._derived_matrix_RGB_to_XYZ

return self._matrix_RGB_to_XYZ

@matrix_RGB_to_XYZ.setter
Expand Down Expand Up @@ -469,7 +471,9 @@ def matrix_XYZ_to_RGB(self) -> NDArrayFloat:
if self._matrix_XYZ_to_RGB is None or self._use_derived_matrix_XYZ_to_RGB:
if self._derived_matrix_XYZ_to_RGB.size == 0:
self._derive_transformation_matrices()

return self._derived_matrix_XYZ_to_RGB

return self._matrix_XYZ_to_RGB

@matrix_XYZ_to_RGB.setter
Expand Down Expand Up @@ -688,6 +692,7 @@ def __str__(self) -> str:
"""
if self._derived_matrix_XYZ_to_RGB.size == 0:
self._derive_transformation_matrices()

return multiline_str(
self,
[
Expand Down
1 change: 1 addition & 0 deletions colour/models/rgb/transfer_functions/aces.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ def float_2_cv(x: float) -> float:

if out_int:
return as_int(np.round(ACESproxy))

return as_float(from_range_1(ACESproxy / (2**bit_depth - 1)))


Expand Down
2 changes: 2 additions & 0 deletions colour/models/rgb/transfer_functions/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ def legal_to_full(

if out_int:
return as_int(np.round(CV_full * MV))

return as_float(CV_full)


Expand Down Expand Up @@ -202,4 +203,5 @@ def full_to_legal(

if out_int:
return as_int(np.round(CV_legal))

return as_float(CV_legal / MV)
1 change: 1 addition & 0 deletions colour/models/rgb/transfer_functions/dcdm.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ def eotf_inverse_DCDM(XYZ: ArrayLike, out_int: bool = False) -> NDArrayReal:

if out_int:
return as_int(np.round(4095 * XYZ_p))

return as_float(XYZ_p)


Expand Down
1 change: 1 addition & 0 deletions colour/models/rgb/transfer_functions/dicom_gsdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ def eotf_inverse_DICOMGSDF(

if out_int:
return as_int(np.round(J))

return as_float(from_range_1(J / 1023))


Expand Down
3 changes: 3 additions & 0 deletions colour/models/rgb/transfer_functions/gamma.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,12 @@ def gamma_function(

if negative_number_handling == "indeterminate":
return as_float(a**exponent)

if negative_number_handling == "mirror":
return spow(a, exponent)

if negative_number_handling == "preserve":
return as_float(np.where(a <= 0, a, a**exponent))

# negative_number_handling == 'clamp':
return as_float(np.where(a <= 0, 0, a**exponent))
4 changes: 4 additions & 0 deletions colour/models/rgb/transfer_functions/itur_bt_2100.py
Original file line number Diff line number Diff line change
Expand Up @@ -1152,6 +1152,7 @@ def ootf_BT2100_HLG_1(

if is_single_channel:
return as_float(from_range_1(R_D))

RGB_D = tstack([R_D, G_D, B_D])

return from_range_1(RGB_D)
Expand Down Expand Up @@ -1238,6 +1239,7 @@ def ootf_BT2100_HLG_2(

if is_single_channel:
return as_float(from_range_1(R_D))

RGB_D = tstack([R_D, G_D, B_D])

return from_range_1(RGB_D)
Expand Down Expand Up @@ -1433,6 +1435,7 @@ def ootf_inverse_BT2100_HLG_1(

if is_single_channel:
return as_float(from_range_1(R_S))

RGB_S = tstack([R_S, G_S, B_S])

return from_range_1(RGB_S)
Expand Down Expand Up @@ -1531,6 +1534,7 @@ def ootf_inverse_BT2100_HLG_2(

if is_single_channel:
return as_float(from_range_1(R_S))

RGB_S = tstack([R_S, G_S, B_S])

return from_range_1(RGB_S)
Expand Down
5 changes: 5 additions & 0 deletions colour/models/rgb/transfer_functions/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,19 @@ def logarithmic_function_basic(

if style == "log10":
return as_float(np.where(x >= FLT_MIN, np.log10(x), np.log10(FLT_MIN)))

if style == "antilog10":
return as_float(10**x)

if style == "log2":
return as_float(np.where(x >= FLT_MIN, np.log2(x), np.log2(FLT_MIN)))

if style == "antilog2":
return as_float(2**x)

if style == "logb":
return as_float(np.log(x) / np.log(base))

# style == 'antilogb'
return as_float(base**x)

Expand Down
Loading

0 comments on commit baf108e

Please sign in to comment.