diff --git a/colour/characterisation/correction.py b/colour/characterisation/correction.py index 111947a4a4..3903dea447 100644 --- a/colour/characterisation/correction.py +++ b/colour/characterisation/correction.py @@ -64,6 +64,7 @@ from colour.hints import ArrayLike, Any, Literal, NDArrayFloat, Union from colour.utilities import ( CanonicalMapping, + as_float, as_float_array, as_int, closest, @@ -414,9 +415,9 @@ def polynomial_expansion_Finlayson2015( if root_polynomial_expansion: return tstack( [ - R, - G, - B, + as_float(R), + as_float(G), + as_float(B), spow(R * G, 1 / 2), spow(G * B, 1 / 2), spow(R * B, 1 / 2), @@ -441,9 +442,9 @@ def polynomial_expansion_Finlayson2015( if root_polynomial_expansion: return tstack( [ - R, - G, - B, + as_float(R), + as_float(G), + as_float(B), spow(R * G, 1 / 2), spow(G * B, 1 / 2), spow(R * B, 1 / 2), @@ -484,9 +485,9 @@ def polynomial_expansion_Finlayson2015( if root_polynomial_expansion: return tstack( [ - R, - G, - B, + as_float(R), + as_float(G), + as_float(B), spow(R * G, 1 / 2), spow(G * B, 1 / 2), spow(R * B, 1 / 2), diff --git a/colour/characterisation/tests/test_correction.py b/colour/characterisation/tests/test_correction.py index e9c0dd9c9d..c2b84ba248 100644 --- a/colour/characterisation/tests/test_correction.py +++ b/colour/characterisation/tests/test_correction.py @@ -683,8 +683,8 @@ def test_nan_matrix_colour_correction_Cheung2004(self): # pragma: no cover matrix_colour_correction_Cheung2004` definition nan support. """ - # NOTE: Hangs on "Linux". - if platform.system() == "Linux": + # NOTE: Hangs on "macOS" and "Linux". + if platform.system() in ("Darwin", "Linux"): return cases = [-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan] @@ -790,8 +790,8 @@ def test_nan_matrix_colour_correction_Finlayson2015( matrix_colour_correction_Finlayson2015` definition nan support. """ - # NOTE: Hangs on "Linux". - if platform.system() == "Linux": + # NOTE: Hangs on "macOS" and "Linux". + if platform.system() in ("Darwin", "Linux"): return cases = [-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan] @@ -888,8 +888,8 @@ def test_nan_matrix_colour_correction_Vandermonde( matrix_colour_correction_Vandermonde` definition nan support. """ - # NOTE: Hangs on "Linux". - if platform.system() == "Linux": + # NOTE: Hangs on "macOS" and "Linux". + if platform.system() in ("Darwin", "Linux"): return cases = [-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan] @@ -966,8 +966,8 @@ def test_nan_colour_correction_Cheung2004(self): # pragma: no cover colour_correction_Cheung2004` definition nan support. """ - # NOTE: Hangs on "Linux". - if platform.system() == "Linux": + # NOTE: Hangs on "macOS" and "Linux". + if platform.system() in ("Darwin", "Linux"): return cases = [-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan] @@ -1051,8 +1051,8 @@ def test_nan_colour_correction_Finlayson2015(self): # pragma: no cover colour_correction_Finlayson2015` definition nan support. """ - # NOTE: Hangs on "Linux". - if platform.system() == "Linux": + # NOTE: Hangs on "macOS" and "Linux". + if platform.system() in ("Darwin", "Linux"): return cases = [-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan] @@ -1130,8 +1130,8 @@ def test_nan_colour_correction_Vandermonde(self): # pragma: no cover colour_correction_Vandermonde` definition nan support. """ - # NOTE: Hangs on "Linux". - if platform.system() == "Linux": + # NOTE: Hangs on "macOS" and "Linux". + if platform.system() in ("Darwin", "Linux"): return cases = [-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan] diff --git a/colour/io/luts/lut.py b/colour/io/luts/lut.py index c93cbf1e72..fcf9b3d5af 100644 --- a/colour/io/luts/lut.py +++ b/colour/io/luts/lut.py @@ -49,6 +49,7 @@ cast, ) from colour.utilities import ( + as_array, as_float_array, as_int, as_int_array, @@ -2118,10 +2119,15 @@ def linear_table( if domain.shape != (2, 3): samples = list( np.flip( - [ - axes[: (~np.isnan(axes)).cumsum().argmax() + 1] - for axes in np.transpose(domain) - ], + # NOTE: "dtype=object" is required for ragged array support + # in "Numpy" 1.24.0. + as_array( + [ + axes[: (~np.isnan(axes)).cumsum().argmax() + 1] + for axes in np.transpose(domain) + ], + dtype=object, # pyright: ignore + ), -1, ) ) diff --git a/colour/models/rgb/transfer_functions/canon.py b/colour/models/rgb/transfer_functions/canon.py index 7184024ab7..84e19845e2 100644 --- a/colour/models/rgb/transfer_functions/canon.py +++ b/colour/models/rgb/transfer_functions/canon.py @@ -112,7 +112,7 @@ def log_encoding_CanonLog( are obtained as follows: >>> x = np.array([0, 2, 18, 90, 720]) / 100 - >>> np.around(log_encoding_CanonLog(x) * (2**10 - 1)).astype(np.int) + >>> np.around(log_encoding_CanonLog(x) * (2**10 - 1)).astype(np.int_) array([ 128, 169, 351, 614, 1016]) >>> np.around(log_encoding_CanonLog(x, 10, False) * 100, 1) array([ 7.3, 12. , 32.8, 62.7, 108.7]) diff --git a/colour/models/rgb/transfer_functions/fujifilm_f_log.py b/colour/models/rgb/transfer_functions/fujifilm_f_log.py index ffa09e8d9d..99f70c175b 100644 --- a/colour/models/rgb/transfer_functions/fujifilm_f_log.py +++ b/colour/models/rgb/transfer_functions/fujifilm_f_log.py @@ -125,7 +125,7 @@ def log_encoding_FLog( >>> x = np.array([0, 18, 90]) / 100 >>> np.around(log_encoding_FLog(x, 10, False) * 100, 1) array([ 3.5, 46.3, 73.2]) - >>> np.around(log_encoding_FLog(x) * (2**10 - 1)).astype(np.int) + >>> np.around(log_encoding_FLog(x) * (2**10 - 1)).astype(np.int_) array([ 95, 470, 705]) """ @@ -294,7 +294,7 @@ def log_encoding_FLog2( >>> x = np.array([0, 18, 90]) / 100 >>> np.around(log_encoding_FLog2(x, 10, False) * 100, 1) array([ 3.5, 38.4, 57.8]) - >>> np.around(log_encoding_FLog2(x) * (2**10 - 1)).astype(np.int) + >>> np.around(log_encoding_FLog2(x) * (2**10 - 1)).astype(np.int_) array([ 95, 400, 570]) """ diff --git a/colour/models/rgb/transfer_functions/panasonic_v_log.py b/colour/models/rgb/transfer_functions/panasonic_v_log.py index bc14727354..4018688a2f 100644 --- a/colour/models/rgb/transfer_functions/panasonic_v_log.py +++ b/colour/models/rgb/transfer_functions/panasonic_v_log.py @@ -98,11 +98,11 @@ def log_encoding_VLog( are obtained as follows: >>> L_in = np.array([0, 18, 90]) / 100 - >>> np.around(log_encoding_VLog(L_in, 10, False) * 100).astype(np.int) + >>> np.around(log_encoding_VLog(L_in, 10, False) * 100).astype(np.int_) array([ 7, 42, 61]) - >>> np.around(log_encoding_VLog(L_in) * (2**10 - 1)).astype(np.int) + >>> np.around(log_encoding_VLog(L_in) * (2**10 - 1)).astype(np.int_) array([128, 433, 602]) - >>> np.around(log_encoding_VLog(L_in) * (2**12 - 1)).astype(np.int) + >>> np.around(log_encoding_VLog(L_in) * (2**12 - 1)).astype(np.int_) array([ 512, 1733, 2409]) Note that some values in the last column values of diff --git a/colour/models/rgb/transfer_functions/sony.py b/colour/models/rgb/transfer_functions/sony.py index 595c684ea2..40d4454df2 100644 --- a/colour/models/rgb/transfer_functions/sony.py +++ b/colour/models/rgb/transfer_functions/sony.py @@ -111,9 +111,9 @@ def log_encoding_SLog( :cite:`SonyCorporation2012a` are obtained as follows: >>> x = np.array([0, 18, 90]) / 100 - >>> np.around(log_encoding_SLog(x, 10, False) * 100).astype(np.int) + >>> np.around(log_encoding_SLog(x, 10, False) * 100).astype(np.int_) array([ 3, 38, 65]) - >>> np.around(log_encoding_SLog(x) * (2**10 - 1)).astype(np.int) + >>> np.around(log_encoding_SLog(x) * (2**10 - 1)).astype(np.int_) array([ 90, 394, 636]) """ @@ -257,9 +257,9 @@ def log_encoding_SLog2( :cite:`SonyCorporation2012a` are obtained as follows: >>> x = np.array([0, 18, 90]) / 100 - >>> np.around(log_encoding_SLog2(x, 10, False) * 100).astype(np.int) + >>> np.around(log_encoding_SLog2(x, 10, False) * 100).astype(np.int_) array([ 3, 32, 59]) - >>> np.around(log_encoding_SLog2(x) * (2**10 - 1)).astype(np.int) + >>> np.around(log_encoding_SLog2(x) * (2**10 - 1)).astype(np.int_) array([ 90, 347, 582]) """ @@ -386,9 +386,9 @@ def log_encoding_SLog3( :cite:`SonyCorporationd` are obtained as follows: >>> x = np.array([0, 18, 90]) / 100 - >>> np.around(log_encoding_SLog3(x, 10, False) * 100).astype(np.int) + >>> np.around(log_encoding_SLog3(x, 10, False) * 100).astype(np.int_) array([ 4, 41, 61]) - >>> np.around(log_encoding_SLog3(x) * (2**10 - 1)).astype(np.int) + >>> np.around(log_encoding_SLog3(x) * (2**10 - 1)).astype(np.int_) array([ 95, 420, 598]) """ diff --git a/colour/notation/munsell.py b/colour/notation/munsell.py index d8a7118adc..459b848df9 100644 --- a/colour/notation/munsell.py +++ b/colour/notation/munsell.py @@ -906,8 +906,8 @@ def _munsell_specification_to_xyY(specification: ArrayLike) -> NDArrayFloat: x_plus, y_plus = tsplit(munsell_specification_to_xy(specification_plus)) if value_minus == value_plus: - x = x_minus - y = y_minus + x = as_float(x_minus) + y = as_float(y_minus) else: with domain_range_scale("ignore"): Y_minus = luminance_ASTMD1535(value_minus) @@ -917,10 +917,12 @@ def _munsell_specification_to_xyY(specification: ArrayLike) -> NDArrayFloat: x_minus_plus = np.squeeze([x_minus, x_plus]) y_minus_plus = np.squeeze([y_minus, y_plus]) - x = LinearInterpolator(Y_minus_plus, x_minus_plus)(Y) - y = LinearInterpolator(Y_minus_plus, y_minus_plus)(Y) + x = as_float(LinearInterpolator(Y_minus_plus, x_minus_plus)(Y)) + y = as_float(LinearInterpolator(Y_minus_plus, y_minus_plus)(Y)) - return tstack([x, y, from_range_1(Y / 100)]) + Y = from_range_1(Y / 100) + + return tstack([x, y, Y]) def munsell_specification_to_xyY(specification: ArrayLike) -> NDArrayFloat: @@ -1293,12 +1295,12 @@ def _xyY_to_munsell_specification(xyY: ArrayLike) -> NDArrayFloat: if chroma_inner > chroma_maximum: chroma_inner = specification_current[2] = chroma_maximum - specification_inner = ( + specification_inner = [ hue_current, value, chroma_inner, code_current, - ) + ] with domain_range_scale("ignore"): x_inner, y_inner, _Y_inner = _munsell_specification_to_xyY( diff --git a/colour/notation/tests/test_munsell.py b/colour/notation/tests/test_munsell.py index 05beb28716..b30011cad7 100644 --- a/colour/notation/tests/test_munsell.py +++ b/colour/notation/tests/test_munsell.py @@ -52,6 +52,7 @@ munsell_value_ASTMD1535, ) from colour.utilities import ( + as_array, as_float_array, domain_range_scale, ignore_numpy_errors, @@ -154,7 +155,7 @@ def _generate_unit_tests_specifications() -> tuple: # pragma: no cover return specifications, specifications_r -MUNSELL_SPECIFICATIONS: NDArrayFloat = np.array( +MUNSELL_SPECIFICATIONS: NDArrayFloat = as_array( [ [ [7.18927191, 5.34025196, 16.05861170, 3.00000000], @@ -556,10 +557,11 @@ def _generate_unit_tests_specifications() -> tuple: # pragma: no cover [3.40490668, 6.59689139, 9.20874115, 7.00000000], [0.41967010, 0.31821655, 0.36537324], ], - ] + ], + dtype=object, # pyright: ignore ) -MUNSELL_GREYS_SPECIFICATIONS: NDArrayFloat = np.array( +MUNSELL_GREYS_SPECIFICATIONS: NDArrayFloat = as_array( list( zip( np.linspace(0, 10, 25)[:, None], @@ -591,10 +593,11 @@ def _generate_unit_tests_specifications() -> tuple: # pragma: no cover [0.31006, 0.31616, 1.00000000], ), ) - ) + ), + dtype=object, # pyright: ignore ) -MUNSELL_EVEN_SPECIFICATIONS: NDArrayFloat = np.array( +MUNSELL_EVEN_SPECIFICATIONS: NDArrayFloat = as_array( [ [(7.5, 6.0, 16.0, 3), [0.18320000, 0.44140000, 0.29301153]], [(7.5, 9.0, 12.0, 3), [0.24190000, 0.39850000, 0.76695586]], @@ -697,10 +700,11 @@ def _generate_unit_tests_specifications() -> tuple: # pragma: no cover [(7.5, 5.0, 4.0, 5), [0.38500000, 0.41200000, 0.19271844]], [(2.5, 6.0, 10.0, 7), [0.43200000, 0.31180000, 0.29301153]], [(8.0, 2, 14.0, 1), [0.07257382, 0.10413956, 0.03048116]], - ] # pyright: ignore + ], + dtype=object, # pyright: ignore ) -MUNSELL_BOUNDING_HUES: NDArrayFloat = np.array( +MUNSELL_BOUNDING_HUES: NDArrayFloat = as_float_array( [ ((5.0, 3.0), (7.5, 3.0)), ((5.0, 3.0), (7.5, 3.0)), diff --git a/colour/plotting/models.py b/colour/plotting/models.py index c4a37c2346..effc8ae307 100644 --- a/colour/plotting/models.py +++ b/colour/plotting/models.py @@ -1911,81 +1911,79 @@ def plot_constant_hue_loci( Examples -------- - >>> data = np.array( + >>> data = [ ... [ - ... [ - ... None, - ... np.array([0.95010000, 1.00000000, 1.08810000]), - ... np.array([0.40920000, 0.28120000, 0.30600000]), - ... np.array( - ... [ - ... [0.02495100, 0.01908600, 0.02032900], - ... [0.10944300, 0.06235900, 0.06788100], - ... [0.27186500, 0.18418700, 0.19565300], - ... [0.48898900, 0.40749400, 0.44854600], - ... ] - ... ), - ... None, - ... ], - ... [ - ... None, - ... np.array([0.95010000, 1.00000000, 1.08810000]), - ... np.array([0.30760000, 0.48280000, 0.42770000]), - ... np.array( - ... [ - ... [0.02108000, 0.02989100, 0.02790400], - ... [0.06194700, 0.11251000, 0.09334400], - ... [0.15255800, 0.28123300, 0.23234900], - ... [0.34157700, 0.56681300, 0.47035300], - ... ] - ... ), - ... None, - ... ], - ... [ - ... None, - ... np.array([0.95010000, 1.00000000, 1.08810000]), - ... np.array([0.39530000, 0.28120000, 0.18450000]), - ... np.array( - ... [ - ... [0.02436400, 0.01908600, 0.01468800], - ... [0.10331200, 0.06235900, 0.02854600], - ... [0.26311900, 0.18418700, 0.12109700], - ... [0.43158700, 0.40749400, 0.39008600], - ... ] - ... ), - ... None, - ... ], - ... [ - ... None, - ... np.array([0.95010000, 1.00000000, 1.08810000]), - ... np.array([0.20510000, 0.18420000, 0.57130000]), - ... np.array( - ... [ - ... [0.03039800, 0.02989100, 0.06123300], - ... [0.08870000, 0.08498400, 0.21843500], - ... [0.18405800, 0.18418700, 0.40111400], - ... [0.32550100, 0.34047200, 0.50296900], - ... [0.53826100, 0.56681300, 0.80010400], - ... ] - ... ), - ... None, - ... ], - ... [ - ... None, - ... np.array([0.95010000, 1.00000000, 1.08810000]), - ... np.array([0.35770000, 0.28120000, 0.11250000]), - ... np.array( - ... [ - ... [0.03678100, 0.02989100, 0.01481100], - ... [0.17127700, 0.11251000, 0.01229900], - ... [0.30080900, 0.28123300, 0.21229800], - ... [0.52976000, 0.40749400, 0.11720000], - ... ] - ... ), - ... None, - ... ], - ... ] - ... ) + ... None, + ... np.array([0.95010000, 1.00000000, 1.08810000]), + ... np.array([0.40920000, 0.28120000, 0.30600000]), + ... np.array( + ... [ + ... [0.02495100, 0.01908600, 0.02032900], + ... [0.10944300, 0.06235900, 0.06788100], + ... [0.27186500, 0.18418700, 0.19565300], + ... [0.48898900, 0.40749400, 0.44854600], + ... ] + ... ), + ... None, + ... ], + ... [ + ... None, + ... np.array([0.95010000, 1.00000000, 1.08810000]), + ... np.array([0.30760000, 0.48280000, 0.42770000]), + ... np.array( + ... [ + ... [0.02108000, 0.02989100, 0.02790400], + ... [0.06194700, 0.11251000, 0.09334400], + ... [0.15255800, 0.28123300, 0.23234900], + ... [0.34157700, 0.56681300, 0.47035300], + ... ] + ... ), + ... None, + ... ], + ... [ + ... None, + ... np.array([0.95010000, 1.00000000, 1.08810000]), + ... np.array([0.39530000, 0.28120000, 0.18450000]), + ... np.array( + ... [ + ... [0.02436400, 0.01908600, 0.01468800], + ... [0.10331200, 0.06235900, 0.02854600], + ... [0.26311900, 0.18418700, 0.12109700], + ... [0.43158700, 0.40749400, 0.39008600], + ... ] + ... ), + ... None, + ... ], + ... [ + ... None, + ... np.array([0.95010000, 1.00000000, 1.08810000]), + ... np.array([0.20510000, 0.18420000, 0.57130000]), + ... np.array( + ... [ + ... [0.03039800, 0.02989100, 0.06123300], + ... [0.08870000, 0.08498400, 0.21843500], + ... [0.18405800, 0.18418700, 0.40111400], + ... [0.32550100, 0.34047200, 0.50296900], + ... [0.53826100, 0.56681300, 0.80010400], + ... ] + ... ), + ... None, + ... ], + ... [ + ... None, + ... np.array([0.95010000, 1.00000000, 1.08810000]), + ... np.array([0.35770000, 0.28120000, 0.11250000]), + ... np.array( + ... [ + ... [0.03678100, 0.02989100, 0.01481100], + ... [0.17127700, 0.11251000, 0.01229900], + ... [0.30080900, 0.28123300, 0.21229800], + ... [0.52976000, 0.40749400, 0.11720000], + ... ] + ... ), + ... None, + ... ], + ... ] >>> plot_constant_hue_loci(data, "CIE Lab") # doctest: +ELLIPSIS (
, <...AxesSubplot...>) @@ -1995,7 +1993,9 @@ def plot_constant_hue_loci( """ # TODO: Filter appropriate colour models. - data = as_array(data) + # NOTE: "dtype=object" is required for ragged array support + # in "Numpy" 1.24.0. + data = as_array(data, dtype=object) # pyright: ignore settings: Dict[str, Any] = {"uniform": True} settings.update(kwargs) diff --git a/colour/plotting/tests/test_models.py b/colour/plotting/tests/test_models.py index 9fb0825e1b..45b3255c1d 100644 --- a/colour/plotting/tests/test_models.py +++ b/colour/plotting/tests/test_models.py @@ -494,81 +494,79 @@ class TestPlotConstantHueLoci(unittest.TestCase): def test_plot_constant_hue_loci(self): """Test :func:`colour.plotting.models.plot_constant_hue_loci` definition.""" - data = np.array( + data = [ [ - [ - None, - np.array([0.95010000, 1.00000000, 1.08810000]), - np.array([0.40920000, 0.28120000, 0.30600000]), - np.array( - [ - [0.02495100, 0.01908600, 0.02032900], - [0.10944300, 0.06235900, 0.06788100], - [0.27186500, 0.18418700, 0.19565300], - [0.48898900, 0.40749400, 0.44854600], - ] - ), - None, - ], - [ - None, - np.array([0.95010000, 1.00000000, 1.08810000]), - np.array([0.30760000, 0.48280000, 0.42770000]), - np.array( - [ - [0.02108000, 0.02989100, 0.02790400], - [0.06194700, 0.11251000, 0.09334400], - [0.15255800, 0.28123300, 0.23234900], - [0.34157700, 0.56681300, 0.47035300], - ] - ), - None, - ], - [ - None, - np.array([0.95010000, 1.00000000, 1.08810000]), - np.array([0.39530000, 0.28120000, 0.18450000]), - np.array( - [ - [0.02436400, 0.01908600, 0.01468800], - [0.10331200, 0.06235900, 0.02854600], - [0.26311900, 0.18418700, 0.12109700], - [0.43158700, 0.40749400, 0.39008600], - ] - ), - None, - ], - [ - None, - np.array([0.95010000, 1.00000000, 1.08810000]), - np.array([0.20510000, 0.18420000, 0.57130000]), - np.array( - [ - [0.03039800, 0.02989100, 0.06123300], - [0.08870000, 0.08498400, 0.21843500], - [0.18405800, 0.18418700, 0.40111400], - [0.32550100, 0.34047200, 0.50296900], - [0.53826100, 0.56681300, 0.80010400], - ] - ), - None, - ], - [ - None, - np.array([0.95010000, 1.00000000, 1.08810000]), - np.array([0.35770000, 0.28120000, 0.11250000]), - np.array( - [ - [0.03678100, 0.02989100, 0.01481100], - [0.17127700, 0.11251000, 0.01229900], - [0.30080900, 0.28123300, 0.21229800], - [0.52976000, 0.40749400, 0.11720000], - ] - ), - None, - ], - ] - ) + None, + np.array([0.95010000, 1.00000000, 1.08810000]), + np.array([0.40920000, 0.28120000, 0.30600000]), + np.array( + [ + [0.02495100, 0.01908600, 0.02032900], + [0.10944300, 0.06235900, 0.06788100], + [0.27186500, 0.18418700, 0.19565300], + [0.48898900, 0.40749400, 0.44854600], + ] + ), + None, + ], + [ + None, + np.array([0.95010000, 1.00000000, 1.08810000]), + np.array([0.30760000, 0.48280000, 0.42770000]), + np.array( + [ + [0.02108000, 0.02989100, 0.02790400], + [0.06194700, 0.11251000, 0.09334400], + [0.15255800, 0.28123300, 0.23234900], + [0.34157700, 0.56681300, 0.47035300], + ] + ), + None, + ], + [ + None, + np.array([0.95010000, 1.00000000, 1.08810000]), + np.array([0.39530000, 0.28120000, 0.18450000]), + np.array( + [ + [0.02436400, 0.01908600, 0.01468800], + [0.10331200, 0.06235900, 0.02854600], + [0.26311900, 0.18418700, 0.12109700], + [0.43158700, 0.40749400, 0.39008600], + ] + ), + None, + ], + [ + None, + np.array([0.95010000, 1.00000000, 1.08810000]), + np.array([0.20510000, 0.18420000, 0.57130000]), + np.array( + [ + [0.03039800, 0.02989100, 0.06123300], + [0.08870000, 0.08498400, 0.21843500], + [0.18405800, 0.18418700, 0.40111400], + [0.32550100, 0.34047200, 0.50296900], + [0.53826100, 0.56681300, 0.80010400], + ] + ), + None, + ], + [ + None, + np.array([0.95010000, 1.00000000, 1.08810000]), + np.array([0.35770000, 0.28120000, 0.11250000]), + np.array( + [ + [0.03678100, 0.02989100, 0.01481100], + [0.17127700, 0.11251000, 0.01229900], + [0.30080900, 0.28123300, 0.21229800], + [0.52976000, 0.40749400, 0.11720000], + ] + ), + None, + ], + ] figure, axes = plot_constant_hue_loci( data, "IPT", scatter_kwargs={"marker": "v"} diff --git a/colour/plotting/volume.py b/colour/plotting/volume.py index eeedd27105..42ae7f0a52 100644 --- a/colour/plotting/volume.py +++ b/colour/plotting/volume.py @@ -74,7 +74,7 @@ def nadir_grid( limits: Optional[ArrayLike] = None, segments: int = 10, - labels: Optional[Sequence[str]] = None, + labels: Optional[Union[ArrayLike, Sequence[str]]] = None, axes: Optional[plt.Axes] = None, **kwargs: Any, ) -> Tuple[NDArrayFloat, NDArrayFloat, NDArrayFloat]: diff --git a/colour/recovery/otsu2018.py b/colour/recovery/otsu2018.py index 731f48e07f..cfee9ae468 100644 --- a/colour/recovery/otsu2018.py +++ b/colour/recovery/otsu2018.py @@ -1576,14 +1576,13 @@ def to_dataset(self) -> Dataset_Otsu2018: selector_array = zeros(4) else: - def add_rows(node, data=None): + def add_rows( + node: Node_Otsu2018, data: Optional[dict] = None + ) -> Optional[dict]: """Add rows for given node and its children.""" - data = cast( - dict, - optional( - data, {"rows": [], "node_to_leaf_id": {}, "leaf_id": 0} - ), + data = optional( + data, {"rows": [], "node_to_leaf_id": {}, "leaf_id": 0} ) if node.is_leaf(): @@ -1599,7 +1598,7 @@ def add_rows(node, data=None): return data - data = add_rows(self) + data = cast(dict, add_rows(self)) rows = data["rows"] for i, row in enumerate(rows): diff --git a/colour/recovery/tests/test_jiang2013.py b/colour/recovery/tests/test_jiang2013.py index d320cd6904..07cfa2ab02 100644 --- a/colour/recovery/tests/test_jiang2013.py +++ b/colour/recovery/tests/test_jiang2013.py @@ -65,103 +65,103 @@ def test_PCA_Jiang2013(self): np.array( [ [ - [-1.37594347e-03, 3.99415732e-03, -6.04239828e-04], - [-2.14834542e-03, 1.84422104e-03, 3.21589852e-01], - [-2.75718149e-02, 5.53587216e-03, 5.40389791e-02], - [-2.51062139e-02, -4.21646800e-02, -2.70235131e-02], - [-2.01162330e-02, -3.37116245e-02, -5.68936622e-03], - [-1.39228153e-02, -3.29798532e-02, -1.95221649e-02], - [-9.44512929e-03, -3.30093792e-02, -3.04555338e-02], - [-2.01995779e-02, -1.28939958e-02, 2.22562167e-02], - [-2.39442292e-02, -9.80934362e-03, -1.01147393e-02], - [-4.19632625e-02, 4.98705001e-02, -8.57577942e-03], - [-4.98873166e-02, 6.93660333e-02, 2.05472209e-01], - [-6.52714132e-02, 9.37861421e-02, 3.73495566e-02], - [-9.41257461e-02, 1.22440811e-01, 1.40014392e-01], - [-1.09159133e-01, 1.31199835e-01, 8.83163250e-02], - [-1.23148401e-01, 2.42809357e-01, 2.01309902e-01], - [-1.16739413e-01, 2.77007375e-01, 1.86676559e-01], - [-1.25341332e-01, 2.99941272e-01, 2.17837858e-01], - [-1.45992549e-01, 2.55865322e-01, 2.27131989e-01], - [-2.52490904e-01, -1.14997503e-01, -2.20533434e-01], - [-3.51634066e-01, -4.52868183e-01, -1.39652545e-01], - [-3.58057369e-01, -4.07242523e-01, 2.58829683e-01], - [-3.69278993e-01, -1.81208375e-01, 5.19968568e-01], - [-3.53748849e-01, -3.01000786e-02, -2.55655981e-01], - [-3.53409087e-01, 1.68475269e-01, -2.84106537e-01], - [-3.26961156e-01, 2.90689809e-01, -1.63314143e-01], - [-2.90673539e-01, 3.28627021e-01, -2.49733529e-01], - [-8.96475804e-02, -9.68265584e-02, -6.97440356e-02], - [-1.89166432e-02, -8.22111312e-02, -2.42073036e-03], - [-5.21149231e-03, -1.57890680e-02, -4.33465348e-05], - [-2.32366424e-03, -1.37750678e-03, 4.06389245e-04], - [-1.53786508e-03, 2.54398457e-03, -3.80279581e-04], + [-0.00137594, -0.00399416, -0.00060424], + [-0.00214835, -0.00184422, 0.32158985], + [-0.02757181, -0.00553587, 0.05403898], + [-0.02510621, 0.04216468, -0.02702351], + [-0.02011623, 0.03371162, -0.00568937], + [-0.01392282, 0.03297985, -0.01952216], + [-0.00944513, 0.03300938, -0.03045553], + [-0.02019958, 0.01289400, 0.02225622], + [-0.02394423, 0.00980934, -0.01011474], + [-0.04196326, -0.04987050, -0.00857578], + [-0.04988732, -0.06936603, 0.20547221], + [-0.06527141, -0.09378614, 0.03734956], + [-0.09412575, -0.12244081, 0.14001439], + [-0.10915913, -0.13119983, 0.08831632], + [-0.12314840, -0.24280936, 0.20130990], + [-0.11673941, -0.27700737, 0.18667656], + [-0.12534133, -0.29994127, 0.21783786], + [-0.14599255, -0.25586532, 0.22713199], + [-0.25249090, 0.11499750, -0.22053343], + [-0.35163407, 0.45286818, -0.13965255], + [-0.35805737, 0.40724252, 0.25882968], + [-0.36927899, 0.18120838, 0.51996857], + [-0.35374885, 0.03010008, -0.25565598], + [-0.35340909, -0.16847527, -0.28410654], + [-0.32696116, -0.29068981, -0.16331414], + [-0.29067354, -0.32862702, -0.24973353], + [-0.08964758, 0.09682656, -0.06974404], + [-0.01891664, 0.08221113, -0.00242073], + [-0.00521149, 0.01578907, -0.00004335], + [-0.00232366, 0.00137751, 0.00040639], + [-0.00153787, -0.00254398, -0.00038028], ], [ - [-1.19597520e-03, 2.67792288e-03, -3.86643802e-04], - [-2.00326785e-03, 3.22982608e-03, 5.86749223e-01], - [-1.24781553e-02, -3.31397595e-02, -3.56296307e-02], - [-3.20768524e-02, -5.70329419e-02, -9.69280990e-03], - [-4.71505049e-02, -5.29645114e-02, 7.66902127e-02], - [-5.79400988e-02, -5.45573700e-02, -3.14568063e-04], - [-1.07455711e-01, 1.58910582e-03, -7.05327185e-02], - [-1.41785255e-01, -3.36276409e-02, -1.05701318e-01], - [-1.68114016e-01, -5.56983321e-02, -1.23153686e-01], - [-1.84637156e-01, -4.61540356e-02, 2.00697387e-01], - [-2.15316233e-01, -9.74507835e-02, 1.80376932e-01], - [-2.54425702e-01, -1.83304806e-01, -1.36618663e-01], - [-2.81680176e-01, -2.51932665e-01, -7.73950380e-02], - [-2.92371785e-01, -2.85454281e-01, 1.46039739e-02], - [-2.96931166e-01, -2.39094667e-01, -2.41823482e-01], - [-2.86313189e-01, -1.94764406e-01, -5.44135282e-02], - [-2.71959682e-01, -1.20874204e-01, 4.06551254e-01], - [-2.59881399e-01, -1.58131608e-02, 3.24704412e-01], - [-2.42226602e-01, 7.91297201e-02, -2.70855184e-01], - [-2.30696979e-01, 1.85836669e-01, -2.53245992e-02], - [-2.08319826e-01, 2.67455613e-01, -2.32430787e-01], - [-1.94371680e-01, 3.24250095e-01, 1.02375615e-01], - [-1.84708937e-01, 3.47680795e-01, -1.85437047e-02], - [-1.80561798e-01, 3.59832206e-01, -6.30127108e-02], - [-1.71413369e-01, 3.50673059e-01, 1.97691095e-01], - [-1.47125410e-01, 3.04231720e-01, -7.27877894e-02], - [-2.89702613e-02, 4.57399297e-02, -1.10745662e-02], - [-1.90227628e-03, -4.61591110e-03, 3.34622914e-04], - [-6.91221876e-04, -1.18816974e-03, -6.73601845e-04], - [-4.55594621e-04, 1.52863579e-04, -3.90316310e-05], - [-3.95094896e-04, 4.97187702e-04, -3.12174899e-04], + [-0.00119598, -0.00267792, -0.00047163], + [-0.00200327, -0.00322983, 0.58674915], + [-0.01247816, 0.03313976, -0.03562970], + [-0.03207685, 0.05703294, -0.00969283], + [-0.04715050, 0.05296451, 0.07669022], + [-0.05794010, 0.05455737, -0.00031457], + [-0.10745571, -0.00158911, -0.07053271], + [-0.14178525, 0.03362764, -0.10570131], + [-0.16811402, 0.05569833, -0.12315365], + [-0.18463716, 0.04615404, 0.20069739], + [-0.21531623, 0.09745078, 0.18037692], + [-0.25442570, 0.18330481, -0.13661865], + [-0.28168018, 0.25193267, -0.07739509], + [-0.29237178, 0.28545428, 0.01460388], + [-0.29693117, 0.23909467, -0.24182353], + [-0.28631319, 0.19476441, -0.05441354], + [-0.27195968, 0.12087420, 0.40655125], + [-0.25988140, 0.01581316, 0.32470450], + [-0.24222660, -0.07912972, -0.27085507], + [-0.23069698, -0.18583667, -0.02532450], + [-0.20831983, -0.26745561, -0.23243075], + [-0.19437168, -0.32425009, 0.10237571], + [-0.18470894, -0.34768079, -0.01854361], + [-0.18056180, -0.35983221, -0.06301260], + [-0.17141337, -0.35067306, 0.19769116], + [-0.14712541, -0.30423172, -0.07278775], + [-0.02897026, -0.04573993, -0.01107455], + [-0.00190228, 0.00461591, 0.00033462], + [-0.00069122, 0.00118817, -0.00067360], + [-0.00045559, -0.00015286, -0.00003903], + [-0.00039509, -0.00049719, -0.00031217], ], [ - [-3.28337112e-02, 4.70716173e-02, -9.98004473e-01], - [-5.93269036e-02, 7.52974019e-02, 2.05260665e-02], - [-1.19473811e-01, -7.97721941e-02, -6.30794639e-03], - [-1.84922334e-01, -2.61273738e-01, -5.20246519e-03], - [-2.20915638e-01, -2.92799758e-01, -1.19336143e-02], - [-2.53778754e-01, -3.06777085e-01, 1.25936314e-03], - [-2.99698219e-01, -2.65417765e-01, -7.01599755e-03], - [-3.02327547e-01, -2.53786221e-01, -6.03326686e-03], - [-3.00317318e-01, -1.97511844e-01, 6.89292013e-03], - [-2.80722764e-01, -1.18042847e-01, 5.98880768e-04], - [-2.60057468e-01, -1.83633282e-02, 1.24579462e-02], - [-2.38393671e-01, 7.18242068e-02, 1.33587494e-02], - [-2.17218308e-01, 1.42454103e-01, 1.25650206e-02], - [-1.98284048e-01, 1.76849496e-01, 2.16223803e-02], - [-1.90184510e-01, 2.01377808e-01, 1.45692504e-02], - [-1.81967620e-01, 2.20863209e-01, 9.80505521e-03], - [-1.71686442e-01, 2.27718732e-01, 1.72325013e-02], - [-1.69770729e-01, 2.35040183e-01, 2.20444682e-02], - [-1.62776705e-01, 2.28977971e-01, 1.55453131e-02], - [-1.58804226e-01, 2.25836749e-01, 2.01730266e-02], - [-1.49668124e-01, 2.14943120e-01, 9.86008333e-03], - [-1.34801552e-01, 1.95111622e-01, 1.15561577e-02], - [-1.25417642e-01, 1.81132377e-01, 5.97801693e-03], - [-1.23557313e-01, 1.78351495e-01, 1.02617561e-02], - [-1.11750645e-01, 1.59976514e-01, 8.14162092e-03], - [-9.44030423e-02, 1.34234535e-01, 9.11543681e-03], - [-1.67058128e-02, 2.01966959e-02, 1.09903718e-03], - [-4.50023573e-04, -1.47361849e-03, -6.44936616e-05], - [-1.02919085e-03, 9.59038318e-04, 8.20098491e-05], - [-9.73971054e-04, 1.23434432e-03, 6.73016617e-05], - [-9.71160886e-04, 1.24835480e-03, 8.00827657e-05], + [-0.03283371, -0.04707162, 0.99800447], + [-0.05932690, -0.07529740, -0.02052607], + [-0.11947381, 0.07977219, 0.00630795], + [-0.18492233, 0.26127374, 0.00520247], + [-0.22091564, 0.29279976, 0.01193361], + [-0.25377875, 0.30677709, -0.00125936], + [-0.29969822, 0.26541777, 0.00701600], + [-0.30232755, 0.25378622, 0.00603327], + [-0.30031732, 0.19751184, -0.00689292], + [-0.28072276, 0.11804285, -0.00059888], + [-0.26005747, 0.01836333, -0.01245795], + [-0.23839367, -0.07182421, -0.01335875], + [-0.21721831, -0.14245410, -0.01256502], + [-0.19828405, -0.17684950, -0.02162238], + [-0.19018451, -0.20137781, -0.01456925], + [-0.18196762, -0.22086321, -0.00980506], + [-0.17168644, -0.22771873, -0.01723250], + [-0.16977073, -0.23504018, -0.02204447], + [-0.16277670, -0.22897797, -0.01554531], + [-0.15880423, -0.22583675, -0.02017303], + [-0.14966812, -0.21494312, -0.00986008], + [-0.13480155, -0.19511162, -0.01155616], + [-0.12541764, -0.18113238, -0.00597802], + [-0.12355731, -0.17835150, -0.01026176], + [-0.11175064, -0.15997651, -0.00814162], + [-0.09440304, -0.13423453, -0.00911544], + [-0.01670581, -0.02019670, -0.00109904], + [-0.00045002, 0.00147362, 0.00006449], + [-0.00102919, -0.00095904, -0.00008201], + [-0.00097397, -0.00123434, -0.00006730], + [-0.00097116, -0.00124835, -0.00008008], ], ] )[..., 0:2], diff --git a/colour/recovery/tests/test_otsu2018.py b/colour/recovery/tests/test_otsu2018.py index 4d5e82da61..94ef242e90 100644 --- a/colour/recovery/tests/test_otsu2018.py +++ b/colour/recovery/tests/test_otsu2018.py @@ -490,42 +490,42 @@ def test_PCA(self): 0.11620896, ], [ - 0.03137588, - 0.06204234, - 0.11364884, - 0.17579436, - 0.20914074, - 0.22152351, - 0.23120105, - 0.24039823, - 0.24730359, - 0.25195045, - 0.25237533, - 0.24672212, - 0.23538236, - 0.22094141, - 0.20389065, - 0.18356599, - 0.15952882, - 0.13567812, - 0.11401807, - 0.09178015, - 0.06539517, - 0.03173809, - -0.00658524, - -0.04710763, - -0.08379987, - -0.11074555, - -0.12606191, - -0.13630094, - -0.13988107, - -0.14193361, - -0.14671866, - -0.15164795, - -0.15772737, - -0.16328073, - -0.16588768, - -0.16947164, + -0.03137588, + -0.06204234, + -0.11364884, + -0.17579436, + -0.20914074, + -0.22152351, + -0.23120105, + -0.24039823, + -0.24730359, + -0.25195045, + -0.25237533, + -0.24672212, + -0.23538236, + -0.22094141, + -0.20389065, + -0.18356599, + -0.15952882, + -0.13567812, + -0.11401807, + -0.09178015, + -0.06539517, + -0.03173809, + 0.00658524, + 0.04710763, + 0.08379987, + 0.11074555, + 0.12606191, + 0.13630094, + 0.13988107, + 0.14193361, + 0.14671866, + 0.15164795, + 0.15772737, + 0.16328073, + 0.16588768, + 0.16947164, ], [ -0.01360289, diff --git a/colour/temperature/cie_d.py b/colour/temperature/cie_d.py index 97bd6eaadc..e003363835 100644 --- a/colour/temperature/cie_d.py +++ b/colour/temperature/cie_d.py @@ -159,16 +159,18 @@ def CCT_to_xy_CIE_D(CCT: ArrayLike) -> NDArrayFloat: CCT_3 = CCT**3 CCT_2 = CCT**2 - x = np.where( - CCT <= 7000, - -4.607 * 10**9 / CCT_3 - + 2.9678 * 10**6 / CCT_2 - + 0.09911 * 10**3 / CCT - + 0.244063, - -2.0064 * 10**9 / CCT_3 - + 1.9018 * 10**6 / CCT_2 - + 0.24748 * 10**3 / CCT - + 0.23704, + x = as_float( + np.where( + CCT <= 7000, + -4.607 * 10**9 / CCT_3 + + 2.9678 * 10**6 / CCT_2 + + 0.09911 * 10**3 / CCT + + 0.244063, + -2.0064 * 10**9 / CCT_3 + + 1.9018 * 10**6 / CCT_2 + + 0.24748 * 10**3 / CCT + + 0.23704, + ) ) y = daylight_locus_function(x) diff --git a/colour/utilities/array.py b/colour/utilities/array.py index 65a86404e1..4c654ff608 100644 --- a/colour/utilities/array.py +++ b/colour/utilities/array.py @@ -594,14 +594,19 @@ def as_int(a: ArrayLike, dtype: Optional[Type[DTypeInt]] = None) -> NDArrayInt: dtype = optional(dtype, DEFAULT_INT_DTYPE) args = getattr(DTypeInt, "__args__") + attest( dtype in args, f'"dtype" must be one of the following types: {args}', ) - # TODO: Reassess implementation when and if - # https://github.com/numpy/numpy/issues/11956 is addressed. - return dtype(np.squeeze(a)) # pyright: ignore + try: + if len(a) == 1: # pyright: ignore + a = np.squeeze(a) + except TypeError: + pass + + return dtype(a) # pyright: ignore def as_float( @@ -643,6 +648,12 @@ def as_float( f'"dtype" must be one of the following types: {args}', ) + try: + if len(a) == 1: # pyright: ignore + a = np.squeeze(a) + except TypeError: + pass + return dtype(a) # pyright: ignore diff --git a/utilities/generate_plots.py b/utilities/generate_plots.py index 7eba9a05c2..d8ec3f3867 100755 --- a/utilities/generate_plots.py +++ b/utilities/generate_plots.py @@ -710,81 +710,79 @@ def generate_documentation_plots(output_directory: str): ) plt.close(plot_multi_cctfs(["ITU-R BT.709", "sRGB"], **arguments)[0]) - data = np.array( + data = [ [ - [ - None, - np.array([0.95010000, 1.00000000, 1.08810000]), - np.array([0.40920000, 0.28120000, 0.30600000]), - np.array( - [ - [0.02495100, 0.01908600, 0.02032900], - [0.10944300, 0.06235900, 0.06788100], - [0.27186500, 0.18418700, 0.19565300], - [0.48898900, 0.40749400, 0.44854600], - ] - ), - None, - ], - [ - None, - np.array([0.95010000, 1.00000000, 1.08810000]), - np.array([0.30760000, 0.48280000, 0.42770000]), - np.array( - [ - [0.02108000, 0.02989100, 0.02790400], - [0.06194700, 0.11251000, 0.09334400], - [0.15255800, 0.28123300, 0.23234900], - [0.34157700, 0.56681300, 0.47035300], - ] - ), - None, - ], - [ - None, - np.array([0.95010000, 1.00000000, 1.08810000]), - np.array([0.39530000, 0.28120000, 0.18450000]), - np.array( - [ - [0.02436400, 0.01908600, 0.01468800], - [0.10331200, 0.06235900, 0.02854600], - [0.26311900, 0.18418700, 0.12109700], - [0.43158700, 0.40749400, 0.39008600], - ] - ), - None, - ], - [ - None, - np.array([0.95010000, 1.00000000, 1.08810000]), - np.array([0.20510000, 0.18420000, 0.57130000]), - np.array( - [ - [0.03039800, 0.02989100, 0.06123300], - [0.08870000, 0.08498400, 0.21843500], - [0.18405800, 0.18418700, 0.40111400], - [0.32550100, 0.34047200, 0.50296900], - [0.53826100, 0.56681300, 0.80010400], - ] - ), - None, - ], - [ - None, - np.array([0.95010000, 1.00000000, 1.08810000]), - np.array([0.35770000, 0.28120000, 0.11250000]), - np.array( - [ - [0.03678100, 0.02989100, 0.01481100], - [0.17127700, 0.11251000, 0.01229900], - [0.30080900, 0.28123300, 0.21229800], - [0.52976000, 0.40749400, 0.11720000], - ] - ), - None, - ], - ] # pyright: ignore - ) + None, + np.array([0.95010000, 1.00000000, 1.08810000]), + np.array([0.40920000, 0.28120000, 0.30600000]), + np.array( + [ + [0.02495100, 0.01908600, 0.02032900], + [0.10944300, 0.06235900, 0.06788100], + [0.27186500, 0.18418700, 0.19565300], + [0.48898900, 0.40749400, 0.44854600], + ] + ), + None, + ], + [ + None, + np.array([0.95010000, 1.00000000, 1.08810000]), + np.array([0.30760000, 0.48280000, 0.42770000]), + np.array( + [ + [0.02108000, 0.02989100, 0.02790400], + [0.06194700, 0.11251000, 0.09334400], + [0.15255800, 0.28123300, 0.23234900], + [0.34157700, 0.56681300, 0.47035300], + ] + ), + None, + ], + [ + None, + np.array([0.95010000, 1.00000000, 1.08810000]), + np.array([0.39530000, 0.28120000, 0.18450000]), + np.array( + [ + [0.02436400, 0.01908600, 0.01468800], + [0.10331200, 0.06235900, 0.02854600], + [0.26311900, 0.18418700, 0.12109700], + [0.43158700, 0.40749400, 0.39008600], + ] + ), + None, + ], + [ + None, + np.array([0.95010000, 1.00000000, 1.08810000]), + np.array([0.20510000, 0.18420000, 0.57130000]), + np.array( + [ + [0.03039800, 0.02989100, 0.06123300], + [0.08870000, 0.08498400, 0.21843500], + [0.18405800, 0.18418700, 0.40111400], + [0.32550100, 0.34047200, 0.50296900], + [0.53826100, 0.56681300, 0.80010400], + ] + ), + None, + ], + [ + None, + np.array([0.95010000, 1.00000000, 1.08810000]), + np.array([0.35770000, 0.28120000, 0.11250000]), + np.array( + [ + [0.03678100, 0.02989100, 0.01481100], + [0.17127700, 0.11251000, 0.01229900], + [0.30080900, 0.28123300, 0.21229800], + [0.52976000, 0.40749400, 0.11720000], + ] + ), + None, + ], + ] arguments["filename"] = os.path.join( output_directory, "Plotting_Plot_Constant_Hue_Loci.png" )