From 8e5f37e1cb9d9012ea728697fb23ce170f50dcf8 Mon Sep 17 00:00:00 2001 From: Thomas Mansencal Date: Sat, 10 Dec 2022 22:48:43 +1300 Subject: [PATCH] Replace "Mypy" with "Pyright". --- ...nuous-integration-static-type-checking.yml | 2 +- colour/__init__.py | 16 +- colour/adaptation/__init__.py | 4 +- colour/adaptation/cie1994.py | 70 ++--- colour/adaptation/cmccat2000.py | 26 +- colour/adaptation/datasets/cat.py | 26 +- colour/adaptation/fairchild1990.py | 39 +-- colour/adaptation/vonkries.py | 6 +- colour/adaptation/zhai2018.py | 14 +- colour/algebra/__init__.py | 2 +- colour/algebra/common.py | 84 +++-- colour/algebra/coordinates/transformations.py | 16 +- colour/algebra/extrapolation.py | 18 +- colour/algebra/interpolation.py | 216 +++++++------ colour/algebra/prng.py | 6 +- colour/algebra/regression.py | 6 +- colour/algebra/tests/test_interpolation.py | 45 +-- colour/algebra/tests/test_prng.py | 4 +- colour/appearance/atd95.py | 97 ++++-- colour/appearance/cam16.py | 55 ++-- colour/appearance/ciecam02.py | 250 +++++++-------- colour/appearance/ciecam16.py | 61 ++-- colour/appearance/hellwig2022.py | 130 ++++---- colour/appearance/hke.py | 32 +- colour/appearance/hunt.py | 249 ++++++++------- colour/appearance/kim2009.py | 53 ++-- colour/appearance/llab.py | 131 ++++---- colour/appearance/nayatani95.py | 211 +++++++------ colour/appearance/rlab.py | 55 ++-- colour/appearance/zcam.py | 117 ++++--- colour/biochemistry/__init__.py | 4 +- colour/biochemistry/michaelis_menten.py | 68 ++-- colour/blindness/machado2009.py | 23 +- colour/characterisation/__init__.py | 2 +- colour/characterisation/aces_it.py | 61 ++-- colour/characterisation/cameras.py | 22 +- colour/characterisation/correction.py | 40 ++- colour/characterisation/datasets/aces_it.py | 3 +- .../datasets/cameras/dslr/sensitivities.py | 3 +- .../chromaticity_coordinates.py | 28 +- .../datasets/colour_checkers/sds.py | 3 +- .../datasets/displays/crt/primaries.py | 3 +- .../datasets/displays/lcd/primaries.py | 3 +- .../characterisation/datasets/filters/sds.py | 3 +- .../characterisation/datasets/lenses/sds.py | 3 +- colour/characterisation/displays.py | 22 +- .../characterisation/tests/test_correction.py | 6 +- colour/colorimetry/blackbody.py | 40 +-- colour/colorimetry/cmfs.py | 22 +- colour/colorimetry/correction.py | 4 +- colour/colorimetry/datasets/cmfs.py | 7 +- .../datasets/illuminants/hunterlab.py | 5 +- .../colorimetry/datasets/illuminants/sds.py | 5 +- .../illuminants/sds_d_illuminant_series.py | 3 +- colour/colorimetry/datasets/lefs.py | 7 +- .../colorimetry/datasets/light_sources/sds.py | 11 +- colour/colorimetry/dominant.py | 21 +- colour/colorimetry/generation.py | 31 +- colour/colorimetry/illuminants.py | 13 +- colour/colorimetry/lefs.py | 56 ++-- colour/colorimetry/lightness.py | 52 ++- colour/colorimetry/luminance.py | 52 ++- colour/colorimetry/photometry.py | 30 +- colour/colorimetry/spectrum.py | 142 +++++---- colour/colorimetry/tests/test_blackbody.py | 10 +- colour/colorimetry/tests/test_correction.py | 5 +- colour/colorimetry/tests/test_illuminants.py | 4 +- colour/colorimetry/tests/test_lefs.py | 3 +- colour/colorimetry/tests/test_spectrum.py | 19 +- .../tests/test_tristimulus_values.py | 28 +- colour/colorimetry/tests/test_uniformity.py | 6 +- colour/colorimetry/transformations.py | 22 +- colour/colorimetry/tristimulus_values.py | 57 ++-- colour/colorimetry/uniformity.py | 8 +- colour/colorimetry/whiteness.py | 31 +- colour/colorimetry/yellowness.py | 18 +- colour/constants/common.py | 18 +- colour/continuous/abstract.py | 100 +++--- colour/continuous/multi_signals.py | 106 +++---- colour/continuous/signal.py | 99 +++--- colour/contrast/__init__.py | 6 +- colour/contrast/barten1999.py | 85 +++-- colour/corresponding/prediction.py | 18 +- colour/corresponding/tests/test_prediction.py | 12 +- colour/difference/__init__.py | 6 +- colour/difference/cam02_ucs.py | 24 +- colour/difference/delta_e.py | 30 +- colour/difference/din99.py | 8 +- colour/difference/huang2015.py | 8 +- colour/difference/stress.py | 16 +- .../examples/colorimetry/examples_spectrum.py | 18 +- colour/examples/contrast/examples_contrast.py | 17 +- colour/examples/graph/examples_graph.py | 4 +- colour/examples/io/examples_ctl.py | 2 +- colour/examples/models/examples_ycbcr.py | 8 +- .../plotting/examples_colorimetry_plots.py | 13 +- .../plotting/examples_section_plots.py | 2 +- colour/geometry/__init__.py | 2 +- colour/geometry/ellipse.py | 17 +- colour/geometry/intersection.py | 31 +- colour/geometry/primitives.py | 70 ++--- colour/geometry/section.py | 23 +- colour/geometry/vertices.py | 54 ++-- colour/graph/conversion.py | 57 ++-- colour/hints/__init__.py | 295 ++++-------------- colour/io/ctl.py | 26 +- colour/io/image.py | 67 ++-- colour/io/luts/__init__.py | 20 +- colour/io/luts/cinespace_csp.py | 20 +- colour/io/luts/iridas_cube.py | 12 +- colour/io/luts/lut.py | 207 ++++++------ colour/io/luts/operator.py | 29 +- colour/io/luts/resolve_cube.py | 14 +- colour/io/luts/sequence.py | 24 +- colour/io/luts/sony_spi1d.py | 8 +- colour/io/luts/sony_spi3d.py | 10 +- colour/io/luts/sony_spimtx.py | 6 +- colour/io/luts/tests/test_lut.py | 52 ++- colour/io/luts/tests/test_sequence.py | 12 +- colour/io/ocio.py | 8 +- colour/io/tabular.py | 14 +- colour/io/tests/test_tabular.py | 3 +- colour/io/tests/test_tm2714.py | 14 +- colour/io/tests/test_uprtek_sekonic.py | 4 +- colour/io/tests/test_xrite.py | 3 +- colour/io/tm2714.py | 37 +-- colour/io/uprtek_sekonic.py | 12 +- colour/io/xrite.py | 6 +- colour/models/__init__.py | 2 +- colour/models/cam02_ucs.py | 40 +-- colour/models/cam16_ucs.py | 13 +- colour/models/cie_lab.py | 10 +- colour/models/cie_luv.py | 20 +- colour/models/cie_ucs.py | 14 +- colour/models/cie_uvw.py | 8 +- colour/models/cie_xyy.py | 14 +- colour/models/common.py | 12 +- colour/models/datasets/macadam_ellipses.py | 4 +- colour/models/datasets/pointer_gamut.py | 8 +- colour/models/din99.py | 26 +- colour/models/hdr_cie_lab.py | 27 +- colour/models/hdr_ipt.py | 27 +- colour/models/hunter_lab.py | 8 +- colour/models/hunter_rdab.py | 6 +- colour/models/icacb.py | 24 +- colour/models/igpgtg.py | 27 +- colour/models/ipt.py | 18 +- colour/models/jzazbz.py | 27 +- colour/models/munish2021.py | 14 +- colour/models/oklab.py | 14 +- colour/models/osa_ucs.py | 12 +- colour/models/prolab.py | 20 +- colour/models/rgb/cmyk.py | 10 +- colour/models/rgb/common.py | 10 +- colour/models/rgb/cylindrical.py | 26 +- colour/models/rgb/datasets/aces.py | 18 +- colour/models/rgb/datasets/adobe_rgb_1998.py | 10 +- .../rgb/datasets/adobe_wide_gamut_rgb.py | 10 +- colour/models/rgb/datasets/apple_rgb.py | 10 +- colour/models/rgb/datasets/arri.py | 18 +- colour/models/rgb/datasets/best_rgb.py | 10 +- colour/models/rgb/datasets/beta_rgb.py | 10 +- .../models/rgb/datasets/blackmagic_design.py | 10 +- .../models/rgb/datasets/canon_cinema_gamut.py | 12 +- colour/models/rgb/datasets/cie_rgb.py | 10 +- colour/models/rgb/datasets/color_match_rgb.py | 10 +- .../models/rgb/datasets/davinci_wide_gamut.py | 10 +- colour/models/rgb/datasets/dcdm_xyz.py | 10 +- colour/models/rgb/datasets/dci_p3.py | 16 +- colour/models/rgb/datasets/display_p3.py | 12 +- colour/models/rgb/datasets/dji_d_gamut.py | 10 +- colour/models/rgb/datasets/don_rgb_4.py | 10 +- colour/models/rgb/datasets/ebu_3213_e.py | 10 +- colour/models/rgb/datasets/eci_rgb_v2.py | 21 +- colour/models/rgb/datasets/ekta_space_ps5.py | 10 +- .../models/rgb/datasets/filmlight_e_gamut.py | 10 +- .../models/rgb/datasets/fujifilm_f_gamut.py | 10 +- colour/models/rgb/datasets/gopro.py | 10 +- colour/models/rgb/datasets/itur_bt_2020.py | 10 +- colour/models/rgb/datasets/itur_bt_470.py | 18 +- colour/models/rgb/datasets/itur_bt_709.py | 10 +- colour/models/rgb/datasets/itut_h_273.py | 22 +- colour/models/rgb/datasets/max_rgb.py | 10 +- colour/models/rgb/datasets/nikon_n_gamut.py | 10 +- colour/models/rgb/datasets/ntsc.py | 18 +- colour/models/rgb/datasets/p3_d65.py | 10 +- colour/models/rgb/datasets/pal_secam.py | 10 +- .../models/rgb/datasets/panasonic_v_gamut.py | 10 +- colour/models/rgb/datasets/red.py | 64 ++-- colour/models/rgb/datasets/rimm_romm_rgb.py | 34 +- colour/models/rgb/datasets/russell_rgb.py | 12 +- colour/models/rgb/datasets/sharp.py | 10 +- colour/models/rgb/datasets/smpte_240m.py | 12 +- colour/models/rgb/datasets/smpte_c.py | 10 +- colour/models/rgb/datasets/sony.py | 42 +-- colour/models/rgb/datasets/srgb.py | 10 +- colour/models/rgb/datasets/xtreme_rgb.py | 12 +- colour/models/rgb/derivation.py | 19 +- colour/models/rgb/hanbury2003.py | 12 +- colour/models/rgb/ictcp.py | 30 +- colour/models/rgb/itut_h_273.py | 47 ++- colour/models/rgb/prismatic.py | 6 +- colour/models/rgb/rgb_colourspace.py | 63 ++-- .../models/rgb/transfer_functions/__init__.py | 67 ++-- colour/models/rgb/transfer_functions/aces.py | 68 ++-- .../rgb/transfer_functions/arib_std_b67.py | 18 +- colour/models/rgb/transfer_functions/arri.py | 26 +- .../transfer_functions/blackmagic_design.py | 14 +- colour/models/rgb/transfer_functions/canon.py | 78 +++-- .../models/rgb/transfer_functions/cineon.py | 18 +- .../models/rgb/transfer_functions/common.py | 47 ++- .../davinci_intermediate.py | 14 +- colour/models/rgb/transfer_functions/dcdm.py | 34 +- .../rgb/transfer_functions/dicom_gsdf.py | 28 +- .../rgb/transfer_functions/dji_d_log.py | 10 +- .../models/rgb/transfer_functions/exponent.py | 35 +-- .../rgb/transfer_functions/filmic_pro.py | 12 +- .../rgb/transfer_functions/filmlight_t_log.py | 26 +- .../rgb/transfer_functions/fujifilm_f_log.py | 30 +- colour/models/rgb/transfer_functions/gamma.py | 12 +- colour/models/rgb/transfer_functions/gopro.py | 10 +- .../rgb/transfer_functions/itur_bt_1361.py | 4 +- .../rgb/transfer_functions/itur_bt_1886.py | 14 +- .../rgb/transfer_functions/itur_bt_2020.py | 18 +- .../rgb/transfer_functions/itur_bt_2100.py | 194 ++++++------ .../rgb/transfer_functions/itur_bt_601.py | 10 +- .../rgb/transfer_functions/itur_bt_709.py | 10 +- .../rgb/transfer_functions/itut_h_273.py | 16 +- .../rgb/transfer_functions/leica_l_log.py | 30 +- .../models/rgb/transfer_functions/linear.py | 6 +- colour/models/rgb/transfer_functions/log.py | 76 +++-- .../rgb/transfer_functions/nikon_n_log.py | 30 +- .../models/rgb/transfer_functions/panalog.py | 18 +- .../rgb/transfer_functions/panasonic_v_log.py | 30 +- .../rgb/transfer_functions/pivoted_log.py | 30 +- colour/models/rgb/transfer_functions/red.py | 78 ++--- .../rgb/transfer_functions/rimm_romm_rgb.py | 114 ++++--- .../rgb/transfer_functions/smpte_240m.py | 10 +- colour/models/rgb/transfer_functions/sony.py | 78 +++-- colour/models/rgb/transfer_functions/srgb.py | 10 +- .../models/rgb/transfer_functions/st_2084.py | 18 +- .../rgb/transfer_functions/viper_log.py | 10 +- colour/models/rgb/ycbcr.py | 146 ++++----- colour/models/rgb/ycocg.py | 10 +- colour/notation/datasets/munsell/all.py | 4 +- .../notation/datasets/munsell/experimental.py | 4 +- colour/notation/datasets/munsell/real.py | 4 +- colour/notation/hexadecimal.py | 12 +- colour/notation/munsell.py | 217 +++++++------ colour/notation/tests/test_munsell.py | 26 +- colour/phenomena/rayleigh.py | 123 ++++---- colour/phenomena/tests/test_rayleigh.py | 3 +- colour/plotting/blindness.py | 9 +- colour/plotting/characterisation.py | 8 +- colour/plotting/colorimetry.py | 87 +++--- colour/plotting/common.py | 134 ++++---- colour/plotting/corresponding.py | 10 +- colour/plotting/datasets/astm_g_173.py | 7 +- colour/plotting/diagrams.py | 230 +++++++------- colour/plotting/graph.py | 2 +- colour/plotting/models.py | 186 ++++++----- colour/plotting/notation.py | 10 +- colour/plotting/phenomena.py | 29 +- colour/plotting/quality.py | 40 +-- colour/plotting/section.py | 70 ++--- colour/plotting/temperature.py | 54 ++-- colour/plotting/tm3018/components.py | 45 ++- colour/plotting/tm3018/report.py | 54 ++-- colour/plotting/volume.py | 62 ++-- colour/quality/__init__.py | 6 +- colour/quality/cfi2017.py | 61 ++-- colour/quality/cqs.py | 109 +++---- colour/quality/cri.py | 50 ++- colour/quality/datasets/tcs.py | 5 +- colour/quality/datasets/vs.py | 5 +- colour/quality/ssi.py | 15 +- colour/quality/tests/test_cfi2017.py | 5 +- colour/quality/tests/test_cri.py | 3 +- colour/quality/tests/test_ssi.py | 3 +- colour/quality/tm3018.py | 63 ++-- colour/recovery/__init__.py | 2 +- colour/recovery/datasets/dyer2017.py | 4 +- colour/recovery/datasets/mallett2019.py | 4 +- colour/recovery/datasets/otsu2018.py | 10 +- colour/recovery/datasets/smits1999.py | 3 +- colour/recovery/jakob2019.py | 90 +++--- colour/recovery/jiang2013.py | 24 +- colour/recovery/mallett2019.py | 6 +- colour/recovery/meng2015.py | 10 +- colour/recovery/otsu2018.py | 176 +++++------ colour/recovery/smits1999.py | 10 +- colour/recovery/tests/test_jakob2019.py | 24 +- colour/temperature/__init__.py | 16 +- colour/temperature/cie_d.py | 19 +- colour/temperature/hernandez1999.py | 17 +- colour/temperature/kang2002.py | 21 +- colour/temperature/krystek1985.py | 21 +- colour/temperature/mccamy1992.py | 17 +- colour/temperature/ohno2013.py | 35 +-- colour/temperature/planck1900.py | 23 +- colour/temperature/robertson1968.py | 23 +- .../temperature/tests/test_robertson1968.py | 3 +- colour/utilities/__init__.py | 6 +- colour/utilities/array.py | 208 ++++++------ colour/utilities/common.py | 67 ++-- colour/utilities/data_structures.py | 73 +++-- colour/utilities/deprecation.py | 10 +- colour/utilities/documentation.py | 4 +- colour/utilities/metrics.py | 16 +- colour/utilities/tests/test_array.py | 2 +- colour/utilities/tests/test_common.py | 8 +- colour/utilities/tests/test_deprecated.py | 2 +- colour/utilities/verbose.py | 36 +-- .../volume/datasets/optimal_colour_stimuli.py | 14 +- colour/volume/macadam_limits.py | 14 +- colour/volume/mesh.py | 6 +- colour/volume/pointer_gamut.py | 6 +- colour/volume/rgb.py | 41 ++- colour/volume/spectrum.py | 24 +- docs/colour.hints.rst | 53 ++-- docs/conf.py | 26 +- pyproject.toml | 20 +- requirements.txt | 28 +- tasks.py | 35 +-- utilities/generate_plots.py | 10 +- 325 files changed, 5119 insertions(+), 5436 deletions(-) diff --git a/.github/workflows/continuous-integration-static-type-checking.yml b/.github/workflows/continuous-integration-static-type-checking.yml index af810d5e4c..269467af6b 100644 --- a/.github/workflows/continuous-integration-static-type-checking.yml +++ b/.github/workflows/continuous-integration-static-type-checking.yml @@ -32,4 +32,4 @@ jobs: pip install -r requirements.txt - name: Static Type Checking run: | - mypy --install-types --non-interactive --show-error-codes --warn-unused-ignores --warn-redundant-casts $CI_PACKAGE + pyright --skipunannotated diff --git a/colour/__init__.py b/colour/__init__.py index 627bc48d47..31e74000c5 100644 --- a/colour/__init__.py +++ b/colour/__init__.py @@ -904,12 +904,12 @@ def __getattr__(self, attribute) -> Any: return super().__getattr__(attribute) -colour.__application_name__ = __application_name__ # type: ignore[attr-defined] +colour.__application_name__ = __application_name__ # pyright: ignore -colour.__major_version__ = __major_version__ # type: ignore[attr-defined] -colour.__minor_version__ = __minor_version__ # type: ignore[attr-defined] -colour.__change_version__ = __change_version__ # type: ignore[attr-defined] -colour.__version__ = __version__ # type: ignore[attr-defined] +colour.__major_version__ = __major_version__ # pyright: ignore +colour.__minor_version__ = __minor_version__ # pyright: ignore +colour.__change_version__ = __change_version__ # pyright: ignore +colour.__version__ = __version__ # pyright: ignore # v0.4.0 API_CHANGES = { @@ -943,14 +943,14 @@ def __getattr__(self, attribute) -> Any: """Defines the *colour.models* sub-package API changes.""" if not is_documentation_building(): - sys.modules["colour"] = colour( # type: ignore[assignment] + sys.modules["colour"] = colour( # pyright: ignore sys.modules["colour"], build_API_changes(API_CHANGES) ) del ModuleAPI, is_documentation_building, build_API_changes, sys -colour.__disable_lazy_load__ = True # type: ignore[attr-defined] -__disable_lazy_load__ = colour.__disable_lazy_load__ # type: ignore[attr-defined] +colour.__disable_lazy_load__ = True # pyright: ignore +__disable_lazy_load__ = colour.__disable_lazy_load__ # pyright: ignore """ Ensures that the lazy loaded datasets are not transformed during import. See :class:`colour.utilities.LazyCanonicalMapping` for more information. diff --git a/colour/adaptation/__init__.py b/colour/adaptation/__init__.py index 820188e628..9728b6ba5e 100644 --- a/colour/adaptation/__init__.py +++ b/colour/adaptation/__init__.py @@ -26,7 +26,7 @@ from __future__ import annotations -from colour.hints import Any, ArrayLike, Literal, NDArray, Union +from colour.hints import Any, ArrayLike, Literal, NDArrayFloat, Union from colour.utilities import ( CanonicalMapping, filter_kwargs, @@ -136,7 +136,7 @@ def chromatic_adaptation( str, ] = "Von Kries", **kwargs: Any, -) -> NDArray: +) -> NDArrayFloat: """ Adapt given stimulus from test viewing conditions to reference viewing conditions. diff --git a/colour/adaptation/cie1994.py b/colour/adaptation/cie1994.py index 6ac29168a1..555f4f513f 100644 --- a/colour/adaptation/cie1994.py +++ b/colour/adaptation/cie1994.py @@ -22,9 +22,7 @@ from colour.adaptation import CAT_VON_KRIES from colour.hints import ( ArrayLike, - FloatingOrArrayLike, - FloatingOrNDArray, - NDArray, + NDArrayFloat, ) from colour.utilities import ( as_float_array, @@ -57,13 +55,15 @@ "corresponding_colour", ] -MATRIX_XYZ_TO_RGB_CIE1994: NDArray = CAT_VON_KRIES +MATRIX_XYZ_TO_RGB_CIE1994: NDArrayFloat = CAT_VON_KRIES """ *CIE 1994* colour appearance model *CIE XYZ* tristimulus values to cone responses matrix. """ -MATRIX_RGB_TO_XYZ_CIE1994: NDArray = np.linalg.inv(MATRIX_XYZ_TO_RGB_CIE1994) +MATRIX_RGB_TO_XYZ_CIE1994: NDArrayFloat = np.linalg.inv( + MATRIX_XYZ_TO_RGB_CIE1994 +) """ *CIE 1994* colour appearance model cone responses to *CIE XYZ* tristimulus values matrix. @@ -74,11 +74,11 @@ def chromatic_adaptation_CIE1994( XYZ_1: ArrayLike, xy_o1: ArrayLike, xy_o2: ArrayLike, - Y_o: FloatingOrArrayLike, - E_o1: FloatingOrArrayLike, - E_o2: FloatingOrArrayLike, - n: FloatingOrArrayLike = 1, -) -> NDArray: + Y_o: ArrayLike, + E_o1: ArrayLike, + E_o2: ArrayLike, + n: ArrayLike = 1, +) -> NDArrayFloat: """ Adapt given stimulus *CIE XYZ_1* tristimulus values from test viewing conditions to reference viewing conditions using *CIE 1994* chromatic @@ -174,7 +174,7 @@ def chromatic_adaptation_CIE1994( return from_range_100(XYZ_2) -def XYZ_to_RGB_CIE1994(XYZ: ArrayLike) -> NDArray: +def XYZ_to_RGB_CIE1994(XYZ: ArrayLike) -> NDArrayFloat: """ Convert from *CIE XYZ* tristimulus values to cone responses. @@ -198,7 +198,7 @@ def XYZ_to_RGB_CIE1994(XYZ: ArrayLike) -> NDArray: return vector_dot(MATRIX_XYZ_TO_RGB_CIE1994, XYZ) -def RGB_to_XYZ_CIE1994(RGB: ArrayLike) -> NDArray: +def RGB_to_XYZ_CIE1994(RGB: ArrayLike) -> NDArrayFloat: """ Convert from cone responses to *CIE XYZ* tristimulus values. @@ -222,7 +222,7 @@ def RGB_to_XYZ_CIE1994(RGB: ArrayLike) -> NDArray: return vector_dot(MATRIX_RGB_TO_XYZ_CIE1994, RGB) -def intermediate_values(xy_o: ArrayLike) -> NDArray: +def intermediate_values(xy_o: ArrayLike) -> NDArrayFloat: """ Return the intermediate values :math:`\\xi`, :math:`\\eta`, :math:`\\zeta`. @@ -257,8 +257,8 @@ def intermediate_values(xy_o: ArrayLike) -> NDArray: def effective_adapting_responses( - xez: ArrayLike, Y_o: FloatingOrArrayLike, E_o: FloatingOrArrayLike -) -> NDArray: + xez: ArrayLike, Y_o: ArrayLike, E_o: ArrayLike +) -> NDArrayFloat: """ Derive the effective adapting responses in the fundamental primary system of the test or reference field. @@ -296,7 +296,7 @@ def effective_adapting_responses( return RGB_o -def beta_1(x: FloatingOrArrayLike) -> FloatingOrNDArray: +def beta_1(x: ArrayLike) -> NDArrayFloat: """ Compute the exponent :math:`\\beta_1` for the middle and long-wavelength sensitive cones. @@ -308,7 +308,7 @@ def beta_1(x: FloatingOrArrayLike) -> FloatingOrNDArray: Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Exponent :math:`\\beta_1`. Examples @@ -322,7 +322,7 @@ def beta_1(x: FloatingOrArrayLike) -> FloatingOrNDArray: return (6.469 + 6.362 * x_p) / (6.469 + x_p) -def beta_2(x: FloatingOrArrayLike) -> FloatingOrNDArray: +def beta_2(x: ArrayLike) -> NDArrayFloat: """ Compute the exponent :math:`\\beta_2` for the short-wavelength sensitive cones. @@ -334,7 +334,7 @@ def beta_2(x: FloatingOrArrayLike) -> FloatingOrNDArray: Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Exponent :math:`\\beta_2`. Examples @@ -348,7 +348,7 @@ def beta_2(x: FloatingOrArrayLike) -> FloatingOrNDArray: return 0.7844 * (8.414 + 8.091 * x_p) / (8.414 + x_p) -def exponential_factors(RGB_o: ArrayLike) -> NDArray: +def exponential_factors(RGB_o: ArrayLike) -> NDArrayFloat: """ Return the chromatic adaptation exponential factors :math:`\\beta_1(R_o)`, :math:`\\beta_1(G_o)` and :math:`\\beta_2(B_o)` of given cone responses. @@ -387,9 +387,9 @@ def K_coefficient( xez_2: ArrayLike, bRGB_o1: ArrayLike, bRGB_o2: ArrayLike, - Y_o: FloatingOrArrayLike, - n: FloatingOrArrayLike = 1, -) -> FloatingOrNDArray: + Y_o: ArrayLike, + n: ArrayLike = 1, +) -> NDArrayFloat: """ Compute the coefficient :math:`K` for correcting the difference between the test and references illuminances. @@ -417,7 +417,7 @@ def K_coefficient( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Coefficient :math:`K`. Examples @@ -455,10 +455,10 @@ def corresponding_colour( xez_2: ArrayLike, bRGB_o1: ArrayLike, bRGB_o2: ArrayLike, - Y_o: FloatingOrArrayLike, - K: FloatingOrArrayLike, - n: FloatingOrArrayLike = 1, -) -> NDArray: + Y_o: ArrayLike, + K: ArrayLike, + n: ArrayLike = 1, +) -> NDArrayFloat: """ Compute the corresponding colour cone responses of given test sample cone responses :math:`RGB_1`. @@ -518,13 +518,13 @@ def corresponding_colour( n = as_float_array(n) def RGB_c( - x_1: NDArray, - x_2: NDArray, - y_1: NDArray, - y_2: NDArray, - z: NDArray, - n: NDArray, - ) -> NDArray: + x_1: NDArrayFloat, + x_2: NDArrayFloat, + y_1: NDArrayFloat, + y_2: NDArrayFloat, + z: NDArrayFloat, + n: NDArrayFloat, + ) -> NDArrayFloat: """Compute the corresponding colour cone responses component.""" with sdiv_mode(): diff --git a/colour/adaptation/cmccat2000.py b/colour/adaptation/cmccat2000.py index edb68fd380..827c793785 100644 --- a/colour/adaptation/cmccat2000.py +++ b/colour/adaptation/cmccat2000.py @@ -29,10 +29,8 @@ from colour.algebra import vector_dot from colour.hints import ( ArrayLike, - Floating, - FloatingOrArrayLike, Literal, - NDArray, + NDArrayFloat, Union, ) from colour.utilities import ( @@ -59,7 +57,7 @@ "chromatic_adaptation_CMCCAT2000", ] -CAT_INVERSE_CMCCAT2000: NDArray = np.linalg.inv(CAT_CMCCAT2000) +CAT_INVERSE_CMCCAT2000: NDArrayFloat = np.linalg.inv(CAT_CMCCAT2000) """ Inverse *CMCCAT2000* chromatic adaptation transform. @@ -81,7 +79,7 @@ class InductionFactors_CMCCAT2000(NamedTuple): :cite:`Li2002a`, :cite:`Westland2012k` """ - F: Floating + F: float VIEWING_CONDITIONS_CMCCAT2000: CanonicalMapping = CanonicalMapping( @@ -104,12 +102,12 @@ def chromatic_adaptation_forward_CMCCAT2000( XYZ: ArrayLike, XYZ_w: ArrayLike, XYZ_wr: ArrayLike, - L_A1: FloatingOrArrayLike, - L_A2: FloatingOrArrayLike, + L_A1: ArrayLike, + L_A2: ArrayLike, surround: InductionFactors_CMCCAT2000 = VIEWING_CONDITIONS_CMCCAT2000[ "Average" ], -) -> NDArray: +) -> NDArrayFloat: """ Adapt given stimulus *CIE XYZ* tristimulus values from test viewing conditions to reference viewing conditions using *CMCCAT2000* forward @@ -199,12 +197,12 @@ def chromatic_adaptation_inverse_CMCCAT2000( XYZ_c: ArrayLike, XYZ_w: ArrayLike, XYZ_wr: ArrayLike, - L_A1: FloatingOrArrayLike, - L_A2: FloatingOrArrayLike, + L_A1: ArrayLike, + L_A2: ArrayLike, surround: InductionFactors_CMCCAT2000 = VIEWING_CONDITIONS_CMCCAT2000[ "Average" ], -) -> NDArray: +) -> NDArrayFloat: """ Adapt given stimulus corresponding colour *CIE XYZ* tristimulus values from reference viewing conditions to test viewing conditions using @@ -296,13 +294,13 @@ def chromatic_adaptation_CMCCAT2000( XYZ: ArrayLike, XYZ_w: ArrayLike, XYZ_wr: ArrayLike, - L_A1: FloatingOrArrayLike, - L_A2: FloatingOrArrayLike, + L_A1: ArrayLike, + L_A2: ArrayLike, surround: InductionFactors_CMCCAT2000 = VIEWING_CONDITIONS_CMCCAT2000[ "Average" ], direction: Union[Literal["Forward", "Inverse"], str] = "Forward", -) -> NDArray: +) -> NDArrayFloat: """ Adapt given stimulus *CIE XYZ* tristimulus values using given viewing conditions. diff --git a/colour/adaptation/datasets/cat.py b/colour/adaptation/datasets/cat.py index 850e4b0098..e40e70aa04 100644 --- a/colour/adaptation/datasets/cat.py +++ b/colour/adaptation/datasets/cat.py @@ -75,7 +75,7 @@ import numpy as np -from colour.hints import NDArray +from colour.hints import NDArrayFloat from colour.utilities import CanonicalMapping __author__ = "Colour Developers" @@ -101,7 +101,7 @@ "CHROMATIC_ADAPTATION_TRANSFORMS", ] -CAT_XYZ_SCALING: NDArray = np.array(np.identity(3)).reshape([3, 3]) +CAT_XYZ_SCALING: NDArrayFloat = np.array(np.identity(3)).reshape([3, 3]) """ *XYZ Scaling* chromatic adaptation transform. @@ -110,7 +110,7 @@ :cite:`Lindbloom2009g` """ -CAT_VON_KRIES: NDArray = np.array( +CAT_VON_KRIES: NDArrayFloat = np.array( [ [0.4002400, 0.7076000, -0.0808100], [-0.2263000, 1.1653200, 0.0457000], @@ -126,7 +126,7 @@ :cite:`Nayatani1995a` """ -CAT_BRADFORD: NDArray = np.array( +CAT_BRADFORD: NDArrayFloat = np.array( [ [0.8951000, 0.2664000, -0.1614000], [-0.7502000, 1.7135000, 0.0367000], @@ -141,7 +141,7 @@ :cite:`Lindbloom2009g` """ -CAT_SHARP: NDArray = np.array( +CAT_SHARP: NDArrayFloat = np.array( [ [1.2694, -0.0988, -0.1706], [-0.8364, 1.8006, 0.0357], @@ -156,7 +156,7 @@ :cite:`Bianco2010a` """ -CAT_FAIRCHILD: NDArray = np.array( +CAT_FAIRCHILD: NDArrayFloat = np.array( [ [0.8562, 0.3372, -0.1934], [-0.8360, 1.8327, 0.0033], @@ -171,7 +171,7 @@ :cite:`Fairchildb` """ -CAT_CMCCAT97: NDArray = np.array( +CAT_CMCCAT97: NDArrayFloat = np.array( [ [0.8951, -0.7502, 0.0389], [0.2664, 1.7135, 0.0685], @@ -186,7 +186,7 @@ :cite:`Westland2012g` """ -CAT_CMCCAT2000: NDArray = np.array( +CAT_CMCCAT2000: NDArrayFloat = np.array( [ [0.7982, 0.3389, -0.1371], [-0.5918, 1.5512, 0.0406], @@ -201,7 +201,7 @@ :cite:`Westland2012k` """ -CAT_CAT02: NDArray = np.array( +CAT_CAT02: NDArrayFloat = np.array( [ [0.7328, 0.4296, -0.1624], [-0.7036, 1.6975, 0.0061], @@ -216,7 +216,7 @@ :cite:`Wikipedia2007` """ -CAT_CAT02_BRILL2008: NDArray = np.array( +CAT_CAT02_BRILL2008: NDArrayFloat = np.array( [ [0.7328, 0.4296, -0.1624], [-0.7036, 1.6975, 0.0061], @@ -232,7 +232,7 @@ :cite:`Brill2008a`, :cite:`Li2007e` """ -CAT_CAT16: NDArray = np.array( +CAT_CAT16: NDArrayFloat = np.array( [ [0.401288, 0.650173, -0.051461], [-0.250268, 1.204414, 0.045854], @@ -247,7 +247,7 @@ :cite:`Li2017` """ -CAT_BIANCO2010: NDArray = np.array( +CAT_BIANCO2010: NDArrayFloat = np.array( [ [0.8752, 0.2787, -0.1539], [-0.8904, 1.8709, 0.0195], @@ -262,7 +262,7 @@ :cite:`Bianco2010a` """ -CAT_PC_BIANCO2010: NDArray = np.array( +CAT_PC_BIANCO2010: NDArrayFloat = np.array( [ [0.6489, 0.3915, -0.0404], [-0.3775, 1.3055, 0.0720], diff --git a/colour/adaptation/fairchild1990.py b/colour/adaptation/fairchild1990.py index e45e6cf0d8..0cb6fd8fd7 100644 --- a/colour/adaptation/fairchild1990.py +++ b/colour/adaptation/fairchild1990.py @@ -21,14 +21,7 @@ from colour.algebra import sdiv, sdiv_mode, spow, vector_dot from colour.adaptation import CAT_VON_KRIES -from colour.hints import ( - ArrayLike, - Boolean, - FloatingOrArrayLike, - FloatingOrNDArray, - NDArray, - cast, -) +from colour.hints import ArrayLike, NDArrayFloat from colour.utilities import ( as_float_array, from_range_100, @@ -54,13 +47,13 @@ "degrees_of_adaptation", ] -MATRIX_XYZ_TO_RGB_FAIRCHILD1990: NDArray = CAT_VON_KRIES +MATRIX_XYZ_TO_RGB_FAIRCHILD1990: NDArrayFloat = CAT_VON_KRIES """ *Fairchild (1990)* colour appearance model *CIE XYZ* tristimulus values to cone responses matrix. """ -MATRIX_RGB_TO_XYZ_FAIRCHILD1990: NDArray = np.linalg.inv(CAT_VON_KRIES) +MATRIX_RGB_TO_XYZ_FAIRCHILD1990: NDArrayFloat = np.linalg.inv(CAT_VON_KRIES) """ *Fairchild (1990)* colour appearance model cone responses to *CIE XYZ* tristimulus values matrix. @@ -71,9 +64,9 @@ def chromatic_adaptation_Fairchild1990( XYZ_1: ArrayLike, XYZ_n: ArrayLike, XYZ_r: ArrayLike, - Y_n: FloatingOrArrayLike, - discount_illuminant: Boolean = False, -) -> NDArray: + Y_n: ArrayLike, + discount_illuminant: bool = False, +) -> NDArrayFloat: """ Adapt given stimulus *CIE XYZ_1* tristimulus values from test viewing conditions to reference viewing conditions using *Fairchild (1990)* @@ -164,7 +157,7 @@ def chromatic_adaptation_Fairchild1990( return from_range_100(XYZ_c) -def XYZ_to_RGB_Fairchild1990(XYZ: ArrayLike) -> NDArray: +def XYZ_to_RGB_Fairchild1990(XYZ: ArrayLike) -> NDArrayFloat: """ Convert from *CIE XYZ* tristimulus values to cone responses. @@ -188,7 +181,7 @@ def XYZ_to_RGB_Fairchild1990(XYZ: ArrayLike) -> NDArray: return vector_dot(MATRIX_XYZ_TO_RGB_FAIRCHILD1990, XYZ) -def RGB_to_XYZ_Fairchild1990(RGB: ArrayLike) -> NDArray: +def RGB_to_XYZ_Fairchild1990(RGB: ArrayLike) -> NDArrayFloat: """ Convert from cone responses to *CIE XYZ* tristimulus values. @@ -214,10 +207,10 @@ def RGB_to_XYZ_Fairchild1990(RGB: ArrayLike) -> NDArray: def degrees_of_adaptation( LMS: ArrayLike, - Y_n: FloatingOrArrayLike, - v: FloatingOrArrayLike = 1 / 3, - discount_illuminant: Boolean = False, -) -> NDArray: + Y_n: ArrayLike, + v: ArrayLike = 1 / 3, + discount_illuminant: bool = False, +) -> NDArrayFloat: """ Compute the degrees of adaptation :math:`p_L`, :math:`p_M` and :math:`p_S`. @@ -258,14 +251,14 @@ def degrees_of_adaptation( # E illuminant. LMS_E = vector_dot(CAT_VON_KRIES, ones(LMS.shape)) - Ye_n = cast(NDArray, spow(Y_n, v)) + Ye_n = spow(Y_n, v) - def m_E(x: FloatingOrNDArray, y: FloatingOrNDArray) -> FloatingOrNDArray: + def m_E(x: NDArrayFloat, y: NDArrayFloat) -> NDArrayFloat: """Compute the :math:`m_E` term.""" return (3 * x / y) / np.sum(x / y, axis=-1)[..., None] - def P_c(x: FloatingOrNDArray) -> FloatingOrNDArray: + def P_c(x: NDArrayFloat) -> NDArrayFloat: """Compute the :math:`P_L`, :math:`P_M` or :math:`P_S` terms.""" return sdiv( @@ -274,6 +267,6 @@ def P_c(x: FloatingOrNDArray) -> FloatingOrNDArray: ) with sdiv_mode(): - p_LMS = cast(NDArray, P_c(m_E(LMS, LMS_E))) + p_LMS = P_c(m_E(LMS, LMS_E)) return p_LMS diff --git a/colour/adaptation/vonkries.py b/colour/adaptation/vonkries.py index b591f967a2..4fe5c2b7dc 100644 --- a/colour/adaptation/vonkries.py +++ b/colour/adaptation/vonkries.py @@ -20,7 +20,7 @@ from colour.adaptation import CHROMATIC_ADAPTATION_TRANSFORMS from colour.algebra import matrix_dot, vector_dot, sdiv, sdiv_mode -from colour.hints import ArrayLike, Literal, NDArray, Union +from colour.hints import ArrayLike, Literal, NDArrayFloat, Union from colour.utilities import ( from_range_1, row_as_diagonal, @@ -61,7 +61,7 @@ def matrix_chromatic_adaptation_VonKries( ], str, ] = "CAT02", -) -> NDArray: +) -> NDArrayFloat: """ Compute the *chromatic adaptation* matrix from test viewing conditions to reference viewing conditions. @@ -164,7 +164,7 @@ def chromatic_adaptation_VonKries( ], str, ] = "CAT02", -) -> NDArray: +) -> NDArrayFloat: """ Adapt given stimulus from test viewing conditions to reference viewing conditions. diff --git a/colour/adaptation/zhai2018.py b/colour/adaptation/zhai2018.py index 668ad34bbe..e3a1ca91e4 100644 --- a/colour/adaptation/zhai2018.py +++ b/colour/adaptation/zhai2018.py @@ -17,13 +17,7 @@ from colour.algebra import vector_dot from colour.adaptation import CHROMATIC_ADAPTATION_TRANSFORMS -from colour.hints import ( - ArrayLike, - FloatingOrArrayLike, - Literal, - NDArray, - Union, -) +from colour.hints import ArrayLike, Literal, NDArrayFloat, Union from colour.utilities import ( as_float_array, from_range_100, @@ -47,11 +41,11 @@ def chromatic_adaptation_Zhai2018( XYZ_b: ArrayLike, XYZ_wb: ArrayLike, XYZ_wd: ArrayLike, - D_b: FloatingOrArrayLike = 1, - D_d: FloatingOrArrayLike = 1, + D_b: ArrayLike = 1, + D_d: ArrayLike = 1, XYZ_wo: ArrayLike = np.array([1, 1, 1]), transform: Union[Literal["CAT02", "CAT16"], str] = "CAT02", -) -> NDArray: +) -> NDArrayFloat: """ Adapt given sample colour :math:`XYZ_{\\beta}` tristimulus values from input viewing conditions under :math:`\\beta` illuminant to output viewing diff --git a/colour/algebra/__init__.py b/colour/algebra/__init__.py index 35a1b22650..107a3aa6df 100644 --- a/colour/algebra/__init__.py +++ b/colour/algebra/__init__.py @@ -164,7 +164,7 @@ def __getattr__(self, attribute) -> Any: """Defines the *colour.algebra* sub-package API changes.""" if not is_documentation_building(): - sys.modules["colour.algebra"] = algebra( # type: ignore[assignment] + sys.modules["colour.algebra"] = algebra( # pyright: ignore sys.modules["colour.algebra"], build_API_changes(API_CHANGES) ) diff --git a/colour/algebra/common.py b/colour/algebra/common.py index 97b0f5180d..8e0b2deb99 100644 --- a/colour/algebra/common.py +++ b/colour/algebra/common.py @@ -14,16 +14,10 @@ from colour.hints import ( Any, ArrayLike, - Boolean, Callable, - Floating, - FloatingOrArrayLike, - FloatingOrNDArray, - Integer, Literal, - NDArray, + NDArrayFloat, Optional, - Tuple, Union, cast, ) @@ -238,7 +232,7 @@ def wrapper(*args: Any, **kwargs: Any) -> Any: return wrapper -def sdiv(a: FloatingOrArrayLike, b: FloatingOrArrayLike) -> FloatingOrNDArray: +def sdiv(a: ArrayLike, b: ArrayLike) -> NDArrayFloat: """ Divide given array :math:`b` with array :math:`b` while handling zero-division. @@ -259,12 +253,12 @@ def sdiv(a: FloatingOrArrayLike, b: FloatingOrArrayLike) -> FloatingOrNDArray: :func:`numpy.nan_to_num` definition for more details. - ``Ignore Limit Conversion``: Zero-division occurs silently and NaNs or +/- infs values are converted to zeros or the largest +/- - finite floating point values representable by the division result + finite float point values representable by the division result :class:`numpy.dtype`. See :func:`numpy.nan_to_num` definition for more details. - ``Warning Limit Conversion``: Zero-division occurs with a warning and NaNs or +/- infs values are converted to zeros or the largest +/- - finite floating point values representable by the division result + finite float point values representable by the division result :class:`numpy.dtype`. Parameters @@ -276,7 +270,7 @@ def sdiv(a: FloatingOrArrayLike, b: FloatingOrArrayLike) -> FloatingOrNDArray: Returns ------- - :class:`np.floating` or :class:`numpy.ndarray` + :class:`np.float` or :class:`numpy.ndarray` Array :math:`b` safely divided by :math:`a`. Examples @@ -354,14 +348,14 @@ def sdiv(a: FloatingOrArrayLike, b: FloatingOrArrayLike) -> FloatingOrNDArray: return c -_SPOW_ENABLED: Boolean = True +_SPOW_ENABLED: bool = True """ Global variable storing the current *Colour* safe / symmetrical power function enabled state. """ -def is_spow_enabled() -> Boolean: +def is_spow_enabled() -> bool: """ Return whether *Colour* safe / symmetrical power function is enabled. @@ -385,7 +379,7 @@ def is_spow_enabled() -> Boolean: return _SPOW_ENABLED -def set_spow_enable(enable: Boolean): +def set_spow_enable(enable: bool): """ Set *Colour* safe / symmetrical power function enabled state. @@ -422,7 +416,7 @@ class spow_enable: function. """ - def __init__(self, enable: Boolean) -> None: + def __init__(self, enable: bool) -> None: self._enable = enable self._previous_state = is_spow_enabled() @@ -455,7 +449,7 @@ def wrapper(*args: Any, **kwargs: Any) -> Any: return wrapper -def spow(a: FloatingOrArrayLike, p: FloatingOrArrayLike) -> FloatingOrNDArray: +def spow(a: ArrayLike, p: ArrayLike) -> NDArrayFloat: """ Raise given array :math:`a` to the power :math:`p` as follows: :math:`sign(a) * |a|^p`. @@ -474,7 +468,7 @@ def spow(a: FloatingOrArrayLike, p: FloatingOrArrayLike) -> FloatingOrNDArray: Returns ------- - :class:`np.floating` or :class:`numpy.ndarray` + :class:`np.float` or :class:`numpy.ndarray` Array :math:`a` safely raised to the power :math:`p`. Examples @@ -500,7 +494,7 @@ def spow(a: FloatingOrArrayLike, p: FloatingOrArrayLike) -> FloatingOrNDArray: return as_float(a_p) -def normalise_vector(a: FloatingOrArrayLike) -> FloatingOrNDArray: +def normalise_vector(a: ArrayLike) -> NDArrayFloat: """ Normalise given vector :math:`a`. @@ -529,10 +523,10 @@ def normalise_vector(a: FloatingOrArrayLike) -> FloatingOrNDArray: def normalise_maximum( a: ArrayLike, - axis: Optional[Integer] = None, - factor: Floating = 1, - clip: Boolean = True, -) -> NDArray: + axis: Optional[int] = None, + factor: float = 1, + clip: bool = True, +) -> NDArrayFloat: """ Normalise given array :math:`a` values by :math:`a` maximum value and optionally clip them between. @@ -570,7 +564,7 @@ def normalise_maximum( return np.clip(a, 0, factor) if clip else a -def vector_dot(m: ArrayLike, v: ArrayLike) -> NDArray: +def vector_dot(m: ArrayLike, v: ArrayLike) -> NDArrayFloat: """ Perform the dot product of the matrix array :math:`m` with the vector array :math:`v`. @@ -614,7 +608,7 @@ def vector_dot(m: ArrayLike, v: ArrayLike) -> NDArray: return np.einsum("...ij,...j->...i", as_float_array(m), as_float_array(v)) -def matrix_dot(a: ArrayLike, b: ArrayLike) -> NDArray: +def matrix_dot(a: ArrayLike, b: ArrayLike) -> NDArrayFloat: """ Perform the dot product of the matrix array :math:`a` with the matrix array :math:`b`. @@ -675,7 +669,7 @@ def matrix_dot(a: ArrayLike, b: ArrayLike) -> NDArray: ) -def euclidean_distance(a: ArrayLike, b: ArrayLike) -> FloatingOrNDArray: +def euclidean_distance(a: ArrayLike, b: ArrayLike) -> NDArrayFloat: """ Return the *Euclidean* distance between point array :math:`a` and point array :math:`b`. @@ -693,7 +687,7 @@ def euclidean_distance(a: ArrayLike, b: ArrayLike) -> FloatingOrNDArray: Returns ------- - :class:`np.floating` or :class:`numpy.ndarray` + :class:`np.float` or :class:`numpy.ndarray` *Euclidean* distance. Examples @@ -709,7 +703,7 @@ def euclidean_distance(a: ArrayLike, b: ArrayLike) -> FloatingOrNDArray: ) -def manhattan_distance(a: ArrayLike, b: ArrayLike) -> FloatingOrNDArray: +def manhattan_distance(a: ArrayLike, b: ArrayLike) -> NDArrayFloat: """ Return the *Manhattan* (or *City-Block*) distance between point array :math:`a` and point array :math:`b`. @@ -727,7 +721,7 @@ def manhattan_distance(a: ArrayLike, b: ArrayLike) -> FloatingOrNDArray: Returns ------- - :class:`np.floating` or :class:`numpy.ndarray` + :class:`np.float` or :class:`numpy.ndarray` *Manhattan* distance. Examples @@ -745,7 +739,7 @@ def manhattan_distance(a: ArrayLike, b: ArrayLike) -> FloatingOrNDArray: def linear_conversion( a: ArrayLike, old_range: ArrayLike, new_range: ArrayLike -) -> NDArray: +) -> NDArrayFloat: """ Perform a simple linear conversion of given array :math:`a` between the old and new ranges. @@ -780,11 +774,11 @@ def linear_conversion( def linstep_function( - x: FloatingOrArrayLike, - a: FloatingOrArrayLike = 0, - b: FloatingOrArrayLike = 1, - clip: Boolean = False, -) -> NDArray: + x: ArrayLike, + a: ArrayLike = 0, + b: ArrayLike = 1, + clip: bool = False, +) -> NDArrayFloat: """ Perform a simple linear interpolation between given array :math:`a` and array :math:`b` using :math:`x` array. @@ -827,11 +821,11 @@ def linstep_function( def smoothstep_function( - x: FloatingOrArrayLike, - a: FloatingOrArrayLike = 0, - b: FloatingOrArrayLike = 1, - clip: Boolean = False, -) -> NDArray: + x: ArrayLike, + a: ArrayLike = 0, + b: ArrayLike = 1, + clip: bool = False, +) -> NDArrayFloat: """ Evaluate the *smoothstep* sigmoid-like function on array :math:`x`. @@ -870,7 +864,7 @@ def smoothstep_function( smooth = smoothstep_function -def is_identity(a: ArrayLike) -> Boolean: +def is_identity(a: ArrayLike) -> bool: """ Return whether :math:`a` array is an identity matrix. @@ -897,10 +891,10 @@ def is_identity(a: ArrayLike) -> Boolean: def eigen_decomposition( a: ArrayLike, - eigen_w_v_count: Optional[Integer] = None, - descending_order: Boolean = True, - covariance_matrix: Boolean = False, -) -> Tuple[NDArray, NDArray]: + eigen_w_v_count: Optional[int] = None, + descending_order: bool = True, + covariance_matrix: bool = False, +) -> tuple[NDArrayFloat, NDArrayFloat]: """ Return the eigen-values :math:`w` and eigen-vectors :math:`v` of given array :math:`a` in given order. @@ -923,7 +917,7 @@ def eigen_decomposition( Returns ------- :class:`tuple` - Tuple of eigen-values :math:`w` and eigen-vectors :math:`v`. The + tuple of eigen-values :math:`w` and eigen-vectors :math:`v`. The eigenv-alues are in given order, each repeated according to its multiplicity. The column ``v[:, i]`` is the normalized eigen-vector corresponding to the eige-nvalue ``w[i]``. diff --git a/colour/algebra/coordinates/transformations.py b/colour/algebra/coordinates/transformations.py index e1eac1fd68..248fd8e00d 100644 --- a/colour/algebra/coordinates/transformations.py +++ b/colour/algebra/coordinates/transformations.py @@ -23,7 +23,7 @@ ---------- - :cite:`Wikipedia2005a` : Wikipedia. (2005). ISO 31-11. Retrieved July 31, 2016, from https://en.wikipedia.org/wiki/ISO_31-11 -- :cite:`Wikipedia2006` : Wikipedia. (2006). List of common coordinate +- :cite:`Wikipedia2006` : Wikipedia. (2006). list of common coordinate transformations. Retrieved July 18, 2014, from http://en.wikipedia.org/wiki/List_of_common_coordinate_transformations """ @@ -33,7 +33,7 @@ import numpy as np from colour.algebra import sdiv, sdiv_mode -from colour.hints import ArrayLike, NDArray +from colour.hints import ArrayLike, NDArrayFloat from colour.utilities import as_float_array, tsplit, tstack __author__ = "Colour Developers" @@ -53,7 +53,7 @@ ] -def cartesian_to_spherical(a: ArrayLike) -> NDArray: +def cartesian_to_spherical(a: ArrayLike) -> NDArrayFloat: """ Transform given cartesian coordinates array :math:`xyz` to spherical coordinates array :math:`\\rho\\theta\\phi` (radial distance, inclination @@ -95,7 +95,7 @@ def cartesian_to_spherical(a: ArrayLike) -> NDArray: return rtp -def spherical_to_cartesian(a: ArrayLike) -> NDArray: +def spherical_to_cartesian(a: ArrayLike) -> NDArrayFloat: """ Transform given spherical coordinates array :math:`\\rho\\theta\\phi` (radial distance, inclination or elevation and azimuth) to cartesian @@ -136,7 +136,7 @@ def spherical_to_cartesian(a: ArrayLike) -> NDArray: return xyz -def cartesian_to_polar(a: ArrayLike) -> NDArray: +def cartesian_to_polar(a: ArrayLike) -> NDArrayFloat: """ Transform given cartesian coordinates array :math:`xy` to polar coordinates array :math:`\\rho\\phi` (radial coordinate, angular @@ -173,7 +173,7 @@ def cartesian_to_polar(a: ArrayLike) -> NDArray: return tstack([rho, phi]) -def polar_to_cartesian(a: ArrayLike) -> NDArray: +def polar_to_cartesian(a: ArrayLike) -> NDArrayFloat: """ Transform given polar coordinates array :math:`\\rho\\phi` (radial coordinate, angular coordinate) to cartesian coordinates array :math:`xy`. @@ -209,7 +209,7 @@ def polar_to_cartesian(a: ArrayLike) -> NDArray: return tstack([x, y]) -def cartesian_to_cylindrical(a: ArrayLike) -> NDArray: +def cartesian_to_cylindrical(a: ArrayLike) -> NDArrayFloat: """ Transform given cartesian coordinates array :math:`xyz` to cylindrical coordinates array :math:`\\rho\\phi z` (radial distance, azimuth and @@ -245,7 +245,7 @@ def cartesian_to_cylindrical(a: ArrayLike) -> NDArray: return tstack([rho, phi, a[..., -1]]) -def cylindrical_to_cartesian(a: ArrayLike) -> NDArray: +def cylindrical_to_cartesian(a: ArrayLike) -> NDArrayFloat: """ Transform given cylindrical coordinates array :math:`\\rho\\phi z` (radial distance, azimuth and height) to cartesian coordinates array diff --git a/colour/algebra/extrapolation.py b/colour/algebra/extrapolation.py index f0a5713b97..10bae93f1e 100644 --- a/colour/algebra/extrapolation.py +++ b/colour/algebra/extrapolation.py @@ -23,11 +23,11 @@ from colour.algebra import NullInterpolator, sdiv, sdiv_mode from colour.constants import DEFAULT_FLOAT_DTYPE from colour.hints import ( + Any, DTypeNumber, - FloatingOrArrayLike, - FloatingOrNDArray, + ArrayLike, Literal, - NDArray, + NDArrayFloat, Number, Optional, Type, @@ -143,8 +143,10 @@ def __init__( left: Optional[Number] = None, right: Optional[Number] = None, dtype: Optional[Type[DTypeNumber]] = None, + *args: Any, + **kwargs: Any, ) -> None: - dtype = cast(Type[DTypeNumber], optional(dtype, DEFAULT_FLOAT_DTYPE)) + dtype = optional(dtype, DEFAULT_FLOAT_DTYPE) self._interpolator: TypeInterpolator = NullInterpolator( np.array([-np.inf, np.inf]), np.array([-np.inf, np.inf]) @@ -286,7 +288,7 @@ def right(self, value: Optional[Number]): self._right = value - def __call__(self, x: FloatingOrArrayLike) -> FloatingOrNDArray: + def __call__(self, x: ArrayLike) -> NDArrayFloat: """ Evaluate the Extrapolator at given point(s). @@ -297,17 +299,17 @@ def __call__(self, x: FloatingOrArrayLike) -> FloatingOrNDArray: Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Extrapolated points value(s). """ - x = np.atleast_1d(x).astype(self._dtype) + x = cast(NDArrayFloat, np.atleast_1d(x).astype(self._dtype)) xe = as_float(self._evaluate(x)) return xe - def _evaluate(self, x: NDArray) -> NDArray: + def _evaluate(self, x: NDArrayFloat) -> NDArrayFloat: """ Perform the extrapolating evaluation at given points. diff --git a/colour/algebra/interpolation.py b/colour/algebra/interpolation.py index 6ca5f17c86..c64ea8c592 100644 --- a/colour/algebra/interpolation.py +++ b/colour/algebra/interpolation.py @@ -71,16 +71,10 @@ Any, ArrayLike, Callable, - Dict, DTypeNumber, - Floating, - FloatingOrArrayLike, - FloatingOrNDArray, - Integer, Literal, - NDArray, + NDArrayFloat, Optional, - Tuple, Type, Union, cast, @@ -130,7 +124,7 @@ ] -def kernel_nearest_neighbour(x: ArrayLike) -> NDArray: +def kernel_nearest_neighbour(x: ArrayLike) -> NDArrayFloat: """ Return the *nearest-neighbour* kernel evaluated at given samples. @@ -157,7 +151,7 @@ def kernel_nearest_neighbour(x: ArrayLike) -> NDArray: return np.where(np.abs(x) < 0.5, 1, 0) -def kernel_linear(x: ArrayLike) -> NDArray: +def kernel_linear(x: ArrayLike) -> NDArrayFloat: """ Return the *linear* kernel evaluated at given samples. @@ -187,7 +181,7 @@ def kernel_linear(x: ArrayLike) -> NDArray: return np.where(np.abs(x) < 1, 1 - np.abs(x), 0) -def kernel_sinc(x: ArrayLike, a: Floating = 3) -> NDArray: +def kernel_sinc(x: ArrayLike, a: float = 3) -> NDArrayFloat: """ Return the *sinc* kernel evaluated at given samples. @@ -223,7 +217,7 @@ def kernel_sinc(x: ArrayLike, a: Floating = 3) -> NDArray: return np.where(np.abs(x) < a, np.sinc(x), 0) -def kernel_lanczos(x: ArrayLike, a: Floating = 3) -> NDArray: +def kernel_lanczos(x: ArrayLike, a: float = 3) -> NDArrayFloat: """ Return the *lanczos* kernel evaluated at given samples. @@ -260,8 +254,8 @@ def kernel_lanczos(x: ArrayLike, a: Floating = 3) -> NDArray: def kernel_cardinal_spline( - x: ArrayLike, a: Floating = 0.5, b: Floating = 0.0 -) -> NDArray: + x: ArrayLike, a: float = 0.5, b: float = 0.0 +) -> NDArrayFloat: """ Return the *cardinal spline* kernel evaluated at given samples. @@ -404,32 +398,32 @@ def __init__( self, x: ArrayLike, y: ArrayLike, - window: Floating = 3, + window: float = 3, kernel: Callable = kernel_lanczos, - kernel_kwargs: Optional[Dict] = None, - padding_kwargs: Optional[Dict] = None, + kernel_kwargs: Optional[dict] = None, + padding_kwargs: Optional[dict] = None, dtype: Optional[Type[DTypeNumber]] = None, + *args: Any, + **kwargs: Any, ) -> None: - dtype = cast(Type[DTypeNumber], optional(dtype, DEFAULT_FLOAT_DTYPE)) + dtype = optional(dtype, DEFAULT_FLOAT_DTYPE) - self._x_p: NDArray = np.array([]) - self._y_p: NDArray = np.array([]) + self._x_p: NDArrayFloat = np.array([]) + self._y_p: NDArrayFloat = np.array([]) - self._x: NDArray = np.array([]) - self._y: NDArray = np.array([]) - self._window: Floating = 3 - self._padding_kwargs: Dict = { + self._x: NDArrayFloat = np.array([]) + self._y: NDArrayFloat = np.array([]) + self._window: float = 3 + self._padding_kwargs: dict = { "pad_width": (window, window), "mode": "reflect", } self._kernel: Callable = kernel_lanczos - self._kernel_kwargs: Dict = {} + self._kernel_kwargs: dict = {} self._dtype: Type[DTypeNumber] = dtype - # TODO: Remove pragma when https://github.com/python/mypy/issues/3004 - # is resolved. - self.x = x # type: ignore[assignment] - self.y = y # type: ignore[assignment] + self.x = x + self.y = y self.window = window self.padding_kwargs = optional(padding_kwargs, self._padding_kwargs) self.kernel = kernel @@ -438,7 +432,7 @@ def __init__( self._validate_dimensions() @property - def x(self) -> NDArray: + def x(self) -> NDArrayFloat: """ Getter and setter property for the independent :math:`x` variable. @@ -487,7 +481,7 @@ def x(self, value: ArrayLike): ) @property - def y(self) -> NDArray: + def y(self) -> NDArrayFloat: """ Getter and setter property for the dependent and already known :math:`y` variable. @@ -523,7 +517,7 @@ def y(self, value: ArrayLike): self._y_p = np.pad(self._y, **self._padding_kwargs) @property - def window(self) -> Floating: + def window(self) -> float: """ Getter and setter property for the window. @@ -534,14 +528,14 @@ def window(self) -> Floating: Returns ------- - :class:`numpy.floating` + :class:`float` Window. """ return self._window @window.setter - def window(self, value: Floating): + def window(self, value: float): """Setter for the **self.window** property.""" attest( @@ -588,7 +582,7 @@ def kernel(self, value: Callable): self._kernel = value @property - def kernel_kwargs(self) -> Dict: + def kernel_kwargs(self) -> dict: """ Getter and setter property for the kernel call time arguments. @@ -606,7 +600,7 @@ def kernel_kwargs(self) -> Dict: return self._kernel_kwargs @kernel_kwargs.setter - def kernel_kwargs(self, value: Dict): + def kernel_kwargs(self, value: dict): """Setter for the **self.kernel_kwargs** property.""" attest( @@ -617,7 +611,7 @@ def kernel_kwargs(self, value: Dict): self._kernel_kwargs = value @property - def padding_kwargs(self) -> Dict: + def padding_kwargs(self) -> dict: """ Getter and setter property for the kernel call time arguments. @@ -635,7 +629,7 @@ def padding_kwargs(self) -> Dict: return self._padding_kwargs @padding_kwargs.setter - def padding_kwargs(self, value: Dict): + def padding_kwargs(self, value: dict): """Setter for the **self.padding_kwargs** property.""" attest( @@ -649,7 +643,7 @@ def padding_kwargs(self, value: Dict): if self._y is not None: self.y = self._y - def __call__(self, x: FloatingOrArrayLike) -> FloatingOrNDArray: + def __call__(self, x: ArrayLike) -> NDArrayFloat: """ Evaluate the interpolator at given point(s). @@ -660,17 +654,17 @@ def __call__(self, x: FloatingOrArrayLike) -> FloatingOrNDArray: Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Interpolated value(s). """ - x = np.atleast_1d(x).astype(self._dtype) + x = cast(NDArrayFloat, np.atleast_1d(x).astype(self._dtype)) xi = as_float(self._evaluate(x)) return xi - def _evaluate(self, x: NDArray) -> NDArray: + def _evaluate(self, x: NDArrayFloat) -> NDArrayFloat: """ Perform the interpolator evaluation at given points. @@ -717,7 +711,7 @@ def _validate_dimensions(self): f'dimensions: "{len(self._x)}", "{len(self._y)}"' ) - def _validate_interpolation_range(self, x: NDArray): + def _validate_interpolation_range(self, x: NDArrayFloat): """Validate given point to be in interpolation range.""" below_interpolation_range = x < self._x[0] @@ -815,22 +809,22 @@ def __init__( x: ArrayLike, y: ArrayLike, dtype: Optional[Type[DTypeNumber]] = None, + *args: Any, + **kwargs: Any, ) -> None: - dtype = cast(Type[DTypeNumber], optional(dtype, DEFAULT_FLOAT_DTYPE)) + dtype = optional(dtype, DEFAULT_FLOAT_DTYPE) - self._x: NDArray = np.array([]) - self._y: NDArray = np.array([]) + self._x: NDArrayFloat = np.array([]) + self._y: NDArrayFloat = np.array([]) self._dtype: Type[DTypeNumber] = dtype - # TODO: Remove pragma when https://github.com/python/mypy/issues/3004 - # is resolved. - self.x = x # type: ignore[assignment] - self.y = y # type: ignore[assignment] + self.x = x + self.y = y self._validate_dimensions() @property - def x(self) -> NDArray: + def x(self) -> NDArrayFloat: """ Getter and setter property for the independent :math:`x` variable. @@ -851,7 +845,7 @@ def x(self) -> NDArray: def x(self, value: ArrayLike): """Setter for the **self.x** property.""" - value = np.atleast_1d(value).astype(self._dtype) + value = cast(NDArrayFloat, np.atleast_1d(value).astype(self._dtype)) attest( value.ndim == 1, @@ -861,7 +855,7 @@ def x(self, value: ArrayLike): self._x = value @property - def y(self) -> NDArray: + def y(self) -> NDArrayFloat: """ Getter and setter property for the dependent and already known :math:`y` variable. @@ -884,7 +878,7 @@ def y(self) -> NDArray: def y(self, value: ArrayLike): """Setter for the **self.y** property.""" - value = np.atleast_1d(value).astype(self._dtype) + value = cast(NDArrayFloat, np.atleast_1d(value).astype(self._dtype)) attest( value.ndim == 1, @@ -893,7 +887,7 @@ def y(self, value: ArrayLike): self._y = value - def __call__(self, x: FloatingOrArrayLike) -> FloatingOrNDArray: + def __call__(self, x: ArrayLike) -> NDArrayFloat: """ Evaluate the interpolating polynomial at given point(s). @@ -905,17 +899,17 @@ def __call__(self, x: FloatingOrArrayLike) -> FloatingOrNDArray: Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Interpolated value(s). """ - x = np.atleast_1d(x).astype(self._dtype) + x = cast(NDArrayFloat, np.atleast_1d(x).astype(self._dtype)) xi = as_float(self._evaluate(x)) return xi - def _evaluate(self, x: NDArray) -> NDArray: + def _evaluate(self, x: NDArrayFloat) -> NDArrayFloat: """ Perform the interpolating polynomial evaluation at given points. @@ -944,7 +938,7 @@ def _validate_dimensions(self): f'dimensions: "{len(self._x)}", "{len(self._y)}"' ) - def _validate_interpolation_range(self, x: NDArray): + def _validate_interpolation_range(self, x: NDArrayFloat): """Validate given point to be in interpolation range.""" below_interpolation_range = x < self._x[0] @@ -1037,25 +1031,25 @@ def __init__( x: ArrayLike, y: ArrayLike, dtype: Optional[Type[DTypeNumber]] = None, + *args: Any, + **kwargs: Any, ) -> None: - dtype = cast(Type[DTypeNumber], optional(dtype, DEFAULT_FLOAT_DTYPE)) + dtype = optional(dtype, DEFAULT_FLOAT_DTYPE) - self._xp: NDArray = np.array([]) - self._yp: NDArray = np.array([]) + self._xp: NDArrayFloat = np.array([]) + self._yp: NDArrayFloat = np.array([]) - self._x: NDArray = np.array([]) - self._y: NDArray = np.array([]) + self._x: NDArrayFloat = np.array([]) + self._y: NDArrayFloat = np.array([]) self._dtype: Type[DTypeNumber] = dtype - # TODO: Remove pragma when https://github.com/python/mypy/issues/3004 - # is resolved. - self.x = x # type: ignore[assignment] - self.y = y # type: ignore[assignment] + self.x = x + self.y = y self._validate_dimensions() @property - def x(self) -> NDArray: + def x(self) -> NDArrayFloat: """ Getter and setter property for the independent :math:`x` variable. @@ -1101,7 +1095,7 @@ def x(self, value: ArrayLike): ) @property - def y(self) -> NDArray: + def y(self) -> NDArrayFloat: """ Getter and setter property for the dependent and already known :math:`y` variable. @@ -1184,7 +1178,7 @@ def y(self, value: ArrayLike): ] ) - def __call__(self, x: FloatingOrArrayLike) -> FloatingOrNDArray: + def __call__(self, x: ArrayLike) -> NDArrayFloat: """ Evaluate the interpolating polynomial at given point(s). @@ -1195,17 +1189,17 @@ def __call__(self, x: FloatingOrArrayLike) -> FloatingOrNDArray: Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Interpolated value(s). """ - x = np.atleast_1d(x).astype(self._dtype) + x = cast(NDArrayFloat, np.atleast_1d(x).astype(self._dtype)) xi = as_float(self._evaluate(x)) return xi - def _evaluate(self, x: NDArray) -> NDArray: + def _evaluate(self, x: NDArrayFloat) -> NDArrayFloat: """ Perform the interpolating polynomial evaluation at given point. @@ -1281,7 +1275,7 @@ def _validate_dimensions(self): f'dimensions: "{len(self._x)}", "{len(self._y)}"' ) - def _validate_interpolation_range(self, x: NDArray): + def _validate_interpolation_range(self, x: NDArrayFloat): """Validate given point to be in interpolation range.""" below_interpolation_range = x < self._x[0] @@ -1335,10 +1329,10 @@ def __init__( ) -> None: super().__init__(x, y, *args, **kwargs) - self._y: NDArray = as_float_array(y) + self._y: NDArrayFloat = as_float_array(y) @property - def y(self) -> NDArray: + def y(self) -> NDArrayFloat: """ Getter property for the dependent and already known :math:`y` variable. @@ -1408,24 +1402,24 @@ def __init__( self, x: ArrayLike, y: ArrayLike, - absolute_tolerance: Floating = 10e-7, - relative_tolerance: Floating = 10e-7, - default: Floating = np.nan, + absolute_tolerance: float = 10e-7, + relative_tolerance: float = 10e-7, + default: float = np.nan, dtype: Optional[Type[DTypeNumber]] = None, + *args: Any, + **kwargs: Any, ) -> None: - dtype = cast(Type[DTypeNumber], optional(dtype, DEFAULT_FLOAT_DTYPE)) + dtype = optional(dtype, DEFAULT_FLOAT_DTYPE) - self._x: NDArray = np.array([]) - self._y: NDArray = np.array([]) + self._x: NDArrayFloat = np.array([]) + self._y: NDArrayFloat = np.array([]) self._absolute_tolerance: float = 10e-7 self._relative_tolerance: float = 10e-7 - self._default: Floating = np.nan + self._default: float = np.nan self._dtype: Type[DTypeNumber] = dtype - # TODO: Remove pragma when https://github.com/python/mypy/issues/3004 - # is resolved. - self.x = x # type: ignore[assignment] - self.y = y # type: ignore[assignment] + self.x = x + self.y = y self.absolute_tolerance = absolute_tolerance self.relative_tolerance = relative_tolerance self.default = default @@ -1433,7 +1427,7 @@ def __init__( self._validate_dimensions() @property - def x(self) -> NDArray: + def x(self) -> NDArrayFloat: """ Getter and setter property for the independent :math:`x` variable. @@ -1454,7 +1448,7 @@ def x(self) -> NDArray: def x(self, value: ArrayLike): """Setter for the **self.x** property.""" - value = np.atleast_1d(value).astype(self._dtype) + value = cast(NDArrayFloat, np.atleast_1d(value).astype(self._dtype)) attest( value.ndim == 1, @@ -1464,7 +1458,7 @@ def x(self, value: ArrayLike): self._x = value @property - def y(self) -> NDArray: + def y(self) -> NDArrayFloat: """ Getter and setter property for the dependent and already known :math:`y` variable. @@ -1487,7 +1481,7 @@ def y(self) -> NDArray: def y(self, value: ArrayLike): """Setter for the **self.y** property.""" - value = np.atleast_1d(value).astype(self._dtype) + value = cast(NDArrayFloat, np.atleast_1d(value).astype(self._dtype)) attest( value.ndim == 1, @@ -1497,7 +1491,7 @@ def y(self, value: ArrayLike): self._y = value @property - def relative_tolerance(self) -> Floating: + def relative_tolerance(self) -> float: """ Getter and setter property for the relative tolerance. @@ -1508,14 +1502,14 @@ def relative_tolerance(self) -> Floating: Returns ------- - :class:`numpy.floating` + :class:`float` Relative tolerance. """ return self._relative_tolerance @relative_tolerance.setter - def relative_tolerance(self, value: Floating): + def relative_tolerance(self, value: float): """Setter for the **self.relative_tolerance** property.""" attest( @@ -1526,7 +1520,7 @@ def relative_tolerance(self, value: Floating): self._relative_tolerance = float(value) @property - def absolute_tolerance(self) -> Floating: + def absolute_tolerance(self) -> float: """ Getter and setter property for the absolute tolerance. @@ -1537,14 +1531,14 @@ def absolute_tolerance(self) -> Floating: Returns ------- - :class:`numpy.floating` + :class:`float` Absolute tolerance. """ return self._absolute_tolerance @absolute_tolerance.setter - def absolute_tolerance(self, value: Floating): + def absolute_tolerance(self, value: float): """Setter for the **self.absolute_tolerance** property.""" attest( @@ -1555,7 +1549,7 @@ def absolute_tolerance(self, value: Floating): self._absolute_tolerance = float(value) @property - def default(self) -> Floating: + def default(self) -> float: """ Getter and setter property for the default value for call outside tolerances. @@ -1567,21 +1561,21 @@ def default(self) -> Floating: Returns ------- - :class:`numpy.floating` + :class:`float` Default value. """ return self._default @default.setter - def default(self, value: Floating): + def default(self, value: float): """Setter for the **self.default** property.""" attest(is_numeric(value), '"default" variable must be a "numeric"!') self._default = value - def __call__(self, x: FloatingOrArrayLike) -> FloatingOrNDArray: + def __call__(self, x: ArrayLike) -> NDArrayFloat: """ Evaluate the interpolator at given point(s). @@ -1593,17 +1587,17 @@ def __call__(self, x: FloatingOrArrayLike) -> FloatingOrNDArray: Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Interpolated value(s). """ - x = np.atleast_1d(x).astype(self._dtype) + x = cast(NDArrayFloat, np.atleast_1d(x).astype(self._dtype)) xi = as_float(self._evaluate(x)) return xi - def _evaluate(self, x: NDArray) -> NDArray: + def _evaluate(self, x: NDArrayFloat) -> NDArrayFloat: """ Perform the interpolator evaluation at given points. @@ -1643,7 +1637,7 @@ def _validate_dimensions(self): f'dimensions: "{len(self._x)}", "{len(self._y)}"' ) - def _validate_interpolation_range(self, x: NDArray): + def _validate_interpolation_range(self, x: NDArrayFloat): """Validate given point to be in interpolation range.""" below_interpolation_range = x < self._x[0] @@ -1656,7 +1650,7 @@ def _validate_interpolation_range(self, x: NDArray): raise ValueError(f'"{x}" is above interpolation range.') -def lagrange_coefficients(r: Floating, n: Integer = 4) -> NDArray: +def lagrange_coefficients(r: float, n: int = 4) -> NDArrayFloat: """ Compute the *Lagrange Coefficients* at given point :math:`r` for degree :math:`n`. @@ -1695,7 +1689,7 @@ def lagrange_coefficients(r: Floating, n: Integer = 4) -> NDArray: def vertices_and_relative_coordinates( V_xyz: ArrayLike, table: ArrayLike -) -> Tuple[NDArray, NDArray]: +) -> tuple[NDArrayFloat, NDArrayFloat]: """ Compute the vertices coordinates and indexes relative :math:`V_{xyzr}` coordinates from given :math:`V_{xyzr}` values and interpolation table. @@ -1788,7 +1782,7 @@ def vertices_and_relative_coordinates( i_c = np.clip(i_f + 1, 0, i_m) # Relative to indexes ``V_xyz`` values. - V_xyzr = i_m * V_xyz - i_f + V_xyzr = as_float_array(i_m * V_xyz - i_f) i_f_c = i_f, i_c @@ -1809,7 +1803,7 @@ def vertices_and_relative_coordinates( def table_interpolation_trilinear( V_xyz: ArrayLike, table: ArrayLike -) -> NDArray: +) -> NDArrayFloat: """ Perform the trilinear interpolation of given :math:`V_{xyz}` values using given interpolation table. @@ -1889,7 +1883,7 @@ def table_interpolation_trilinear( def table_interpolation_tetrahedral( V_xyz: ArrayLike, table: ArrayLike -) -> NDArray: +) -> NDArrayFloat: """ Perform the tetrahedral interpolation of given :math:`V_{xyz}` values using given interpolation table. @@ -1989,7 +1983,7 @@ def table_interpolation( V_xyz: ArrayLike, table: ArrayLike, method: Union[Literal["Trilinear", "Tetrahedral"], str] = "Trilinear", -) -> NDArray: +) -> NDArrayFloat: """ Perform interpolation of given :math:`V_{xyz}` values using given interpolation table. diff --git a/colour/algebra/prng.py b/colour/algebra/prng.py index 53c2614c75..a25b50b6a6 100644 --- a/colour/algebra/prng.py +++ b/colour/algebra/prng.py @@ -18,7 +18,7 @@ import numpy as np -from colour.hints import ArrayLike, Integer, NDArray +from colour.hints import ArrayLike, NDArrayFloat from colour.utilities import as_float_array, tstack __author__ = "Colour Developers" @@ -37,10 +37,10 @@ def random_triplet_generator( - size: Integer, + size: int, limits: ArrayLike = np.array([[0, 1], [0, 1], [0, 1]]), random_state: np.random.RandomState = RANDOM_STATE, -) -> NDArray: +) -> NDArrayFloat: """ Return a generator yielding random triplets. diff --git a/colour/algebra/regression.py b/colour/algebra/regression.py index eae946c466..0a0c2ab3be 100644 --- a/colour/algebra/regression.py +++ b/colour/algebra/regression.py @@ -19,7 +19,7 @@ import numpy as np -from colour.hints import ArrayLike, NDArray +from colour.hints import ArrayLike, NDArrayFloat __author__ = "Colour Developers" __copyright__ = "Copyright 2013 Colour Developers" @@ -33,7 +33,9 @@ ] -def least_square_mapping_MoorePenrose(y: ArrayLike, x: ArrayLike) -> NDArray: +def least_square_mapping_MoorePenrose( + y: ArrayLike, x: ArrayLike +) -> NDArrayFloat: """ Compute the *least-squares* mapping from dependent variable :math:`y` to independent variable :math:`x` using *Moore-Penrose* inverse. diff --git a/colour/algebra/tests/test_interpolation.py b/colour/algebra/tests/test_interpolation.py index 40581b1efe..7ce87d14e2 100644 --- a/colour/algebra/tests/test_interpolation.py +++ b/colour/algebra/tests/test_interpolation.py @@ -16,7 +16,7 @@ from itertools import product from colour.algebra.interpolation import vertices_and_relative_coordinates -from colour.hints import NDArray, Tuple +from colour.hints import NDArrayFloat, cast from colour.algebra import ( kernel_nearest_neighbour, kernel_linear, @@ -35,7 +35,7 @@ table_interpolation_tetrahedral, ) from colour.algebra import random_triplet_generator -from colour.io import read_LUT +from colour.io import LUT3D, read_LUT from colour.utilities import ignore_numpy_errors __author__ = "Colour Developers" @@ -70,7 +70,7 @@ "TestTableInterpolationTetrahedral", ] -DATA_POINTS_A: Tuple = ( +DATA_POINTS_A: tuple = ( 9.3700, 12.3200, 12.4600, @@ -89,7 +89,7 @@ 86.0500, ) -DATA_POINTS_A_LINEAR_INTERPOLATED_10_SAMPLES: Tuple = ( +DATA_POINTS_A_LINEAR_INTERPOLATED_10_SAMPLES: tuple = ( 9.370, 9.665, 9.960, @@ -243,7 +243,7 @@ 86.050, ) -DATA_POINTS_A_SPRAGUE_INTERPOLATED_10_SAMPLES: Tuple = ( +DATA_POINTS_A_SPRAGUE_INTERPOLATED_10_SAMPLES: tuple = ( 9.37000000, 9.72075073, 10.06936191, @@ -397,7 +397,7 @@ 86.05000000, ) -DATA_POINTS_A_CUBIC_SPLINE_INTERPOLATED_X2_SAMPLES: Tuple = ( +DATA_POINTS_A_CUBIC_SPLINE_INTERPOLATED_X2_SAMPLES: tuple = ( 9.37000000, 11.08838189, 12.26359953, @@ -432,7 +432,7 @@ 86.05000000, ) -LAGRANGE_COEFFICIENTS_A: NDArray = np.array( +LAGRANGE_COEFFICIENTS_A: NDArrayFloat = np.array( [ [0.92625, 0.09750, -0.02375], [0.85500, 0.19000, -0.04500], @@ -456,7 +456,7 @@ ] ) -LAGRANGE_COEFFICIENTS_B: NDArray = np.array( +LAGRANGE_COEFFICIENTS_B: NDArrayFloat = np.array( [ [-0.0154375, 0.9725625, 0.0511875, -0.0083125], [-0.0285000, 0.9405000, 0.1045000, -0.0165000], @@ -480,19 +480,22 @@ ] ) -LUT_TABLE: NDArray = read_LUT( - os.path.join( - os.path.dirname(__file__), - "..", - "..", - "io", - "luts", - "tests", - "resources", - "iridas_cube", - "Colour_Correct.cube", - ) -).table # type: ignore[union-attr] +LUT_TABLE: NDArrayFloat = cast( + LUT3D, + read_LUT( + os.path.join( + os.path.dirname(__file__), + "..", + "..", + "io", + "luts", + "tests", + "resources", + "iridas_cube", + "Colour_Correct.cube", + ) + ), +).table class TestKernelNearestNeighbour(unittest.TestCase): diff --git a/colour/algebra/tests/test_prng.py b/colour/algebra/tests/test_prng.py index c29a2e2db7..ee7024128b 100644 --- a/colour/algebra/tests/test_prng.py +++ b/colour/algebra/tests/test_prng.py @@ -16,7 +16,7 @@ import unittest from colour.algebra import random_triplet_generator -from colour.hints import NDArray +from colour.hints import NDArrayFloat __author__ = "Colour Developers" __copyright__ = "Copyright 2013 Colour Developers" @@ -30,7 +30,7 @@ "TestRandomTripletGenerator", ] -RANDOM_TRIPLETS: NDArray = np.array( +RANDOM_TRIPLETS: NDArrayFloat = np.array( [ [0.96702984, 0.77938292, 0.43614665], [0.54723225, 0.19768507, 0.94897731], diff --git a/colour/appearance/atd95.py b/colour/appearance/atd95.py index 01970a5be1..beed9baf4b 100644 --- a/colour/appearance/atd95.py +++ b/colour/appearance/atd95.py @@ -32,10 +32,9 @@ from colour.algebra import spow, vector_dot from colour.hints import ( ArrayLike, - FloatingOrArrayLike, - FloatingOrNDArray, - NDArray, + NDArrayFloat, Optional, + Union, ) from colour.utilities import ( MixinDataclassArithmetic, @@ -103,15 +102,33 @@ class CAM_ReferenceSpecification_ATD95(MixinDataclassArithmetic): :cite:`Fairchild2013v`, :cite:`Guth1995a` """ - H: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - C: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - Br: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - A_1: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - T_1: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - D_1: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - A_2: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - T_2: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - D_2: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) + H: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + C: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + Br: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + A_1: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + T_1: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + D_1: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + A_2: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + T_2: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + D_2: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) @dataclass @@ -157,24 +174,42 @@ class CAM_Specification_ATD95(MixinDataclassArithmetic): :cite:`Fairchild2013v`, :cite:`Guth1995a` """ - h: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - C: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - Q: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - A_1: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - T_1: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - D_1: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - A_2: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - T_2: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - D_2: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) + h: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + C: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + Q: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + A_1: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + T_1: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + D_1: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + A_2: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + T_2: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + D_2: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) def XYZ_to_ATD95( XYZ: ArrayLike, XYZ_0: ArrayLike, - Y_0: FloatingOrArrayLike, - k_1: FloatingOrArrayLike, - k_2: FloatingOrArrayLike, - sigma: FloatingOrArrayLike = 300, + Y_0: ArrayLike, + k_1: ArrayLike, + k_2: ArrayLike, + sigma: ArrayLike = 300, ) -> CAM_Specification_ATD95: """ Compute the *ATD (1995)* colour vision model correlates. @@ -281,8 +316,8 @@ def XYZ_to_ATD95( def luminance_to_retinal_illuminance( - XYZ: ArrayLike, Y_c: FloatingOrArrayLike -) -> NDArray: + XYZ: ArrayLike, Y_c: ArrayLike +) -> NDArrayFloat: """ Convert from luminance in :math:`cd/m^2` to retinal illuminance in trolands. @@ -313,7 +348,7 @@ def luminance_to_retinal_illuminance( return as_float_array(18 * spow(Y_c[..., None] * XYZ / 100, 0.8)) -def XYZ_to_LMS_ATD95(XYZ: ArrayLike) -> NDArray: +def XYZ_to_LMS_ATD95(XYZ: ArrayLike) -> NDArrayFloat: """ Convert from *CIE XYZ* tristimulus values to *LMS* cone responses. @@ -350,7 +385,7 @@ def XYZ_to_LMS_ATD95(XYZ: ArrayLike) -> NDArray: return as_float_array(LMS_p) -def opponent_colour_dimensions(LMS_g: ArrayLike) -> NDArray: +def opponent_colour_dimensions(LMS_g: ArrayLike) -> NDArrayFloat: """ Return opponent colour dimensions from given post adaptation cone signals. @@ -390,7 +425,7 @@ def opponent_colour_dimensions(LMS_g: ArrayLike) -> NDArray: return tstack([A_1, T_1, D_1, A_2, T_2, D_2]) -def final_response(value: FloatingOrArrayLike) -> FloatingOrNDArray: +def final_response(value: ArrayLike) -> NDArrayFloat: """ Return the final response of given opponent colour dimension. @@ -401,7 +436,7 @@ def final_response(value: FloatingOrArrayLike) -> FloatingOrNDArray: Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Final response of opponent colour dimension. Examples diff --git a/colour/appearance/cam16.py b/colour/appearance/cam16.py index 303dbfdfaf..197ee37599 100644 --- a/colour/appearance/cam16.py +++ b/colour/appearance/cam16.py @@ -51,10 +51,7 @@ ) from colour.hints import ( ArrayLike, - Boolean, - FloatingOrArrayLike, - FloatingOrNDArray, - NDArray, + NDArrayFloat, Optional, Union, ) @@ -89,10 +86,10 @@ "CAM16_to_XYZ", ] -MATRIX_16: NDArray = CAT_CAT16 +MATRIX_16: NDArrayFloat = CAT_CAT16 """Adaptation matrix :math:`M_{16}`.""" -MATRIX_INVERSE_16: NDArray = np.linalg.inv(MATRIX_16) +MATRIX_INVERSE_16: NDArrayFloat = np.linalg.inv(MATRIX_16) """Inverse adaptation matrix :math:`M^{-1}_{16}`.""" @@ -163,25 +160,41 @@ class CAM_Specification_CAM16(MixinDataclassArithmetic): :cite:`Li2017` """ - J: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - C: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - h: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - s: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - Q: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - M: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - H: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - HC: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) + J: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + C: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + h: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + s: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + Q: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + M: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + H: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + HC: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) def XYZ_to_CAM16( XYZ: ArrayLike, XYZ_w: ArrayLike, - L_A: FloatingOrArrayLike, - Y_b: FloatingOrArrayLike, + L_A: ArrayLike, + Y_b: ArrayLike, surround: Union[ InductionFactors_CIECAM02, InductionFactors_CAM16 ] = VIEWING_CONDITIONS_CAM16["Average"], - discount_illuminant: Boolean = False, + discount_illuminant: bool = False, ) -> CAM_Specification_CAM16: """ Compute the *CAM16* colour appearance model correlates from given @@ -353,13 +366,13 @@ def XYZ_to_CAM16( def CAM16_to_XYZ( specification: CAM_Specification_CAM16, XYZ_w: ArrayLike, - L_A: FloatingOrArrayLike, - Y_b: FloatingOrArrayLike, + L_A: ArrayLike, + Y_b: ArrayLike, surround: Union[ InductionFactors_CIECAM02, InductionFactors_CAM16 ] = VIEWING_CONDITIONS_CAM16["Average"], - discount_illuminant: Boolean = False, -) -> NDArray: + discount_illuminant: bool = False, +) -> NDArrayFloat: """ Convert from *CAM16* specification to *CIE XYZ* tristimulus values. diff --git a/colour/appearance/ciecam02.py b/colour/appearance/ciecam02.py index 6d7e568134..a14e576f40 100644 --- a/colour/appearance/ciecam02.py +++ b/colour/appearance/ciecam02.py @@ -47,13 +47,9 @@ from colour.constants import EPSILON from colour.hints import ( ArrayLike, - Boolean, - Dict, - FloatingOrArrayLike, - FloatingOrNDArray, - NDArray, + NDArrayFloat, Optional, - Tuple, + Union, cast, ) from colour.models import xy_to_XYZ @@ -122,7 +118,7 @@ "matrix_post_adaptation_non_linear_response_compression", ] -CAT_INVERSE_CAT02: NDArray = np.linalg.inv(CAT_CAT02) +CAT_INVERSE_CAT02: NDArrayFloat = np.linalg.inv(CAT_CAT02) """Inverse CAT02 chromatic adaptation transform.""" @@ -164,13 +160,13 @@ class InductionFactors_CIECAM02( :cite:`Wikipedia2007a` """ -HUE_DATA_FOR_HUE_QUADRATURE: Dict = { +HUE_DATA_FOR_HUE_QUADRATURE: dict = { "h_i": np.array([20.14, 90.00, 164.25, 237.53, 380.14]), "e_i": np.array([0.8, 0.7, 1.0, 1.2, 0.8]), "H_i": np.array([0.0, 100.0, 200.0, 300.0, 400.0]), } -CAM_KWARGS_CIECAM02_sRGB: Dict = { +CAM_KWARGS_CIECAM02_sRGB: dict = { "XYZ_w": xy_to_XYZ( CCS_ILLUMINANTS["CIE 1931 2 Degree Standard Observer"]["D65"] ) @@ -222,25 +218,41 @@ class CAM_Specification_CIECAM02(MixinDataclassArithmetic): :cite:`Wikipedia2007a` """ - J: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - C: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - h: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - s: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - Q: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - M: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - H: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - HC: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) + J: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + C: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + h: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + s: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + Q: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + M: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + H: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + HC: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) def XYZ_to_CIECAM02( XYZ: ArrayLike, XYZ_w: ArrayLike, - L_A: FloatingOrArrayLike, - Y_b: FloatingOrArrayLike, + L_A: ArrayLike, + Y_b: ArrayLike, surround: InductionFactors_CIECAM02 = VIEWING_CONDITIONS_CIECAM02[ "Average" ], - discount_illuminant: Boolean = False, + discount_illuminant: bool = False, ) -> CAM_Specification_CIECAM02: """ Compute the *CIECAM02* colour appearance model correlates from given @@ -418,13 +430,13 @@ def XYZ_to_CIECAM02( def CIECAM02_to_XYZ( specification: CAM_Specification_CIECAM02, XYZ_w: ArrayLike, - L_A: FloatingOrArrayLike, - Y_b: FloatingOrArrayLike, + L_A: ArrayLike, + Y_b: ArrayLike, surround: InductionFactors_CIECAM02 = VIEWING_CONDITIONS_CIECAM02[ "Average" ], - discount_illuminant: Boolean = False, -) -> NDArray: + discount_illuminant: bool = False, +) -> NDArrayFloat: """ Convert from *CIECAM02* specification to *CIE XYZ* tristimulus values. @@ -610,7 +622,7 @@ def CIECAM02_to_XYZ( return from_range_100(XYZ) -def chromatic_induction_factors(n: FloatingOrArrayLike) -> NDArray: +def chromatic_induction_factors(n: ArrayLike) -> NDArrayFloat: """ Return the chromatic induction factors :math:`N_{bb}` and :math:`N_{cb}`. @@ -641,8 +653,8 @@ def chromatic_induction_factors(n: FloatingOrArrayLike) -> NDArray: def base_exponential_non_linearity( - n: FloatingOrArrayLike, -) -> FloatingOrNDArray: + n: ArrayLike, +) -> NDArrayFloat: """ Return the base exponential non-linearity :math:`n`. @@ -653,7 +665,7 @@ def base_exponential_non_linearity( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Base exponential non-linearity :math:`z`. Examples @@ -670,15 +682,15 @@ def base_exponential_non_linearity( def viewing_conditions_dependent_parameters( - Y_b: FloatingOrArrayLike, - Y_w: FloatingOrArrayLike, - L_A: FloatingOrArrayLike, -) -> Tuple[ - FloatingOrNDArray, - FloatingOrNDArray, - FloatingOrNDArray, - FloatingOrNDArray, - FloatingOrNDArray, + Y_b: ArrayLike, + Y_w: ArrayLike, + L_A: ArrayLike, +) -> tuple[ + NDArrayFloat, + NDArrayFloat, + NDArrayFloat, + NDArrayFloat, + NDArrayFloat, ]: """ Return the viewing condition dependent parameters. @@ -717,9 +729,7 @@ def viewing_conditions_dependent_parameters( return n, F_L, N_bb, N_cb, z -def degree_of_adaptation( - F: FloatingOrArrayLike, L_A: FloatingOrArrayLike -) -> FloatingOrNDArray: +def degree_of_adaptation(F: ArrayLike, L_A: ArrayLike) -> NDArrayFloat: """ Return the degree of adaptation :math:`D` from given surround maximum degree of adaptation :math:`F` and adapting field *luminance* :math:`L_A` @@ -734,7 +744,7 @@ def degree_of_adaptation( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Degree of adaptation :math:`D`. Examples @@ -754,9 +764,9 @@ def degree_of_adaptation( def full_chromatic_adaptation_forward( RGB: ArrayLike, RGB_w: ArrayLike, - Y_w: FloatingOrArrayLike, - D: FloatingOrArrayLike, -) -> NDArray: + Y_w: ArrayLike, + D: ArrayLike, +) -> NDArrayFloat: """ Apply full chromatic adaptation to given *CMCCAT2000* transform sharpened *RGB* array using given *CMCCAT2000* transform sharpened whitepoint @@ -805,9 +815,9 @@ def full_chromatic_adaptation_forward( def full_chromatic_adaptation_inverse( RGB: ArrayLike, RGB_w: ArrayLike, - Y_w: FloatingOrArrayLike, - D: FloatingOrArrayLike, -) -> NDArray: + Y_w: ArrayLike, + D: ArrayLike, +) -> NDArrayFloat: """ Revert full chromatic adaptation of given *CMCCAT2000* transform sharpened *RGB* array using given *CMCCAT2000* transform sharpened whitepoint @@ -849,10 +859,10 @@ def full_chromatic_adaptation_inverse( Y_w[..., None] * sdiv(D[..., None], RGB_w) + 1 - D[..., None] ) - return cast(NDArray, RGB_c) + return cast(NDArrayFloat, RGB_c) -def RGB_to_rgb(RGB: ArrayLike) -> NDArray: +def RGB_to_rgb(RGB: ArrayLike) -> NDArrayFloat: """ Convert given *RGB* array to *Hunt-Pointer-Estevez* :math:`\\rho\\gamma\\beta` colourspace. @@ -879,7 +889,7 @@ def RGB_to_rgb(RGB: ArrayLike) -> NDArray: return rgb -def rgb_to_RGB(rgb: ArrayLike) -> NDArray: +def rgb_to_RGB(rgb: ArrayLike) -> NDArrayFloat: """ Convert given *Hunt-Pointer-Estevez* :math:`\\rho\\gamma\\beta` colourspace array to *RGB* array. @@ -907,8 +917,8 @@ def rgb_to_RGB(rgb: ArrayLike) -> NDArray: def post_adaptation_non_linear_response_compression_forward( - RGB: ArrayLike, F_L: FloatingOrArrayLike -) -> NDArray: + RGB: ArrayLike, F_L: ArrayLike +) -> NDArrayFloat: """ Return given *CMCCAT2000* transform sharpened *RGB* array with post adaptation non-linear response compression. @@ -949,8 +959,8 @@ def post_adaptation_non_linear_response_compression_forward( def post_adaptation_non_linear_response_compression_inverse( - RGB: ArrayLike, F_L: FloatingOrArrayLike -) -> NDArray: + RGB: ArrayLike, F_L: ArrayLike +) -> NDArrayFloat: """ Return given *CMCCAT2000* transform sharpened *RGB* array without post adaptation non-linear response compression. @@ -992,7 +1002,7 @@ def post_adaptation_non_linear_response_compression_inverse( return RGB_p -def opponent_colour_dimensions_forward(RGB: ArrayLike) -> NDArray: +def opponent_colour_dimensions_forward(RGB: ArrayLike) -> NDArrayFloat: """ Return opponent colour dimensions from given compressed *CMCCAT2000* transform sharpened *RGB* array for forward *CIECAM02* implementation. @@ -1025,8 +1035,8 @@ def opponent_colour_dimensions_forward(RGB: ArrayLike) -> NDArray: def opponent_colour_dimensions_inverse( - P_n: ArrayLike, h: FloatingOrArrayLike -) -> NDArray: + P_n: ArrayLike, h: ArrayLike +) -> NDArrayFloat: """ Return opponent colour dimensions from given points :math:`P_n` and hue :math:`h` in degrees for inverse *CIECAM02* implementation. @@ -1112,9 +1122,7 @@ def opponent_colour_dimensions_inverse( return ab -def hue_angle( - a: FloatingOrArrayLike, b: FloatingOrArrayLike -) -> FloatingOrNDArray: +def hue_angle(a: ArrayLike, b: ArrayLike) -> NDArrayFloat: """ Return the *hue* angle :math:`h` in degrees. @@ -1127,7 +1135,7 @@ def hue_angle( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` *Hue* angle :math:`h` in degrees. Examples @@ -1146,7 +1154,7 @@ def hue_angle( return as_float(h) -def hue_quadrature(h: FloatingOrArrayLike) -> FloatingOrNDArray: +def hue_quadrature(h: ArrayLike) -> NDArrayFloat: """ Return the hue quadrature from given hue :math:`h` angle in degrees. @@ -1157,7 +1165,7 @@ def hue_quadrature(h: FloatingOrArrayLike) -> FloatingOrNDArray: Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Hue quadrature. Examples @@ -1203,7 +1211,7 @@ def hue_quadrature(h: FloatingOrArrayLike) -> FloatingOrNDArray: return as_float(H) -def eccentricity_factor(h: FloatingOrArrayLike) -> FloatingOrNDArray: +def eccentricity_factor(h: ArrayLike) -> NDArrayFloat: """ Return the eccentricity factor :math:`e_t` from given hue :math:`h` angle in degrees for forward *CIECAM02* implementation. @@ -1215,7 +1223,7 @@ def eccentricity_factor(h: FloatingOrArrayLike) -> FloatingOrNDArray: Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Eccentricity factor :math:`e_t`. Examples @@ -1232,8 +1240,8 @@ def eccentricity_factor(h: FloatingOrArrayLike) -> FloatingOrNDArray: def achromatic_response_forward( - RGB: ArrayLike, N_bb: FloatingOrArrayLike -) -> FloatingOrNDArray: + RGB: ArrayLike, N_bb: ArrayLike +) -> NDArrayFloat: """ Return the achromatic response :math:`A` from given compressed *CMCCAT2000* transform sharpened *RGB* array and :math:`N_{bb}` chromatic @@ -1248,7 +1256,7 @@ def achromatic_response_forward( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Achromatic response :math:`A`. Examples @@ -1267,11 +1275,11 @@ def achromatic_response_forward( def achromatic_response_inverse( - A_w: FloatingOrArrayLike, - J: FloatingOrArrayLike, - c: FloatingOrArrayLike, - z: FloatingOrArrayLike, -) -> FloatingOrNDArray: + A_w: ArrayLike, + J: ArrayLike, + c: ArrayLike, + z: ArrayLike, +) -> NDArrayFloat: """ Return the achromatic response :math:`A` from given achromatic response :math:`A_w` for the whitepoint, *Lightness* correlate :math:`J`, surround @@ -1291,7 +1299,7 @@ def achromatic_response_inverse( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Achromatic response :math:`A`. Examples @@ -1315,11 +1323,11 @@ def achromatic_response_inverse( def lightness_correlate( - A: FloatingOrArrayLike, - A_w: FloatingOrArrayLike, - c: FloatingOrArrayLike, - z: FloatingOrArrayLike, -) -> FloatingOrNDArray: + A: ArrayLike, + A_w: ArrayLike, + c: ArrayLike, + z: ArrayLike, +) -> NDArrayFloat: """ Return the *Lightness* correlate :math:`J`. @@ -1336,7 +1344,7 @@ def lightness_correlate( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` *Lightness* correlate :math:`J`. Examples @@ -1361,11 +1369,11 @@ def lightness_correlate( def brightness_correlate( - c: FloatingOrArrayLike, - J: FloatingOrArrayLike, - A_w: FloatingOrArrayLike, - F_L: FloatingOrArrayLike, -) -> FloatingOrNDArray: + c: ArrayLike, + J: ArrayLike, + A_w: ArrayLike, + F_L: ArrayLike, +) -> NDArrayFloat: """ Return the *brightness* correlate :math:`Q`. @@ -1382,7 +1390,7 @@ def brightness_correlate( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` *Brightness* correlate :math:`Q`. Examples @@ -1406,13 +1414,13 @@ def brightness_correlate( def temporary_magnitude_quantity_forward( - N_c: FloatingOrArrayLike, - N_cb: FloatingOrArrayLike, - e_t: FloatingOrArrayLike, - a: FloatingOrArrayLike, - b: FloatingOrArrayLike, + N_c: ArrayLike, + N_cb: ArrayLike, + e_t: ArrayLike, + a: ArrayLike, + b: ArrayLike, RGB_a: ArrayLike, -) -> FloatingOrNDArray: +) -> NDArrayFloat: """ Return the temporary magnitude quantity :math:`t`. for forward *CIECAM02* implementation. @@ -1434,7 +1442,7 @@ def temporary_magnitude_quantity_forward( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Temporary magnitude quantity :math:`t`. Examples @@ -1466,8 +1474,8 @@ def temporary_magnitude_quantity_forward( def temporary_magnitude_quantity_inverse( - C: FloatingOrArrayLike, J: FloatingOrArrayLike, n: FloatingOrArrayLike -) -> FloatingOrNDArray: + C: ArrayLike, J: ArrayLike, n: ArrayLike +) -> NDArrayFloat: """ Return the temporary magnitude quantity :math:`t`. for inverse *CIECAM02* implementation. @@ -1483,7 +1491,7 @@ def temporary_magnitude_quantity_inverse( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Temporary magnitude quantity :math:`t`. Examples @@ -1505,15 +1513,15 @@ def temporary_magnitude_quantity_inverse( def chroma_correlate( - J: FloatingOrArrayLike, - n: FloatingOrArrayLike, - N_c: FloatingOrArrayLike, - N_cb: FloatingOrArrayLike, - e_t: FloatingOrArrayLike, - a: FloatingOrArrayLike, - b: FloatingOrArrayLike, + J: ArrayLike, + n: ArrayLike, + N_c: ArrayLike, + N_cb: ArrayLike, + e_t: ArrayLike, + a: ArrayLike, + b: ArrayLike, RGB_a: ArrayLike, -) -> FloatingOrNDArray: +) -> NDArrayFloat: """ Return the *chroma* correlate :math:`C`. @@ -1538,7 +1546,7 @@ def chroma_correlate( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` *Chroma* correlate :math:`C`. Examples @@ -1565,9 +1573,7 @@ def chroma_correlate( return C -def colourfulness_correlate( - C: FloatingOrArrayLike, F_L: FloatingOrArrayLike -) -> FloatingOrNDArray: +def colourfulness_correlate(C: ArrayLike, F_L: ArrayLike) -> NDArrayFloat: """ Return the *colourfulness* correlate :math:`M`. @@ -1580,7 +1586,7 @@ def colourfulness_correlate( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` *Colourfulness* correlate :math:`M`. Examples @@ -1599,9 +1605,7 @@ def colourfulness_correlate( return M -def saturation_correlate( - M: FloatingOrArrayLike, Q: FloatingOrArrayLike -) -> FloatingOrNDArray: +def saturation_correlate(M: ArrayLike, Q: ArrayLike) -> NDArrayFloat: """ Return the *saturation* correlate :math:`s`. @@ -1614,7 +1618,7 @@ def saturation_correlate( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` *Saturation* correlate :math:`s`. Examples @@ -1635,13 +1639,13 @@ def saturation_correlate( def P( - N_c: FloatingOrArrayLike, - N_cb: FloatingOrArrayLike, - e_t: FloatingOrArrayLike, - t: FloatingOrArrayLike, - A: FloatingOrArrayLike, - N_bb: FloatingOrArrayLike, -) -> NDArray: + N_c: ArrayLike, + N_cb: ArrayLike, + e_t: ArrayLike, + t: ArrayLike, + A: ArrayLike, + N_bb: ArrayLike, +) -> NDArrayFloat: """ Return the points :math:`P_1`, :math:`P_2` and :math:`P_3`. @@ -1688,7 +1692,7 @@ def P( P_1 = sdiv((50000 / 13) * N_c * N_cb * e_t, t) P_2 = A / N_bb + 0.305 - P_3 = ones(cast(NDArray, P_1).shape) * (21 / 20) + P_3 = ones(P_1.shape) * (21 / 20) P_n = tstack([P_1, P_2, P_3]) @@ -1696,8 +1700,8 @@ def P( def matrix_post_adaptation_non_linear_response_compression( - P_2: FloatingOrArrayLike, a: FloatingOrArrayLike, b: FloatingOrArrayLike -) -> NDArray: + P_2: ArrayLike, a: ArrayLike, b: ArrayLike +) -> NDArrayFloat: """ Apply the post-adaptation non-linear-response compression matrix. diff --git a/colour/appearance/ciecam16.py b/colour/appearance/ciecam16.py index 6b80036e23..4534f4a248 100644 --- a/colour/appearance/ciecam16.py +++ b/colour/appearance/ciecam16.py @@ -50,10 +50,7 @@ ) from colour.hints import ( ArrayLike, - Boolean, - FloatingOrArrayLike, - FloatingOrNDArray, - NDArray, + NDArrayFloat, Optional, Union, ) @@ -158,25 +155,41 @@ class CAM_Specification_CIECAM16(MixinDataclassArithmetic): :cite:`CIEDivision12022` """ - J: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - C: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - h: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - s: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - Q: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - M: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - H: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - HC: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) + J: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + C: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + h: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + s: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + Q: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + M: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + H: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + HC: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) def XYZ_to_CIECAM16( XYZ: ArrayLike, XYZ_w: ArrayLike, - L_A: FloatingOrArrayLike, - Y_b: FloatingOrArrayLike, + L_A: ArrayLike, + Y_b: ArrayLike, surround: Union[ InductionFactors_CIECAM02, InductionFactors_CIECAM16 ] = VIEWING_CONDITIONS_CIECAM16["Average"], - discount_illuminant: Boolean = False, + discount_illuminant: bool = False, ) -> CAM_Specification_CIECAM16: """ Compute the *CIECAM16* colour appearance model correlates from given @@ -365,13 +378,13 @@ def XYZ_to_CIECAM16( def CIECAM16_to_XYZ( specification: CAM_Specification_CIECAM16, XYZ_w: ArrayLike, - L_A: FloatingOrArrayLike, - Y_b: FloatingOrArrayLike, + L_A: ArrayLike, + Y_b: ArrayLike, surround: Union[ InductionFactors_CIECAM02, InductionFactors_CIECAM16 ] = VIEWING_CONDITIONS_CIECAM16["Average"], - discount_illuminant: Boolean = False, -) -> NDArray: + discount_illuminant: bool = False, +) -> NDArrayFloat: """ Convert from *CIECAM16* specification to *CIE XYZ* tristimulus values. @@ -554,7 +567,7 @@ def CIECAM16_to_XYZ( return from_range_100(XYZ) -def f_e_forward(RGB_c: ArrayLike, F_L: FloatingOrArrayLike) -> NDArray: +def f_e_forward(RGB_c: ArrayLike, F_L: ArrayLike) -> NDArrayFloat: """ Compute the post-adaptation cone responses. @@ -603,7 +616,7 @@ def f_e_forward(RGB_c: ArrayLike, F_L: FloatingOrArrayLike) -> NDArray: ) -def f_e_inverse(RGB_a: ArrayLike, F_L: FloatingOrArrayLike) -> NDArray: +def f_e_inverse(RGB_a: ArrayLike, F_L: ArrayLike) -> NDArrayFloat: """ Compute the modified cone-like responses. @@ -654,7 +667,7 @@ def f_e_inverse(RGB_a: ArrayLike, F_L: FloatingOrArrayLike) -> NDArray: ) -def f_q(F_L: FloatingOrArrayLike, q: FloatingOrArrayLike) -> FloatingOrNDArray: +def f_q(F_L: ArrayLike, q: ArrayLike) -> NDArrayFloat: """ Define the :math:`f(q)` function. @@ -686,9 +699,7 @@ def f_q(F_L: FloatingOrArrayLike, q: FloatingOrArrayLike) -> FloatingOrNDArray: return (400 * F_L_q_100) / (27.13 + F_L_q_100) -def d_f_q( - F_L: FloatingOrArrayLike, q: FloatingOrArrayLike -) -> FloatingOrNDArray: +def d_f_q(F_L: ArrayLike, q: ArrayLike) -> NDArrayFloat: """ Define the :math:`f'(q)` function derivative. diff --git a/colour/appearance/hellwig2022.py b/colour/appearance/hellwig2022.py index d358897b3b..5096f693f1 100644 --- a/colour/appearance/hellwig2022.py +++ b/colour/appearance/hellwig2022.py @@ -50,12 +50,8 @@ from colour.appearance.hunt import luminance_level_adaptation_factor from colour.hints import ( ArrayLike, - Boolean, - FloatingOrArrayLike, - FloatingOrNDArray, - NDArray, + NDArrayFloat, Optional, - Tuple, Union, ) from colour.utilities import ( @@ -177,27 +173,47 @@ class CAM_Specification_Hellwig2022(MixinDataclassArithmetic): :cite:`Fairchild2022`, :cite:`Hellwig2022`, :cite:`Hellwig2022a` """ - J: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - C: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - h: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - s: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - Q: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - M: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - H: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - HC: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - J_HK: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - Q_HK: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) + J: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + C: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + h: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + s: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + Q: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + M: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + H: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + HC: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + J_HK: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + Q_HK: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) def XYZ_to_Hellwig2022( XYZ: ArrayLike, XYZ_w: ArrayLike, - L_A: FloatingOrArrayLike, - Y_b: FloatingOrArrayLike, + L_A: ArrayLike, + Y_b: ArrayLike, surround: Union[ InductionFactors_CIECAM02, InductionFactors_Hellwig2022 ] = VIEWING_CONDITIONS_HELLWIG2022["Average"], - discount_illuminant: Boolean = False, + discount_illuminant: bool = False, ) -> CAM_Specification_Hellwig2022: """ Compute the *Hellwig and Fairchild (2022)* colour appearance model @@ -402,13 +418,13 @@ def XYZ_to_Hellwig2022( def Hellwig2022_to_XYZ( specification: CAM_Specification_Hellwig2022, XYZ_w: ArrayLike, - L_A: FloatingOrArrayLike, - Y_b: FloatingOrArrayLike, + L_A: ArrayLike, + Y_b: ArrayLike, surround: Union[ InductionFactors_CIECAM02, InductionFactors_Hellwig2022 ] = VIEWING_CONDITIONS_HELLWIG2022["Average"], - discount_illuminant: Boolean = False, -) -> NDArray: + discount_illuminant: bool = False, +) -> NDArrayFloat: """ Convert from *Hellwig and Fairchild (2022)* specification to *CIE XYZ* tristimulus values. @@ -622,10 +638,10 @@ def Hellwig2022_to_XYZ( def viewing_conditions_dependent_parameters( - Y_b: FloatingOrArrayLike, - Y_w: FloatingOrArrayLike, - L_A: FloatingOrArrayLike, -) -> Tuple[FloatingOrNDArray, FloatingOrNDArray]: + Y_b: ArrayLike, + Y_w: ArrayLike, + L_A: ArrayLike, +) -> tuple[NDArrayFloat, NDArrayFloat]: """ Return the viewing condition dependent parameters. @@ -662,7 +678,7 @@ def viewing_conditions_dependent_parameters( return F_L, z -def achromatic_response_forward(RGB: ArrayLike) -> FloatingOrNDArray: +def achromatic_response_forward(RGB: ArrayLike) -> NDArrayFloat: """ Return the achromatic response :math:`A` from given compressed *CAM16* transform sharpened *RGB* array and :math:`N_{bb}` chromatic @@ -675,7 +691,7 @@ def achromatic_response_forward(RGB: ArrayLike) -> FloatingOrNDArray: Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Achromatic response :math:`A`. Examples @@ -693,8 +709,8 @@ def achromatic_response_forward(RGB: ArrayLike) -> FloatingOrNDArray: def opponent_colour_dimensions_inverse( - P_p_1: FloatingOrArrayLike, h: FloatingOrArrayLike, M: FloatingOrArrayLike -) -> NDArray: + P_p_1: ArrayLike, h: ArrayLike, M: ArrayLike +) -> NDArrayFloat: """ Return opponent colour dimensions from given point :math:`P'_1`, hue :math:`h` in degrees and correlate of *colourfulness* :math:`M` for @@ -739,7 +755,7 @@ def opponent_colour_dimensions_inverse( return ab -def eccentricity_factor(h: FloatingOrArrayLike) -> FloatingOrNDArray: +def eccentricity_factor(h: ArrayLike) -> NDArrayFloat: """ Return the eccentricity factor :math:`e_t` from given hue :math:`h` angle in degrees for forward *CIECAM02* implementation. @@ -751,7 +767,7 @@ def eccentricity_factor(h: FloatingOrArrayLike) -> FloatingOrNDArray: Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Eccentricity factor :math:`e_t`. Examples @@ -785,10 +801,10 @@ def eccentricity_factor(h: FloatingOrArrayLike) -> FloatingOrNDArray: def brightness_correlate( - c: FloatingOrArrayLike, - J: FloatingOrArrayLike, - A_w: FloatingOrArrayLike, -) -> FloatingOrNDArray: + c: ArrayLike, + J: ArrayLike, + A_w: ArrayLike, +) -> NDArrayFloat: """ Return the *brightness* correlate :math:`Q`. @@ -803,7 +819,7 @@ def brightness_correlate( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` *Brightness* correlate :math:`Q`. Examples @@ -826,11 +842,11 @@ def brightness_correlate( def colourfulness_correlate( - N_c: FloatingOrArrayLike, - e_t: FloatingOrArrayLike, - a: FloatingOrArrayLike, - b: FloatingOrArrayLike, -) -> FloatingOrNDArray: + N_c: ArrayLike, + e_t: ArrayLike, + a: ArrayLike, + b: ArrayLike, +) -> NDArrayFloat: """ Return the *colourfulness* correlate :math:`M`. @@ -847,7 +863,7 @@ def colourfulness_correlate( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` *Colourfulness* correlate :math:`M`. Examples @@ -871,9 +887,9 @@ def colourfulness_correlate( def chroma_correlate( - M: FloatingOrArrayLike, - A_w: FloatingOrArrayLike, -) -> FloatingOrNDArray: + M: ArrayLike, + A_w: ArrayLike, +) -> NDArrayFloat: """ Return the *chroma* correlate :math:`C`. @@ -886,7 +902,7 @@ def chroma_correlate( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` *Chroma* correlate :math:`C`. Examples @@ -906,9 +922,7 @@ def chroma_correlate( return C -def saturation_correlate( - M: FloatingOrArrayLike, Q: FloatingOrArrayLike -) -> FloatingOrNDArray: +def saturation_correlate(M: ArrayLike, Q: ArrayLike) -> NDArrayFloat: """ Return the *saturation* correlate :math:`s`. @@ -921,7 +935,7 @@ def saturation_correlate( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` *Saturation* correlate :math:`s`. Examples @@ -942,10 +956,10 @@ def saturation_correlate( def P_p( - N_c: FloatingOrArrayLike, - e_t: FloatingOrArrayLike, - A: FloatingOrArrayLike, -) -> NDArray: + N_c: ArrayLike, + e_t: ArrayLike, + A: ArrayLike, +) -> NDArrayFloat: """ Return the points :math:`P'_1` and :math:`P'_2`. @@ -985,8 +999,8 @@ def P_p( def hue_angle_dependency_Hellwig2022( - h: FloatingOrArrayLike, -) -> FloatingOrNDArray: + h: ArrayLike, +) -> NDArrayFloat: """ Compute the hue angle dependency of the *Helmholtz-Kohlrausch* effect. @@ -997,7 +1011,7 @@ def hue_angle_dependency_Hellwig2022( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Hue angle dependency. References diff --git a/colour/appearance/hke.py b/colour/appearance/hke.py index 38874710b3..4b48de8265 100644 --- a/colour/appearance/hke.py +++ b/colour/appearance/hke.py @@ -28,13 +28,7 @@ import numpy as np from colour.algebra import spow -from colour.hints import ( - ArrayLike, - FloatingOrArrayLike, - FloatingOrNDArray, - Literal, - Union, -) +from colour.hints import ArrayLike, NDArrayFloat, Literal, Union from colour.utilities import ( CanonicalMapping, as_float_array, @@ -76,9 +70,9 @@ def HelmholtzKohlrausch_effect_object_Nayatani1997( uv: ArrayLike, uv_c: ArrayLike, - L_a: FloatingOrArrayLike, + L_a: ArrayLike, method: Union[Literal["VAC", "VCC"], str] = "VCC", -) -> FloatingOrNDArray: +) -> NDArrayFloat: """ Return the *HKE* value for object colours using *Nayatani (1997)* method. @@ -95,7 +89,7 @@ def HelmholtzKohlrausch_effect_object_Nayatani1997( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Luminance factor (:math:`\\Gamma`) value(s) computed with Nayatani object colour estimation method. @@ -133,9 +127,9 @@ def HelmholtzKohlrausch_effect_object_Nayatani1997( def HelmholtzKohlrausch_effect_luminous_Nayatani1997( uv: ArrayLike, uv_c: ArrayLike, - L_a: FloatingOrArrayLike, + L_a: ArrayLike, method: Union[Literal["VAC", "VCC"], str] = "VCC", -) -> FloatingOrNDArray: +) -> NDArrayFloat: """ Return the *HKE* factor for luminous colours using *Nayatani (1997)* method. @@ -152,7 +146,7 @@ def HelmholtzKohlrausch_effect_luminous_Nayatani1997( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Luminance factor (:math:`\\Gamma`) value(s) computed with Nayatani luminous colour estimation method. @@ -188,8 +182,8 @@ def HelmholtzKohlrausch_effect_luminous_Nayatani1997( def coefficient_q_Nayatani1997( - theta: FloatingOrArrayLike, -) -> FloatingOrNDArray: + theta: ArrayLike, +) -> NDArrayFloat: """ Return the :math:`q(\\theta)` coefficient for *Nayatani (1997)* *HKE* computations. @@ -209,7 +203,7 @@ def coefficient_q_Nayatani1997( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` :math:`q` coefficient for *Nayatani (1997)* *HKE* methods. References @@ -247,8 +241,8 @@ def coefficient_q_Nayatani1997( def coefficient_K_Br_Nayatani1997( - L_a: FloatingOrArrayLike, -) -> FloatingOrNDArray: + L_a: ArrayLike, +) -> NDArrayFloat: """ Return the :math:`K_{Br}` coefficient for *Nayatani (1997)* *HKE* computations. @@ -260,7 +254,7 @@ def coefficient_K_Br_Nayatani1997( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` :math:`K_{Br}` coefficient for *Nayatani (1997)* *HKE* methods. Notes diff --git a/colour/appearance/hunt.py b/colour/appearance/hunt.py index e30302e53a..41c35821b6 100644 --- a/colour/appearance/hunt.py +++ b/colour/appearance/hunt.py @@ -26,12 +26,9 @@ from colour.algebra import spow, vector_dot from colour.hints import ( ArrayLike, - Boolean, - Dict, - FloatingOrArrayLike, - FloatingOrNDArray, - NDArray, + NDArrayFloat, Optional, + Union, cast, ) from colour.utilities import ( @@ -165,12 +162,12 @@ def __new__(cls, N_c, N_b, N_cb=None, N_bb=None): "Projected Transparencies, Dark Surrounds" ] -HUE_DATA_FOR_HUE_QUADRATURE: Dict = { +HUE_DATA_FOR_HUE_QUADRATURE: dict = { "h_s": np.array([20.14, 90.00, 164.25, 237.53]), "e_s": np.array([0.8, 0.7, 1.0, 1.2]), } -MATRIX_XYZ_TO_HPE: NDArray = np.array( +MATRIX_XYZ_TO_HPE: NDArrayFloat = np.array( [ [0.38971, 0.68898, -0.07868], [-0.22981, 1.18340, 0.04641], @@ -182,7 +179,7 @@ def __new__(cls, N_c, N_b, N_cb=None, N_bb=None): *Hunt-Pointer-Estevez* :math:`\\rho\\gamma\\beta` colourspace matrix. """ -MATRIX_HPE_TO_XYZ: NDArray = np.linalg.inv(MATRIX_XYZ_TO_HPE) +MATRIX_HPE_TO_XYZ: NDArrayFloat = np.linalg.inv(MATRIX_XYZ_TO_HPE) """ *Hunt* colour appearance model *Hunt-Pointer-Estevez* :math:`\\rho\\gamma\\beta` colourspace to *CIE XYZ* tristimulus values matrix. @@ -221,14 +218,30 @@ class CAM_ReferenceSpecification_Hunt(MixinDataclassArithmetic): :cite:`Fairchild2013u`, :cite:`Hunt2004b` """ - J: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - C_94: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - h_S: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - s: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - Q: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - M_94: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - H: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - H_C: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) + J: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + C_94: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + h_S: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + s: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + Q: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + M_94: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + H: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + H_C: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) @dataclass @@ -268,30 +281,46 @@ class CAM_Specification_Hunt(MixinDataclassArithmetic): :cite:`Fairchild2013u`, :cite:`Hunt2004b` """ - J: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - C: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - h: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - s: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - Q: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - M: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - H: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - HC: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) + J: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + C: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + h: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + s: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + Q: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + M: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + H: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + HC: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) def XYZ_to_Hunt( XYZ: ArrayLike, XYZ_w: ArrayLike, XYZ_b: ArrayLike, - L_A: FloatingOrArrayLike, + L_A: ArrayLike, surround: InductionFactors_Hunt = VIEWING_CONDITIONS_HUNT["Normal Scenes"], - L_AS: Optional[FloatingOrArrayLike] = None, - CCT_w: Optional[FloatingOrArrayLike] = None, + L_AS: Optional[ArrayLike] = None, + CCT_w: Optional[ArrayLike] = None, XYZ_p: Optional[ArrayLike] = None, - p: Optional[FloatingOrArrayLike] = None, - S: Optional[FloatingOrArrayLike] = None, - S_w: Optional[FloatingOrArrayLike] = None, - helson_judd_effect: Boolean = False, - discount_illuminant: Boolean = True, + p: Optional[ArrayLike] = None, + S: Optional[ArrayLike] = None, + S_w: Optional[ArrayLike] = None, + helson_judd_effect: bool = False, + discount_illuminant: bool = True, ) -> CAM_Specification_Hunt: """ Compute the *Hunt* colour appearance model correlates. @@ -518,10 +547,8 @@ def XYZ_to_Hunt( # Computing the correlate of *brightness* :math:`Q`. # ------------------------------------------------------------------------- # Computing achromatic signal :math:`A`. - A = achromatic_signal(cast(FloatingOrNDArray, L_AS), S_p, S_w_p, N_bb, A_a) - A_w = achromatic_signal( - cast(FloatingOrNDArray, L_AS), S_w_p, S_w_p, N_bb, A_aw - ) + A = achromatic_signal(cast(NDArrayFloat, L_AS), S_p, S_w_p, N_bb, A_a) + A_w = achromatic_signal(cast(NDArrayFloat, L_AS), S_w_p, S_w_p, N_bb, A_aw) Q = brightness_correlate(A, A_w, M, surround.N_b) brightness_w = brightness_correlate(A_w, A_w, M_w, surround.N_b) @@ -555,8 +582,8 @@ def XYZ_to_Hunt( def luminance_level_adaptation_factor( - L_A: FloatingOrArrayLike, -) -> FloatingOrNDArray: + L_A: ArrayLike, +) -> NDArrayFloat: """ Return the *luminance* level adaptation factor :math:`F_L`. @@ -567,7 +594,7 @@ def luminance_level_adaptation_factor( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` *Luminance* level adaptation factor :math:`F_L` Examples @@ -586,8 +613,8 @@ def luminance_level_adaptation_factor( def illuminant_scotopic_luminance( - L_A: FloatingOrArrayLike, CCT: FloatingOrArrayLike -) -> FloatingOrNDArray: + L_A: ArrayLike, CCT: ArrayLike +) -> NDArrayFloat: """ Return the approximate scotopic luminance :math:`L_{AS}` of the illuminant. @@ -601,7 +628,7 @@ def illuminant_scotopic_luminance( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Approximate scotopic luminance :math:`L_{AS}`. Examples @@ -618,7 +645,7 @@ def illuminant_scotopic_luminance( return as_float(CCT) -def XYZ_to_rgb(XYZ: ArrayLike) -> NDArray: +def XYZ_to_rgb(XYZ: ArrayLike) -> NDArrayFloat: """ Convert from *CIE XYZ* tristimulus values to *Hunt-Pointer-Estevez* :math:`\\rho\\gamma\\beta` colourspace. @@ -643,7 +670,7 @@ def XYZ_to_rgb(XYZ: ArrayLike) -> NDArray: return vector_dot(MATRIX_XYZ_TO_HPE, XYZ) -def f_n(x: ArrayLike) -> NDArray: +def f_n(x: ArrayLike) -> NDArrayFloat: """ Define the nonlinear response function of the *Hunt* colour appearance model used to model the nonlinear behaviour of various visual responses. @@ -679,10 +706,10 @@ def chromatic_adaptation( L_A, F_L, XYZ_p: Optional[ArrayLike] = None, - p: Optional[FloatingOrArrayLike] = None, - helson_judd_effect: Boolean = False, - discount_illuminant: Boolean = True, -) -> NDArray: + p: Optional[ArrayLike] = None, + helson_judd_effect: bool = False, + discount_illuminant: bool = True, +) -> NDArrayFloat: """ Apply chromatic adaptation to given *CIE XYZ* tristimulus values. @@ -758,9 +785,11 @@ def chromatic_adaptation( # Computing chromatic adaptation factors. if not discount_illuminant: L_A_p = spow(L_A, 1 / 3) - F_rgb = cast(NDArray, (1 + L_A_p + h_rgb) / (1 + L_A_p + (1 / h_rgb))) + F_rgb = cast( + NDArrayFloat, (1 + L_A_p + h_rgb) / (1 + L_A_p + (1 / h_rgb)) + ) else: - F_rgb = ones(cast(NDArray, h_rgb).shape) + F_rgb = ones(cast(NDArrayFloat, h_rgb).shape) # Computing Helson-Judd effect parameters. if helson_judd_effect: @@ -787,8 +816,8 @@ def adjusted_reference_white_signals( rgb_p: ArrayLike, rgb_b: ArrayLike, rgb_w: ArrayLike, - p: FloatingOrArrayLike, -) -> NDArray: + p: ArrayLike, +) -> NDArrayFloat: """ Adjust the white point for simultaneous chromatic contrast. @@ -840,7 +869,7 @@ def adjusted_reference_white_signals( return rgb_w -def achromatic_post_adaptation_signal(rgb: ArrayLike) -> NDArray: +def achromatic_post_adaptation_signal(rgb: ArrayLike) -> NDArrayFloat: """ Return the achromatic post adaptation signal :math:`A` from given *Hunt-Pointer-Estevez* :math:`\\rho\\gamma\\beta` colourspace array. @@ -852,7 +881,7 @@ def achromatic_post_adaptation_signal(rgb: ArrayLike) -> NDArray: Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Achromatic post adaptation signal :math:`A`. Examples @@ -869,7 +898,7 @@ def achromatic_post_adaptation_signal(rgb: ArrayLike) -> NDArray: return A -def colour_difference_signals(rgb: ArrayLike) -> NDArray: +def colour_difference_signals(rgb: ArrayLike) -> NDArrayFloat: """ Return the colour difference signals :math:`C_1`, :math:`C_2` and :math:`C_3` from given *Hunt-Pointer-Estevez* :math:`\\rho\\gamma\\beta` @@ -903,7 +932,7 @@ def colour_difference_signals(rgb: ArrayLike) -> NDArray: return C -def hue_angle(C: FloatingOrArrayLike) -> FloatingOrNDArray: +def hue_angle(C: ArrayLike) -> NDArrayFloat: """ Return the *hue* angle :math:`h` in degrees from given colour difference signals :math:`C`. @@ -915,7 +944,7 @@ def hue_angle(C: FloatingOrArrayLike) -> FloatingOrNDArray: Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` *Hue* angle :math:`h` in degrees. Examples @@ -935,7 +964,7 @@ def hue_angle(C: FloatingOrArrayLike) -> FloatingOrNDArray: return as_float(hue) -def eccentricity_factor(hue: FloatingOrArrayLike) -> FloatingOrNDArray: +def eccentricity_factor(hue: ArrayLike) -> NDArrayFloat: """ Return eccentricity factor :math:`e_s` from given hue angle :math:`h` in degrees. @@ -947,7 +976,7 @@ def eccentricity_factor(hue: FloatingOrArrayLike) -> FloatingOrNDArray: Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Eccentricity factor :math:`e_s`. Examples @@ -969,8 +998,8 @@ def eccentricity_factor(hue: FloatingOrArrayLike) -> FloatingOrNDArray: def low_luminance_tritanopia_factor( - L_A: FloatingOrArrayLike, -) -> FloatingOrNDArray: + L_A: ArrayLike, +) -> NDArrayFloat: """ Return the low luminance tritanopia factor :math:`F_t` from given adapting field *luminance* :math:`L_A` in :math:`cd/m^2`. @@ -982,7 +1011,7 @@ def low_luminance_tritanopia_factor( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Low luminance tritanopia factor :math:`F_t`. Examples @@ -999,12 +1028,12 @@ def low_luminance_tritanopia_factor( def yellowness_blueness_response( - C: FloatingOrArrayLike, - e_s: FloatingOrArrayLike, - N_c: FloatingOrArrayLike, - N_cb: FloatingOrArrayLike, - F_t: FloatingOrArrayLike, -) -> FloatingOrNDArray: + C: ArrayLike, + e_s: ArrayLike, + N_c: ArrayLike, + N_cb: ArrayLike, + F_t: ArrayLike, +) -> NDArrayFloat: """ Return the yellowness / blueness response :math:`M_{yb}`. @@ -1023,7 +1052,7 @@ def yellowness_blueness_response( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Yellowness / blueness response :math:`M_{yb}`. Examples @@ -1054,11 +1083,11 @@ def yellowness_blueness_response( def redness_greenness_response( - C: FloatingOrArrayLike, - e_s: FloatingOrArrayLike, - N_c: FloatingOrArrayLike, - N_cb: FloatingOrArrayLike, -) -> FloatingOrNDArray: + C: ArrayLike, + e_s: ArrayLike, + N_c: ArrayLike, + N_cb: ArrayLike, +) -> NDArrayFloat: """ Return the redness / greenness response :math:`M_{yb}`. @@ -1075,7 +1104,7 @@ def redness_greenness_response( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Redness / greenness response :math:`M_{rg}`. Examples @@ -1101,8 +1130,8 @@ def redness_greenness_response( def overall_chromatic_response( - M_yb: FloatingOrArrayLike, M_rg: FloatingOrArrayLike -) -> FloatingOrNDArray: + M_yb: ArrayLike, M_rg: ArrayLike +) -> NDArrayFloat: """ Return the overall chromatic response :math:`M`. @@ -1115,7 +1144,7 @@ def overall_chromatic_response( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Overall chromatic response :math:`M`. Examples @@ -1134,9 +1163,7 @@ def overall_chromatic_response( return M -def saturation_correlate( - M: FloatingOrArrayLike, rgb_a: ArrayLike -) -> FloatingOrNDArray: +def saturation_correlate(M: ArrayLike, rgb_a: ArrayLike) -> NDArrayFloat: """ Return the *saturation* correlate :math:`s`. @@ -1150,7 +1177,7 @@ def saturation_correlate( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` *Saturation* correlate :math:`s`. Examples @@ -1170,12 +1197,12 @@ def saturation_correlate( def achromatic_signal( - L_AS: FloatingOrArrayLike, - S: FloatingOrArrayLike, - S_w: FloatingOrArrayLike, - N_bb: FloatingOrArrayLike, - A_a: FloatingOrArrayLike, -) -> FloatingOrNDArray: + L_AS: ArrayLike, + S: ArrayLike, + S_w: ArrayLike, + N_bb: ArrayLike, + A_a: ArrayLike, +) -> NDArrayFloat: """ Return the achromatic signal :math:`A`. @@ -1194,7 +1221,7 @@ def achromatic_signal( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Achromatic signal :math:`A`. Examples @@ -1238,11 +1265,11 @@ def achromatic_signal( def brightness_correlate( - A: FloatingOrArrayLike, - A_w: FloatingOrArrayLike, - M: FloatingOrArrayLike, - N_b: FloatingOrArrayLike, -) -> FloatingOrNDArray: + A: ArrayLike, + A_w: ArrayLike, + M: ArrayLike, + N_b: ArrayLike, +) -> NDArrayFloat: """ Return the *brightness* correlate :math:`Q`. @@ -1259,7 +1286,7 @@ def brightness_correlate( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` *Brightness* correlate :math:`Q`. Examples @@ -1286,11 +1313,11 @@ def brightness_correlate( def lightness_correlate( - Y_b: FloatingOrArrayLike, - Y_w: FloatingOrArrayLike, - Q: FloatingOrArrayLike, - Q_w: FloatingOrArrayLike, -) -> FloatingOrNDArray: + Y_b: ArrayLike, + Y_w: ArrayLike, + Q: ArrayLike, + Q_w: ArrayLike, +) -> NDArrayFloat: """ Return the *Lightness* correlate :math:`J`. @@ -1307,7 +1334,7 @@ def lightness_correlate( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` *Lightness* correlate :math:`J`. Examples @@ -1332,12 +1359,12 @@ def lightness_correlate( def chroma_correlate( - s: FloatingOrArrayLike, - Y_b: FloatingOrArrayLike, - Y_w: FloatingOrArrayLike, - Q: FloatingOrArrayLike, - Q_w: FloatingOrArrayLike, -) -> FloatingOrNDArray: + s: ArrayLike, + Y_b: ArrayLike, + Y_w: ArrayLike, + Q: ArrayLike, + Q_w: ArrayLike, +) -> NDArrayFloat: """ Return the *chroma* correlate :math:`C_94`. @@ -1356,7 +1383,7 @@ def chroma_correlate( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` *Chroma* correlate :math:`C_94`. Examples @@ -1388,9 +1415,7 @@ def chroma_correlate( return C_94 -def colourfulness_correlate( - F_L: FloatingOrArrayLike, C_94: FloatingOrArrayLike -) -> FloatingOrNDArray: +def colourfulness_correlate(F_L: ArrayLike, C_94: ArrayLike) -> NDArrayFloat: """ Return the *colourfulness* correlate :math:`M_94`. @@ -1403,7 +1428,7 @@ def colourfulness_correlate( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` *Colourfulness* correlate :math:`M_94`. Examples diff --git a/colour/appearance/kim2009.py b/colour/appearance/kim2009.py index 0d0134d8ee..837116cb82 100644 --- a/colour/appearance/kim2009.py +++ b/colour/appearance/kim2009.py @@ -39,12 +39,9 @@ from colour.algebra import vector_dot, spow from colour.hints import ( ArrayLike, - Boolean, - Floating, - FloatingOrArrayLike, - FloatingOrNDArray, - NDArray, + NDArrayFloat, Optional, + Union, ) from colour.utilities import ( CanonicalMapping, @@ -211,24 +208,40 @@ class CAM_Specification_Kim2009(MixinDataclassArithmetic): :cite:`Kim2009` """ - J: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - C: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - h: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - s: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - Q: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - M: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - H: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - HC: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) + J: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + C: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + h: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + s: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + Q: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + M: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + H: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + HC: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) def XYZ_to_Kim2009( XYZ: ArrayLike, XYZ_w: ArrayLike, - L_A: FloatingOrArrayLike, + L_A: ArrayLike, media: MediaParameters_Kim2009 = MEDIA_PARAMETERS_KIM2009["CRT Displays"], surround: InductionFactors_Kim2009 = VIEWING_CONDITIONS_KIM2009["Average"], - discount_illuminant: Boolean = False, - n_c: Floating = 0.57, + discount_illuminant: bool = False, + n_c: float = 0.57, ) -> CAM_Specification_Kim2009: """ Compute the *Kim, Weyrich and Kautz (2009)* colour appearance model @@ -390,12 +403,12 @@ def XYZ_to_Kim2009( def Kim2009_to_XYZ( specification: CAM_Specification_Kim2009, XYZ_w: ArrayLike, - L_A: FloatingOrArrayLike, + L_A: ArrayLike, media: MediaParameters_Kim2009 = MEDIA_PARAMETERS_KIM2009["CRT Displays"], surround: InductionFactors_Kim2009 = VIEWING_CONDITIONS_KIM2009["Average"], - discount_illuminant: Boolean = False, - n_c: Floating = 0.57, -) -> NDArray: + discount_illuminant: bool = False, + n_c: float = 0.57, +) -> NDArrayFloat: """ Convert from *Kim, Weyrich and Kautz (2009)* specification to *CIE XYZ* tristimulus values. diff --git a/colour/appearance/llab.py b/colour/appearance/llab.py index ec21a1208d..baaa204dc4 100644 --- a/colour/appearance/llab.py +++ b/colour/appearance/llab.py @@ -38,10 +38,9 @@ ) from colour.hints import ( ArrayLike, - FloatingOrArrayLike, - FloatingOrNDArray, - NDArray, + NDArrayFloat, Optional, + Union, ) from colour.utilities import ( CanonicalMapping, @@ -156,7 +155,7 @@ class InductionFactors_LLAB( "35mm Projection Transparency, Dark Surround" ] -MATRIX_XYZ_TO_RGB_LLAB: NDArray = np.array( +MATRIX_XYZ_TO_RGB_LLAB: NDArrayFloat = np.array( [ [0.8951, 0.2664, -0.1614], [-0.7502, 1.7135, 0.0367], @@ -168,7 +167,7 @@ class InductionFactors_LLAB( cone responses matrix. """ -MATRIX_RGB_TO_XYZ_LLAB: NDArray = np.linalg.inv(MATRIX_XYZ_TO_RGB_LLAB) +MATRIX_RGB_TO_XYZ_LLAB: NDArrayFloat = np.linalg.inv(MATRIX_XYZ_TO_RGB_LLAB) """ LLAB(l:c) colour appearance model normalised cone responses to *CIE XYZ* tristimulus values matrix. @@ -208,14 +207,30 @@ class CAM_ReferenceSpecification_LLAB(MixinDataclassArithmetic): :cite:`Fairchild2013x`, :cite:`Luo1996b`, :cite:`Luo1996c` """ - L_L: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - Ch_L: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - h_L: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - s_L: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - C_L: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - HC: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - A_L: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - B_L: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) + L_L: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + Ch_L: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + h_L: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + s_L: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + C_L: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + HC: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + A_L: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + B_L: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) @dataclass @@ -255,21 +270,37 @@ class CAM_Specification_LLAB(MixinDataclassArithmetic): :cite:`Fairchild2013x`, :cite:`Luo1996b`, :cite:`Luo1996c` """ - J: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - C: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - h: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - s: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - M: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - HC: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - a: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - b: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) + J: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + C: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + h: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + s: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + M: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + HC: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + a: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + b: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) def XYZ_to_LLAB( XYZ: ArrayLike, XYZ_0: ArrayLike, - Y_b: FloatingOrArrayLike, - L: FloatingOrArrayLike, + Y_b: ArrayLike, + L: ArrayLike, surround: InductionFactors_LLAB = VIEWING_CONDITIONS_LLAB[ "Reference Samples & Images, Average Surround, Subtending < 4" ], @@ -385,7 +416,7 @@ def XYZ_to_LLAB( ) -def XYZ_to_RGB_LLAB(XYZ: ArrayLike) -> NDArray: +def XYZ_to_RGB_LLAB(XYZ: ArrayLike) -> NDArrayFloat: """ Convert from *CIE XYZ* tristimulus values to normalised cone responses. @@ -416,9 +447,9 @@ def chromatic_adaptation( RGB: ArrayLike, RGB_0: ArrayLike, RGB_0r: ArrayLike, - Y: FloatingOrArrayLike, - D: FloatingOrArrayLike = 1, -) -> NDArray: + Y: ArrayLike, + D: ArrayLike = 1, +) -> NDArrayFloat: """ Apply chromatic adaptation to given *RGB* normalised cone responses array. @@ -473,7 +504,7 @@ def chromatic_adaptation( return XYZ_r -def f(x: FloatingOrArrayLike, F_S: FloatingOrArrayLike) -> FloatingOrNDArray: +def f(x: ArrayLike, F_S: ArrayLike) -> NDArrayFloat: """ Define the nonlinear response function of the *:math:`LLAB(l:c)`* colour appearance model used to model the nonlinear behaviour of various visual @@ -488,7 +519,7 @@ def f(x: FloatingOrArrayLike, F_S: FloatingOrArrayLike) -> FloatingOrNDArray: Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Modeled visual response variable :math:`x`. Examples @@ -514,10 +545,10 @@ def f(x: FloatingOrArrayLike, F_S: FloatingOrArrayLike) -> FloatingOrNDArray: def opponent_colour_dimensions( XYZ: ArrayLike, - Y_b: FloatingOrArrayLike, - F_S: FloatingOrArrayLike, - F_L: FloatingOrArrayLike, -) -> NDArray: + Y_b: ArrayLike, + F_S: ArrayLike, + F_L: ArrayLike, +) -> NDArrayFloat: """ Return opponent colour dimensions from given adapted *CIE XYZ* tristimulus values. @@ -569,9 +600,7 @@ def opponent_colour_dimensions( return Lab -def hue_angle( - a: FloatingOrArrayLike, b: FloatingOrArrayLike -) -> FloatingOrNDArray: +def hue_angle(a: ArrayLike, b: ArrayLike) -> NDArrayFloat: """ Return the *hue* angle :math:`h_L` in degrees. @@ -584,7 +613,7 @@ def hue_angle( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` *Hue* angle :math:`h_L` in degrees. Examples @@ -601,9 +630,7 @@ def hue_angle( return as_float(h_L) -def chroma_correlate( - a: FloatingOrArrayLike, b: FloatingOrArrayLike -) -> FloatingOrNDArray: +def chroma_correlate(a: ArrayLike, b: ArrayLike) -> NDArrayFloat: """ Return the correlate of *chroma* :math:`Ch_L`. @@ -616,7 +643,7 @@ def chroma_correlate( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Correlate of *chroma* :math:`Ch_L`. Examples @@ -637,11 +664,11 @@ def chroma_correlate( def colourfulness_correlate( - L: FloatingOrArrayLike, - L_L: FloatingOrArrayLike, - Ch_L: FloatingOrArrayLike, - F_C: FloatingOrArrayLike, -) -> FloatingOrNDArray: + L: ArrayLike, + L_L: ArrayLike, + Ch_L: ArrayLike, + F_C: ArrayLike, +) -> NDArrayFloat: """ Return the correlate of *colourfulness* :math:`C_L`. @@ -658,7 +685,7 @@ def colourfulness_correlate( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Correlate of *colourfulness* :math:`C_L`. Examples @@ -683,9 +710,7 @@ def colourfulness_correlate( return as_float(C_L) -def saturation_correlate( - Ch_L: FloatingOrArrayLike, L_L: FloatingOrArrayLike -) -> FloatingOrNDArray: +def saturation_correlate(Ch_L: ArrayLike, L_L: ArrayLike) -> NDArrayFloat: """ Return the correlate of *saturation* :math:`S_L`. @@ -698,7 +723,7 @@ def saturation_correlate( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Correlate of *saturation* :math:`S_L`. Examples @@ -717,9 +742,7 @@ def saturation_correlate( return S_L -def final_opponent_signals( - C_L: FloatingOrArrayLike, h_L: FloatingOrArrayLike -) -> NDArray: +def final_opponent_signals(C_L: ArrayLike, h_L: ArrayLike) -> NDArrayFloat: """ Return the final opponent signals :math:`A_L` and :math:`B_L`. diff --git a/colour/appearance/nayatani95.py b/colour/appearance/nayatani95.py index 10fb16a865..d4583aaf33 100644 --- a/colour/appearance/nayatani95.py +++ b/colour/appearance/nayatani95.py @@ -32,10 +32,9 @@ ) from colour.hints import ( ArrayLike, - FloatingOrArrayLike, - FloatingOrNDArray, - NDArray, + NDArrayFloat, Optional, + Union, cast, ) from colour.models import XYZ_to_xy @@ -81,7 +80,7 @@ "chromatic_strength_function", ] -MATRIX_XYZ_TO_RGB_NAYATANI95: NDArray = MATRIX_XYZ_TO_RGB_CIE1994 +MATRIX_XYZ_TO_RGB_NAYATANI95: NDArrayFloat = MATRIX_XYZ_TO_RGB_CIE1994 """ *Nayatani (1995)* colour appearance model *CIE XYZ* tristimulus values to cone responses matrix. @@ -123,15 +122,33 @@ class CAM_ReferenceSpecification_Nayatani95(MixinDataclassArithmetic): :cite:`Fairchild2013ba`, :cite:`Nayatani1995a` """ - L_star_P: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - C: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - theta: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - S: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - B_r: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - M: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - H: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - H_C: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - L_star_N: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) + L_star_P: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + C: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + theta: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + S: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + B_r: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + M: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + H: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + H_C: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + L_star_N: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) @dataclass @@ -173,24 +190,42 @@ class CAM_Specification_Nayatani95(MixinDataclassArithmetic): :cite:`Fairchild2013ba`, :cite:`Nayatani1995a` """ - L_star_P: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - C: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - h: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - s: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - Q: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - M: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - H: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - HC: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - L_star_N: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) + L_star_P: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + C: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + h: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + s: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + Q: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + M: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + H: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + HC: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + L_star_N: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) def XYZ_to_Nayatani95( XYZ: ArrayLike, XYZ_n: ArrayLike, - Y_o: FloatingOrArrayLike, - E_o: FloatingOrArrayLike, - E_or: FloatingOrArrayLike, - n: FloatingOrArrayLike = 1, + Y_o: ArrayLike, + E_o: ArrayLike, + E_or: ArrayLike, + n: ArrayLike = 1, ) -> CAM_Specification_Nayatani95: """ Compute the *Nayatani (1995)* colour appearance model correlates. @@ -345,9 +380,7 @@ def XYZ_to_Nayatani95( ) -def illuminance_to_luminance( - E: FloatingOrArrayLike, Y_f: FloatingOrArrayLike -) -> FloatingOrNDArray: +def illuminance_to_luminance(E: ArrayLike, Y_f: ArrayLike) -> NDArrayFloat: """ Convert given *illuminance* :math:`E` value in lux to *luminance* in :math:`cd/m^2`. @@ -361,7 +394,7 @@ def illuminance_to_luminance( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` *Luminance* :math:`Y` in :math:`cd/m^2`. Examples @@ -376,7 +409,7 @@ def illuminance_to_luminance( return Y_f * E / (100 * np.pi) -def XYZ_to_RGB_Nayatani95(XYZ: ArrayLike) -> NDArray: +def XYZ_to_RGB_Nayatani95(XYZ: ArrayLike) -> NDArrayFloat: """ Convert from *CIE XYZ* tristimulus values to cone responses. @@ -400,9 +433,7 @@ def XYZ_to_RGB_Nayatani95(XYZ: ArrayLike) -> NDArray: return vector_dot(MATRIX_XYZ_TO_RGB_NAYATANI95, XYZ) -def scaling_coefficient( - x: FloatingOrArrayLike, y: FloatingOrArrayLike -) -> FloatingOrNDArray: +def scaling_coefficient(x: ArrayLike, y: ArrayLike) -> NDArrayFloat: """ Return the scaling coefficient :math:`e(R)` or :math:`e(G)`. @@ -415,7 +446,7 @@ def scaling_coefficient( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Scaling coefficient :math:`e(R)` or :math:`e(G)`. Examples @@ -436,11 +467,11 @@ def achromatic_response( RGB: ArrayLike, bRGB_o: ArrayLike, xez: ArrayLike, - bL_or: FloatingOrArrayLike, - eR: FloatingOrArrayLike, - eG: FloatingOrArrayLike, - n: FloatingOrArrayLike = 1, -) -> FloatingOrNDArray: + bL_or: ArrayLike, + eR: ArrayLike, + eG: ArrayLike, + n: ArrayLike = 1, +) -> NDArrayFloat: """ Return the achromatic response :math:`Q` from given stimulus cone responses. @@ -466,7 +497,7 @@ def achromatic_response( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Achromatic response :math:`Q`. Examples @@ -498,8 +529,8 @@ def achromatic_response( def tritanopic_response( - RGB: ArrayLike, bRGB_o: ArrayLike, xez: ArrayLike, n: FloatingOrArrayLike -) -> FloatingOrNDArray: + RGB: ArrayLike, bRGB_o: ArrayLike, xez: ArrayLike, n: ArrayLike +) -> NDArrayFloat: """ Return the tritanopic response :math:`t` from given stimulus cone responses. @@ -518,7 +549,7 @@ def tritanopic_response( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Tritanopic response :math:`t`. Examples @@ -543,8 +574,8 @@ def tritanopic_response( def protanopic_response( - RGB: ArrayLike, bRGB_o: ArrayLike, xez: ArrayLike, n: FloatingOrArrayLike -) -> FloatingOrNDArray: + RGB: ArrayLike, bRGB_o: ArrayLike, xez: ArrayLike, n: ArrayLike +) -> NDArrayFloat: """ Return the protanopic response :math:`p` from given stimulus cone responses. @@ -563,7 +594,7 @@ def protanopic_response( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Protanopic response :math:`p`. Examples @@ -588,8 +619,8 @@ def protanopic_response( def brightness_correlate( - bRGB_o: ArrayLike, bL_or: FloatingOrArrayLike, Q: FloatingOrArrayLike -) -> FloatingOrNDArray: + bRGB_o: ArrayLike, bL_or: ArrayLike, Q: ArrayLike +) -> NDArrayFloat: """ Return the *brightness* correlate :math:`B_r`. @@ -606,7 +637,7 @@ def brightness_correlate( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` *Brightness* correlate :math:`B_r`. Examples @@ -630,9 +661,9 @@ def brightness_correlate( def ideal_white_brightness_correlate( bRGB_o: ArrayLike, xez: ArrayLike, - bL_or: FloatingOrArrayLike, - n: FloatingOrArrayLike, -) -> FloatingOrNDArray: + bL_or: ArrayLike, + n: ArrayLike, +) -> NDArrayFloat: """ Return the ideal white *brightness* correlate :math:`B_{rw}`. @@ -651,7 +682,7 @@ def ideal_white_brightness_correlate( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Ideal white *brightness* correlate :math:`B_{rw}`. Examples @@ -679,8 +710,8 @@ def ideal_white_brightness_correlate( def achromatic_lightness_correlate( - Q: FloatingOrArrayLike, -) -> FloatingOrNDArray: + Q: ArrayLike, +) -> NDArrayFloat: """ Return the *achromatic Lightness* correlate :math:`L_p^\\star`. @@ -691,7 +722,7 @@ def achromatic_lightness_correlate( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` *Achromatic Lightness* correlate :math:`L_p^\\star`. Examples @@ -707,8 +738,8 @@ def achromatic_lightness_correlate( def normalised_achromatic_lightness_correlate( - B_r: FloatingOrArrayLike, B_rw: FloatingOrArrayLike -) -> FloatingOrNDArray: + B_r: ArrayLike, B_rw: ArrayLike +) -> NDArrayFloat: """ Return the *normalised achromatic Lightness* correlate :math:`L_n^\\star`. @@ -721,7 +752,7 @@ def normalised_achromatic_lightness_correlate( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` *Normalised achromatic Lightness* correlate :math:`L_n^\\star`. Examples @@ -739,9 +770,7 @@ def normalised_achromatic_lightness_correlate( return as_float(100 * B_r / B_rw) -def hue_angle( - p: FloatingOrArrayLike, t: FloatingOrArrayLike -) -> FloatingOrNDArray: +def hue_angle(p: ArrayLike, t: ArrayLike) -> NDArrayFloat: """ Return the *hue* angle :math:`h` in degrees. @@ -754,7 +783,7 @@ def hue_angle( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` *Hue* angle :math:`h` in degrees. Examples @@ -774,8 +803,8 @@ def hue_angle( def chromatic_strength_function( - theta: FloatingOrArrayLike, -) -> FloatingOrNDArray: + theta: ArrayLike, +) -> NDArrayFloat: """ Define the chromatic strength function :math:`E_s(\\theta)` used to correct saturation scale as function of hue angle :math:`\\theta` in @@ -788,7 +817,7 @@ def chromatic_strength_function( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Corrected saturation scale. Examples @@ -800,7 +829,7 @@ def chromatic_strength_function( theta = np.radians(theta) - E_s = cast(NDArray, 0.9394) + E_s = cast(NDArrayFloat, 0.9394) E_s += -0.2478 * np.sin(1 * theta) E_s += -0.0743 * np.sin(2 * theta) E_s += +0.0666 * np.sin(3 * theta) @@ -814,11 +843,11 @@ def chromatic_strength_function( def saturation_components( - h: FloatingOrArrayLike, - bL_or: FloatingOrArrayLike, - t: FloatingOrArrayLike, - p: FloatingOrArrayLike, -) -> NDArray: + h: ArrayLike, + bL_or: ArrayLike, + t: ArrayLike, + p: ArrayLike, +) -> NDArrayFloat: """ Return the *saturation* components :math:`S_{RG}` and :math:`S_{YB}`. @@ -861,9 +890,7 @@ def saturation_components( return tstack([S_RG, S_YB]) -def saturation_correlate( - S_RG: FloatingOrArrayLike, S_YB: FloatingOrArrayLike -) -> FloatingOrNDArray: +def saturation_correlate(S_RG: ArrayLike, S_YB: ArrayLike) -> NDArrayFloat: """ Return the correlate of *saturation* :math:`S`. @@ -876,7 +903,7 @@ def saturation_correlate( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Correlate of *saturation* :math:`S`. Examples @@ -896,10 +923,10 @@ def saturation_correlate( def chroma_components( - L_star_P: FloatingOrArrayLike, - S_RG: FloatingOrArrayLike, - S_YB: FloatingOrArrayLike, -) -> NDArray: + L_star_P: ArrayLike, + S_RG: ArrayLike, + S_YB: ArrayLike, +) -> NDArrayFloat: """ Return the *chroma* components :math:`C_{RG}` and :math:`C_{YB}`. @@ -936,9 +963,7 @@ def chroma_components( return tstack([C_RG, C_YB]) -def chroma_correlate( - L_star_P: FloatingOrArrayLike, S: FloatingOrArrayLike -) -> FloatingOrNDArray: +def chroma_correlate(L_star_P: ArrayLike, S: ArrayLike) -> NDArrayFloat: """ Return the correlate of *chroma* :math:`C`. @@ -951,7 +976,7 @@ def chroma_correlate( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Correlate of *chroma* :math:`C`. Examples @@ -971,10 +996,10 @@ def chroma_correlate( def colourfulness_components( - C_RG: FloatingOrArrayLike, - C_YB: FloatingOrArrayLike, - B_rw: FloatingOrArrayLike, -) -> NDArray: + C_RG: ArrayLike, + C_YB: ArrayLike, + B_rw: ArrayLike, +) -> NDArrayFloat: """ Return the *colourfulness* components :math:`M_{RG}` and :math:`M_{YB}`. @@ -989,7 +1014,7 @@ def colourfulness_components( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` *Colourfulness* components :math:`M_{RG}` and :math:`M_{YB}`. Examples @@ -1011,9 +1036,7 @@ def colourfulness_components( return tstack([M_RG, M_YB]) -def colourfulness_correlate( - C: FloatingOrArrayLike, B_rw: FloatingOrArrayLike -) -> FloatingOrNDArray: +def colourfulness_correlate(C: ArrayLike, B_rw: ArrayLike) -> NDArrayFloat: """ Return the correlate of *colourfulness* :math:`M`. @@ -1026,7 +1049,7 @@ def colourfulness_correlate( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Correlate of *colourfulness* :math:`M`. Examples diff --git a/colour/appearance/rlab.py b/colour/appearance/rlab.py index 8fba89ae97..61470002dc 100644 --- a/colour/appearance/rlab.py +++ b/colour/appearance/rlab.py @@ -27,10 +27,9 @@ from colour.appearance.hunt import MATRIX_XYZ_TO_HPE, XYZ_to_rgb from colour.hints import ( ArrayLike, - FloatingOrArrayLike, - FloatingOrNDArray, - NDArray, + NDArrayFloat, Optional, + Union, ) from colour.utilities import ( CanonicalMapping, @@ -59,7 +58,7 @@ "XYZ_to_RLAB", ] -MATRIX_R: NDArray = np.array( +MATRIX_R: NDArrayFloat = np.array( [ [1.9569, -1.1882, 0.2313], [0.3612, 0.6388, 0.0000], @@ -136,13 +135,27 @@ class CAM_ReferenceSpecification_RLAB(MixinDataclassArray): :cite:`Fairchild1996a`, :cite:`Fairchild2013w` """ - LR: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - CR: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - hR: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - sR: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - HR: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - aR: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - bR: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) + LR: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + CR: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + hR: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + sR: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + HR: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + aR: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + bR: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) @dataclass @@ -180,21 +193,21 @@ class CAM_Specification_RLAB(MixinDataclassArray): :cite:`Fairchild1996a`, :cite:`Fairchild2013w` """ - J: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - C: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - h: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - s: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - HC: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - a: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - b: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) + J: Optional[NDArrayFloat] = field(default_factory=lambda: None) + C: Optional[NDArrayFloat] = field(default_factory=lambda: None) + h: Optional[NDArrayFloat] = field(default_factory=lambda: None) + s: Optional[NDArrayFloat] = field(default_factory=lambda: None) + HC: Optional[NDArrayFloat] = field(default_factory=lambda: None) + a: Optional[NDArrayFloat] = field(default_factory=lambda: None) + b: Optional[NDArrayFloat] = field(default_factory=lambda: None) def XYZ_to_RLAB( XYZ: ArrayLike, XYZ_n: ArrayLike, - Y_n: FloatingOrArrayLike, - sigma: FloatingOrArrayLike = VIEWING_CONDITIONS_RLAB["Average"], - D: FloatingOrArrayLike = D_FACTOR_RLAB["Hard Copy Images"], + Y_n: ArrayLike, + sigma: ArrayLike = VIEWING_CONDITIONS_RLAB["Average"], + D: ArrayLike = D_FACTOR_RLAB["Hard Copy Images"], ) -> CAM_Specification_RLAB: """ Compute the *RLAB* model color appearance correlates. diff --git a/colour/appearance/zcam.py b/colour/appearance/zcam.py index ba3c7846e5..00c0caed89 100644 --- a/colour/appearance/zcam.py +++ b/colour/appearance/zcam.py @@ -40,12 +40,9 @@ from colour.colorimetry import CCS_ILLUMINANTS from colour.hints import ( ArrayLike, - Boolean, - Dict, - FloatingOrArrayLike, - FloatingOrNDArray, - NDArray, + NDArrayFloat, Optional, + Union, ) from colour.models import Izazbz_to_XYZ, XYZ_to_Izazbz, xy_to_XYZ from colour.utilities import ( @@ -130,7 +127,7 @@ class InductionFactors_ZCAM( :cite:`Safdar2021` """ -HUE_DATA_FOR_HUE_QUADRATURE: Dict = { +HUE_DATA_FOR_HUE_QUADRATURE: dict = { "h_i": np.array([33.44, 89.29, 146.30, 238.36, 393.44]), "e_i": np.array([0.68, 0.64, 1.52, 0.77, 0.68]), "H_i": np.array([0.0, 100.0, 200.0, 300.0, 400.0]), @@ -175,17 +172,39 @@ class CAM_ReferenceSpecification_ZCAM(MixinDataclassArithmetic): :cite:`Safdar2021` """ - J_z: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - C_z: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - h_z: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - S_z: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - Q_z: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - M_z: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - H: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - H_z: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - V_z: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - K_z: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - W_z: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) + J_z: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + C_z: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + h_z: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + S_z: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + Q_z: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + M_z: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + H: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + H_z: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + V_z: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + K_z: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + W_z: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) @dataclass @@ -291,20 +310,42 @@ class CAM_Specification_ZCAM(MixinDataclassArithmetic): :cite:`Safdar2021` """ - J: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - C: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - h: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - s: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - Q: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - M: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - H: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - HC: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - V: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - K: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) - W: Optional[FloatingOrNDArray] = field(default_factory=lambda: None) + J: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + C: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + h: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + s: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + Q: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + M: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + H: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + HC: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + V: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + K: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) + W: Optional[Union[float, NDArrayFloat]] = field( + default_factory=lambda: None + ) -TVS_D65: NDArray = xy_to_XYZ( +TVS_D65: NDArrayFloat = xy_to_XYZ( CCS_ILLUMINANTS["CIE 1931 2 Degree Standard Observer"]["D65"] ) @@ -312,10 +353,10 @@ class CAM_Specification_ZCAM(MixinDataclassArithmetic): def XYZ_to_ZCAM( XYZ: ArrayLike, XYZ_w: ArrayLike, - L_A: FloatingOrArrayLike, - Y_b: FloatingOrArrayLike, + L_A: ArrayLike, + Y_b: ArrayLike, surround: InductionFactors_ZCAM = VIEWING_CONDITIONS_ZCAM["Average"], - discount_illuminant: Boolean = False, + discount_illuminant: bool = False, ) -> CAM_Specification_ZCAM: """ Compute the *ZCAM* colour appearance model correlates from given *CIE XYZ* @@ -522,11 +563,11 @@ def XYZ_to_ZCAM( def ZCAM_to_XYZ( specification: CAM_Specification_ZCAM, XYZ_w: ArrayLike, - L_A: FloatingOrArrayLike, - Y_b: FloatingOrArrayLike, + L_A: ArrayLike, + Y_b: ArrayLike, surround: InductionFactors_ZCAM = VIEWING_CONDITIONS_ZCAM["Average"], - discount_illuminant: Boolean = False, -) -> NDArray: + discount_illuminant: bool = False, +) -> NDArrayFloat: """ Convert from *ZCAM* specification to *CIE XYZ* tristimulus values. @@ -736,7 +777,7 @@ def ZCAM_to_XYZ( return from_range_1(XYZ) -def hue_quadrature(h: FloatingOrArrayLike) -> FloatingOrNDArray: +def hue_quadrature(h: ArrayLike) -> NDArrayFloat: """ Return the hue quadrature from given hue :math:`h` angle in degrees. @@ -747,7 +788,7 @@ def hue_quadrature(h: FloatingOrArrayLike) -> FloatingOrNDArray: Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Hue quadrature. Examples diff --git a/colour/biochemistry/__init__.py b/colour/biochemistry/__init__.py index 11b21f7361..e991b94072 100644 --- a/colour/biochemistry/__init__.py +++ b/colour/biochemistry/__init__.py @@ -60,9 +60,7 @@ def __getattr__(self, attribute) -> Any: """Defines the *colour.biochemistry* sub-package API changes.""" if not is_documentation_building(): - sys.modules[ - "colour.biochemistry" - ] = biochemistry( # type:ignore[assignment] + sys.modules["colour.biochemistry"] = biochemistry( # pyright: ignore sys.modules["colour.biochemistry"], build_API_changes(API_CHANGES) ) diff --git a/colour/biochemistry/michaelis_menten.py b/colour/biochemistry/michaelis_menten.py index 3864fe748d..3d69e749f2 100644 --- a/colour/biochemistry/michaelis_menten.py +++ b/colour/biochemistry/michaelis_menten.py @@ -29,8 +29,8 @@ from colour.hints import ( Any, - FloatingOrArrayLike, - FloatingOrNDArray, + ArrayLike, + NDArrayFloat, Literal, Union, ) @@ -62,10 +62,10 @@ def reaction_rate_MichaelisMenten_Michaelis1913( - S: FloatingOrArrayLike, - V_max: FloatingOrArrayLike, - K_m: FloatingOrArrayLike, -) -> FloatingOrNDArray: + S: ArrayLike, + V_max: ArrayLike, + K_m: ArrayLike, +) -> NDArrayFloat: """ Describe the rate of enzymatic reactions, by relating reaction rate :math:`v` to concentration of a substrate :math:`S`. @@ -83,7 +83,7 @@ def reaction_rate_MichaelisMenten_Michaelis1913( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Reaction rate :math:`v`. References @@ -106,11 +106,11 @@ def reaction_rate_MichaelisMenten_Michaelis1913( def reaction_rate_MichaelisMenten_Abebe2017( - S: FloatingOrArrayLike, - V_max: FloatingOrArrayLike, - K_m: FloatingOrArrayLike, - b_m: FloatingOrArrayLike, -) -> FloatingOrNDArray: + S: ArrayLike, + V_max: ArrayLike, + K_m: ArrayLike, + b_m: ArrayLike, +) -> NDArrayFloat: """ Describe the rate of enzymatic reactions, by relating reaction rate :math:`v` to concentration of a substrate :math:`S` according to the @@ -133,7 +133,7 @@ def reaction_rate_MichaelisMenten_Abebe2017( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Reaction rate :math:`v`. References @@ -174,14 +174,14 @@ def reaction_rate_MichaelisMenten_Abebe2017( def reaction_rate_MichaelisMenten( - S: FloatingOrArrayLike, - V_max: FloatingOrArrayLike, - K_m: FloatingOrArrayLike, + S: ArrayLike, + V_max: ArrayLike, + K_m: ArrayLike, method: Union[ Literal["Michaelis 1913", "Abebe 2017"], str ] = "Michaelis 1913", **kwargs: Any, -) -> FloatingOrNDArray: +) -> NDArrayFloat: """ Describe the rate of enzymatic reactions, by relating reaction rate :math:`v` to concentration of a substrate :math:`S` according to given @@ -208,7 +208,7 @@ def reaction_rate_MichaelisMenten( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Reaction rate :math:`v`. References @@ -233,10 +233,10 @@ def reaction_rate_MichaelisMenten( def substrate_concentration_MichaelisMenten_Michaelis1913( - v: FloatingOrArrayLike, - V_max: FloatingOrArrayLike, - K_m: FloatingOrArrayLike, -) -> FloatingOrNDArray: + v: ArrayLike, + V_max: ArrayLike, + K_m: ArrayLike, +) -> NDArrayFloat: """ Describe the rate of enzymatic reactions, by relating concentration of a substrate :math:`S` to reaction rate :math:`v`. @@ -254,7 +254,7 @@ def substrate_concentration_MichaelisMenten_Michaelis1913( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Concentration of a substrate :math:`S`. References @@ -278,11 +278,11 @@ def substrate_concentration_MichaelisMenten_Michaelis1913( def substrate_concentration_MichaelisMenten_Abebe2017( - v: FloatingOrArrayLike, - V_max: FloatingOrArrayLike, - K_m: FloatingOrArrayLike, - b_m: FloatingOrArrayLike, -) -> FloatingOrNDArray: + v: ArrayLike, + V_max: ArrayLike, + K_m: ArrayLike, + b_m: ArrayLike, +) -> NDArrayFloat: """ Describe the rate of enzymatic reactions, by relating concentration of a substrate :math:`S` to reaction rate :math:`v` according to the modified @@ -304,7 +304,7 @@ def substrate_concentration_MichaelisMenten_Abebe2017( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Concentration of a substrate :math:`S`. References @@ -348,14 +348,14 @@ def substrate_concentration_MichaelisMenten_Abebe2017( def substrate_concentration_MichaelisMenten( - v: FloatingOrArrayLike, - V_max: FloatingOrArrayLike, - K_m: FloatingOrArrayLike, + v: ArrayLike, + V_max: ArrayLike, + K_m: ArrayLike, method: Union[ Literal["Michaelis 1913", "Abebe 2017"], str ] = "Michaelis 1913", **kwargs: Any, -) -> FloatingOrNDArray: +) -> NDArrayFloat: """ Describe the rate of enzymatic reactions, by relating concentration of a substrate :math:`S` to reaction rate :math:`v` according to given method. @@ -382,7 +382,7 @@ def substrate_concentration_MichaelisMenten( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Concentration of a substrate :math:`S`. References diff --git a/colour/blindness/machado2009.py b/colour/blindness/machado2009.py index acf89164e7..40522d865a 100644 --- a/colour/blindness/machado2009.py +++ b/colour/blindness/machado2009.py @@ -38,7 +38,7 @@ SpectralShape, reshape_msds, ) -from colour.hints import ArrayLike, Floating, Literal, NDArray, Union, cast +from colour.hints import ArrayLike, Literal, NDArrayFloat, Union from colour.utilities import ( as_float_array, as_int_scalar, @@ -62,7 +62,7 @@ "matrix_cvd_Machado2009", ] -MATRIX_LMS_TO_WSYBRG: NDArray = np.array( +MATRIX_LMS_TO_WSYBRG: NDArrayFloat = np.array( [ [0.600, 0.400, 0.000], [0.240, 0.105, -0.700], @@ -77,7 +77,7 @@ def matrix_RGB_to_WSYBRG( cmfs: LMS_ConeFundamentals, primaries: RGB_DisplayPrimaries -) -> NDArray: +) -> NDArrayFloat: """ Compute the matrix transforming from *RGB* colourspace to opponent-colour space using *Machado et al. (2009)* method. @@ -113,7 +113,7 @@ def matrix_RGB_to_WSYBRG( # pylint: disable=E1102 primaries = reshape_msds( - primaries, # type: ignore[assignment] + primaries, cmfs.shape, extrapolator_kwargs={"method": "Constant", "left": 0, "right": 0}, ) @@ -132,7 +132,7 @@ def matrix_RGB_to_WSYBRG( RG_G = np.trapz(G * RG, wavelengths) RG_B = np.trapz(B * RG, wavelengths) - M_G = np.array( + M_G = as_float_array( [ [WS_R, WS_G, WS_B], [YB_R, YB_G, YB_B], @@ -205,7 +205,8 @@ def msds_cmfs_anomalous_trichromacy_Machado2009( array([ 0.0891288..., 0.0870524 , 0.955393 ]) """ - cmfs = cast(LMS_ConeFundamentals, cmfs.copy()) + cmfs = cmfs.copy() + if cmfs.shape.interval != 1: cmfs.interpolate(SpectralShape(cmfs.shape.start, cmfs.shape.end, 1)) @@ -227,7 +228,7 @@ def msds_cmfs_anomalous_trichromacy_Machado2009( area_L = np.trapz(L, cmfs.wavelengths) area_M = np.trapz(M, cmfs.wavelengths) - def alpha(x: NDArray) -> NDArray: + def alpha(x: NDArrayFloat) -> NDArrayFloat: """Compute :math:`alpha` factor.""" return (20 - x) / 20 @@ -254,7 +255,7 @@ def matrix_anomalous_trichromacy_Machado2009( cmfs: LMS_ConeFundamentals, primaries: RGB_DisplayPrimaries, d_LMS: ArrayLike, -) -> NDArray: +) -> NDArrayFloat: """ Compute the *Machado et al. (2009)* *CVD* matrix for given *LMS* cone fundamentals colour matching functions and display primaries tri-spectral @@ -304,7 +305,7 @@ def matrix_anomalous_trichromacy_Machado2009( if cmfs.shape.interval != 1: # pylint: disable=E1102 cmfs = reshape_msds( - cmfs, # type: ignore[assignment] + cmfs, SpectralShape(cmfs.shape.start, cmfs.shape.end, 1), "Interpolate", ) @@ -320,8 +321,8 @@ def matrix_cvd_Machado2009( deficiency: Union[ Literal["Deuteranomaly", "Protanomaly", "Tritanomaly"], str ], - severity: Floating, -) -> NDArray: + severity: float, +) -> NDArrayFloat: """ Compute *Machado et al. (2009)* *CVD* matrix for given deficiency and severity using the pre-computed matrices dataset. diff --git a/colour/characterisation/__init__.py b/colour/characterisation/__init__.py index 79d8b0c626..09c6ca3f7f 100644 --- a/colour/characterisation/__init__.py +++ b/colour/characterisation/__init__.py @@ -109,7 +109,7 @@ def __getattr__(self, attribute) -> Any: if not is_documentation_building(): sys.modules[ "colour.characterisation" - ] = characterisation( # type: ignore[assignment] + ] = characterisation( # pyright: ignore sys.modules["colour.characterisation"], build_API_changes(API_CHANGES) ) diff --git a/colour/characterisation/aces_it.py b/colour/characterisation/aces_it.py index e7c764ee70..fe894915ed 100644 --- a/colour/characterisation/aces_it.py +++ b/colour/characterisation/aces_it.py @@ -72,16 +72,12 @@ from colour.characterisation import MSDS_ACES_RICD, RGB_CameraSensitivities from colour.hints import ( ArrayLike, - Boolean, Callable, - Dict, - Floating, - FloatingOrNDArray, + DTypeFloat, Literal, Mapping, - NDArray, + NDArrayFloat, Optional, - Tuple, Union, cast, ) @@ -133,10 +129,10 @@ "camera_RGB_to_ACES2065_1", ] -FLARE_PERCENTAGE: Floating = 0.00500 +FLARE_PERCENTAGE: float = 0.00500 """Flare percentage in the *ACES* system.""" -S_FLARE_FACTOR: Floating = 0.18000 / (0.18000 + FLARE_PERCENTAGE) +S_FLARE_FACTOR: float = 0.18000 / (0.18000 + FLARE_PERCENTAGE) """Flare modulation factor in the *ACES* system.""" @@ -163,7 +159,7 @@ def sd_to_aces_relative_exposure_values( ] ] = "CAT02", **kwargs, -) -> NDArray: +) -> NDArrayFloat: """ Convert given spectral distribution to *ACES2065-1* colourspace relative exposure values. @@ -233,9 +229,7 @@ def sd_to_aces_relative_exposure_values( **kwargs, ) - illuminant = cast( - SpectralDistribution, optional(illuminant, SDS_ILLUMINANTS["D65"]) - ) + illuminant = optional(illuminant, SDS_ILLUMINANTS["D65"]) shape = MSDS_ACES_RICD.shape if sd.shape != MSDS_ACES_RICD.shape: @@ -249,7 +243,7 @@ def sd_to_aces_relative_exposure_values( r_bar, g_bar, b_bar = tsplit(MSDS_ACES_RICD.values) - def k(x: NDArray, y: NDArray) -> NDArray: + def k(x: NDArrayFloat, y: NDArrayFloat) -> DTypeFloat: """Compute the :math:`K_r`, :math:`K_g` or :math:`K_b` scale factors.""" return 1 / np.sum(x * y) @@ -422,7 +416,7 @@ def generate_illuminants_rawtoaces_v1() -> CanonicalMapping: def white_balance_multipliers( sensitivities: RGB_CameraSensitivities, illuminant: SpectralDistribution -) -> NDArray: +) -> NDArrayFloat: """ Compute the *RGB* white balance multipliers for given camera *RGB* spectral sensitivities and illuminant. @@ -524,7 +518,7 @@ def best_illuminant( sse = sse_c illuminant_b = illuminant - return illuminant_b # type: ignore[return-value] + return cast(SpectralDistribution, illuminant_b) def normalise_illuminant( @@ -583,7 +577,7 @@ def training_data_sds_to_RGB( training_data: MultiSpectralDistributions, sensitivities: RGB_CameraSensitivities, illuminant: SpectralDistribution, -) -> Tuple[NDArray, NDArray]: +) -> tuple[NDArrayFloat, NDArrayFloat]: """ Convert given training data to *RGB* tristimulus values using given illuminant and given camera *RGB* spectral sensitivities. @@ -600,7 +594,7 @@ def training_data_sds_to_RGB( Returns ------- :class:`tuple` - Tuple of training data *RGB* tristimulus values and white balance + tuple of training data *RGB* tristimulus values and white balance multipliers. Examples @@ -678,7 +672,7 @@ def training_data_sds_to_XYZ( str, ] ] = "CAT02", -) -> NDArray: +) -> NDArrayFloat: """ Convert given training data to *CIE XYZ* tristimulus values using given illuminant and given standard observer colour matching functions. @@ -760,7 +754,7 @@ def training_data_sds_to_XYZ( return XYZ -def optimisation_factory_rawtoaces_v1() -> Tuple[Callable, Callable]: +def optimisation_factory_rawtoaces_v1() -> tuple[Callable, Callable]: """ Produce the objective function and *CIE XYZ* colourspace to optimisation colourspace/colour model function according to *RAW to ACES* v1. @@ -786,7 +780,7 @@ def optimisation_factory_rawtoaces_v1() -> Tuple[Callable, Callable]: def objective_function( M: ArrayLike, RGB: ArrayLike, Lab: ArrayLike - ) -> FloatingOrNDArray: + ) -> NDArrayFloat: """Objective function according to *RAW to ACES* v1.""" M = np.reshape(M, [3, 3]) @@ -796,9 +790,9 @@ def objective_function( ) Lab_t = XYZ_to_Lab(XYZ_t, RGB_COLOURSPACE_ACES2065_1.whitepoint) - return as_float(np.linalg.norm(Lab_t - Lab)) + return as_float(np.linalg.norm(Lab_t - as_float_array(Lab))) - def XYZ_to_optimization_colour_model(XYZ: ArrayLike) -> NDArray: + def XYZ_to_optimization_colour_model(XYZ: ArrayLike) -> NDArrayFloat: """*CIE XYZ* colourspace to *CIE L\\*a\\*b\\** colourspace function.""" return XYZ_to_Lab(XYZ, RGB_COLOURSPACE_ACES2065_1.whitepoint) @@ -806,7 +800,7 @@ def XYZ_to_optimization_colour_model(XYZ: ArrayLike) -> NDArray: return objective_function, XYZ_to_optimization_colour_model -def optimisation_factory_Jzazbz() -> Tuple[Callable, Callable]: +def optimisation_factory_Jzazbz() -> tuple[Callable, Callable]: """ Produce the objective function and *CIE XYZ* colourspace to optimisation colourspace/colour model function based on the :math:`J_za_zb_z` @@ -833,7 +827,7 @@ def optimisation_factory_Jzazbz() -> Tuple[Callable, Callable]: def objective_function( M: ArrayLike, RGB: ArrayLike, Jab: ArrayLike - ) -> FloatingOrNDArray: + ) -> NDArrayFloat: """:math:`J_za_zb_z` colourspace based objective function.""" M = np.reshape(M, [3, 3]) @@ -845,7 +839,7 @@ def objective_function( return as_float(np.sum(euclidean_distance(Jab, Jab_t))) - def XYZ_to_optimization_colour_model(XYZ: ArrayLike) -> NDArray: + def XYZ_to_optimization_colour_model(XYZ: ArrayLike) -> NDArrayFloat: """*CIE XYZ* colourspace to :math:`J_za_zb_z` colourspace function.""" return XYZ_to_Jzazbz(XYZ) @@ -859,7 +853,7 @@ def matrix_idt( training_data: Optional[MultiSpectralDistributions] = None, cmfs: Optional[MultiSpectralDistributions] = None, optimisation_factory: Callable = optimisation_factory_rawtoaces_v1, - optimisation_kwargs: Optional[Dict] = None, + optimisation_kwargs: Optional[dict] = None, chromatic_adaptation_transform: Optional[ Union[ Literal[ @@ -879,8 +873,11 @@ def matrix_idt( str, ] ] = "CAT02", - additional_data: Boolean = False, -) -> Union[Tuple[NDArray, NDArray, NDArray, NDArray], Tuple[NDArray, NDArray]]: + additional_data: bool = False, +) -> Union[ + tuple[NDArrayFloat, NDArrayFloat, NDArrayFloat, NDArrayFloat], + tuple[NDArrayFloat, NDArrayFloat], +]: """ Compute an *Input Device Transform* (IDT) matrix for given camera *RGB* spectral sensitivities, illuminant, training data, standard observer colour @@ -913,7 +910,7 @@ def matrix_idt( Returns ------- :class:`tuple` - Tuple of *Input Device Transform* (IDT) matrix and white balance + tuple of *Input Device Transform* (IDT) matrix and white balance multipliers or tuple of *Input Device Transform* (IDT) matrix, white balance multipliers, *XYZ* and *RGB* tristimulus values. @@ -975,7 +972,7 @@ def matrix_idt( f'Aligning "{sensitivities.name}" sensitivities shape to "{shape}".' ) # pylint: disable=E1102 - sensitivities = reshape_msds(sensitivities, shape) # type: ignore[assignment] + sensitivities = reshape_msds(sensitivities, shape) if training_data.shape != shape: runtime_warning( @@ -1023,8 +1020,8 @@ def camera_RGB_to_ACES2065_1( B: ArrayLike, b: ArrayLike, k: ArrayLike = np.ones(3), - clip: Boolean = False, -) -> NDArray: + clip: bool = False, +) -> NDArrayFloat: """ Convert given camera *RGB* colourspace array to *ACES2065-1* colourspace using the *Input Device Transform* (IDT) matrix :math:`B`, the white diff --git a/colour/characterisation/cameras.py b/colour/characterisation/cameras.py index 7a29cf8117..1cccfec720 100644 --- a/colour/characterisation/cameras.py +++ b/colour/characterisation/cameras.py @@ -17,16 +17,26 @@ SpectralShape, ) from colour.continuous import MultiSignals, Signal -from colour.hints import ArrayLike, Any, Optional, Sequence, Union +from colour.hints import ( + ArrayLike, + Any, + Optional, + Sequence, + TYPE_CHECKING, + Union, +) from colour.utilities import is_pandas_installed -if is_pandas_installed(): +if TYPE_CHECKING: from pandas import DataFrame, Series -else: # pragma: no cover - from unittest import mock +else: + if is_pandas_installed(): + from pandas import DataFrame, Series + else: # pragma: no cover + from unittest import mock - DataFrame = mock.MagicMock() - Series = mock.MagicMock() + DataFrame = mock.MagicMock() + Series = mock.MagicMock() __author__ = "Colour Developers" __copyright__ = "Copyright 2013 Colour Developers" diff --git a/colour/characterisation/correction.py b/colour/characterisation/correction.py index 60ae64c065..cc8bca3e22 100644 --- a/colour/characterisation/correction.py +++ b/colour/characterisation/correction.py @@ -64,10 +64,8 @@ from colour.hints import ( ArrayLike, Any, - Boolean, - Integer, Literal, - NDArray, + NDArrayFloat, Union, ) from colour.utilities import ( @@ -111,7 +109,7 @@ def matrix_augmented_Cheung2004( RGB: ArrayLike, terms: Literal[3, 5, 7, 8, 10, 11, 14, 16, 17, 19, 20, 22] = 3, -) -> NDArray: +) -> NDArrayFloat: """ Perform polynomial expansion of given *RGB* colourspace array using *Cheung et al. (2004)* method. @@ -369,8 +367,8 @@ def matrix_augmented_Cheung2004( def polynomial_expansion_Finlayson2015( RGB: ArrayLike, degree: Literal[1, 2, 3, 4] = 1, - root_polynomial_expansion: Boolean = True, -) -> NDArray: + root_polynomial_expansion: bool = True, +) -> NDArrayFloat: """ Perform polynomial expansion of given *RGB* colourspace array using *Finlayson et al. (2015)* method. @@ -558,8 +556,8 @@ def polynomial_expansion_Finlayson2015( def polynomial_expansion_Vandermonde( - a: ArrayLike, degree: Integer = 1 -) -> NDArray: + a: ArrayLike, degree: int = 1 +) -> NDArrayFloat: """ Perform polynomial expansion of given :math:`a` array using *Vandermonde* method. @@ -618,7 +616,7 @@ def polynomial_expansion( Literal["Cheung 2004", "Finlayson 2015", "Vandermonde"], str ] = "Cheung 2004", **kwargs: Any, -) -> NDArray: +) -> NDArrayFloat: """ Perform polynomial expansion of given :math:`a` array. @@ -674,7 +672,7 @@ def matrix_colour_correction_Cheung2004( M_T: ArrayLike, M_R: ArrayLike, terms: Literal[3, 5, 7, 8, 10, 11, 14, 16, 17, 19, 20, 22] = 3, -) -> NDArray: +) -> NDArrayFloat: """ Compute a colour correction matrix from given :math:`M_T` colour array to :math:`M_R` colour array using *Cheung et al. (2004)* method. @@ -717,8 +715,8 @@ def matrix_colour_correction_Finlayson2015( M_T: ArrayLike, M_R: ArrayLike, degree: Literal[1, 2, 3, 4] = 1, - root_polynomial_expansion: Boolean = True, -) -> NDArray: + root_polynomial_expansion: bool = True, +) -> NDArrayFloat: """ Compute a colour correction matrix from given :math:`M_T` colour array to :math:`M_R` colour array using *Finlayson et al. (2015)* method. @@ -763,8 +761,8 @@ def matrix_colour_correction_Finlayson2015( def matrix_colour_correction_Vandermonde( - M_T: ArrayLike, M_R: ArrayLike, degree: Integer = 1 -) -> NDArray: + M_T: ArrayLike, M_R: ArrayLike, degree: int = 1 +) -> NDArrayFloat: """ Compute a colour correction matrix from given :math:`M_T` colour array to :math:`M_R` colour array using *Vandermonde* method. @@ -827,7 +825,7 @@ def matrix_colour_correction( Literal["Cheung 2004", "Finlayson 2015", "Vandermonde"], str ] = "Cheung 2004", **kwargs: Any, -) -> NDArray: +) -> NDArrayFloat: """ Compute a colour correction matrix from given :math:`M_T` colour array to :math:`M_R` colour array. @@ -947,7 +945,7 @@ def colour_correction_Cheung2004( M_T: ArrayLike, M_R: ArrayLike, terms: Literal[3, 5, 7, 8, 10, 11, 14, 16, 17, 19, 20, 22] = 3, -) -> NDArray: +) -> NDArrayFloat: """ Perform colour correction of given *RGB* colourspace array using the colour correction matrix from given :math:`M_T` colour array to @@ -1000,8 +998,8 @@ def colour_correction_Finlayson2015( M_T: ArrayLike, M_R: ArrayLike, degree: Literal[1, 2, 3, 4] = 1, - root_polynomial_expansion: Boolean = True, -) -> NDArray: + root_polynomial_expansion: bool = True, +) -> NDArrayFloat: """ Perform colour correction of given *RGB* colourspace array using the colour correction matrix from given :math:`M_T` colour array to @@ -1056,8 +1054,8 @@ def colour_correction_Finlayson2015( def colour_correction_Vandermonde( - RGB: ArrayLike, M_T: ArrayLike, M_R: ArrayLike, degree: Integer = 1 -) -> NDArray: + RGB: ArrayLike, M_T: ArrayLike, M_R: ArrayLike, degree: int = 1 +) -> NDArrayFloat: """ Perform colour correction of given *RGB* colourspace array using the colour correction matrix from given :math:`M_T` colour array to @@ -1130,7 +1128,7 @@ def colour_correction( Literal["Cheung 2004", "Finlayson 2015", "Vandermonde"], str ] = "Cheung 2004", **kwargs: Any, -) -> NDArray: +) -> NDArrayFloat: """ Perform colour correction of given *RGB* colourspace array using the colour correction matrix from given :math:`M_T` colour array to diff --git a/colour/characterisation/datasets/aces_it.py b/colour/characterisation/datasets/aces_it.py index 494346af5f..35eeba10b5 100644 --- a/colour/characterisation/datasets/aces_it.py +++ b/colour/characterisation/datasets/aces_it.py @@ -27,7 +27,6 @@ from __future__ import annotations from colour.characterisation import RGB_CameraSensitivities -from colour.hints import Dict __author__ = "Colour Developers" __copyright__ = "Copyright 2013 Colour Developers" @@ -41,7 +40,7 @@ "MSDS_ACES_RICD", ] -DATA_ACES_RICD: Dict = { +DATA_ACES_RICD: dict = { 360.0: (1.20e-06, 0.0000000, 5.70e-06), 361.0: (1.40e-06, 0.0000000, 6.40e-06), 362.0: (1.50e-06, 0.0000000, 7.20e-06), diff --git a/colour/characterisation/datasets/cameras/dslr/sensitivities.py b/colour/characterisation/datasets/cameras/dslr/sensitivities.py index 8e1384737f..edbbd35756 100644 --- a/colour/characterisation/datasets/cameras/dslr/sensitivities.py +++ b/colour/characterisation/datasets/cameras/dslr/sensitivities.py @@ -31,7 +31,6 @@ from functools import partial from colour.characterisation import RGB_CameraSensitivities -from colour.hints import Dict from colour.utilities import LazyCanonicalMapping __author__ = "Colour Developers" @@ -46,7 +45,7 @@ "MSDS_CAMERA_SENSITIVITIES_DSLR", ] -DATA_CAMERA_SENSITIVITIES_DSLR: Dict = { +DATA_CAMERA_SENSITIVITIES_DSLR: dict = { "Nikon 5100 (NPL)": { 380.0: ( 0.00156384299336578000, diff --git a/colour/characterisation/datasets/colour_checkers/chromaticity_coordinates.py b/colour/characterisation/datasets/colour_checkers/chromaticity_coordinates.py index 7e3e9ca33a..e848646b86 100644 --- a/colour/characterisation/datasets/colour_checkers/chromaticity_coordinates.py +++ b/colour/characterisation/datasets/colour_checkers/chromaticity_coordinates.py @@ -49,7 +49,7 @@ from collections import namedtuple from colour.colorimetry import CCS_ILLUMINANTS -from colour.hints import Dict, NDArray, Tuple +from colour.hints import NDArrayFloat from colour.models import Lab_to_XYZ, XYZ_to_xyY from colour.utilities import CanonicalMapping @@ -106,7 +106,7 @@ class ColourChecker( """ -SAMPLE_LABELS_COLORCHECKER_CLASSIC: Tuple = ( +SAMPLE_LABELS_COLORCHECKER_CLASSIC: tuple = ( "dark skin", "light skin", "blue sky", @@ -134,7 +134,7 @@ class ColourChecker( ) """*ColorChecker Classic* illuminant.""" -DATA_COLORCHECKER1976: Dict = dict( +DATA_COLORCHECKER1976: dict = dict( zip( SAMPLE_LABELS_COLORCHECKER_CLASSIC, [ @@ -166,7 +166,7 @@ class ColourChecker( ) ) -CCS_ILLUMINANT_COLORCHECKER1976: NDArray = CCS_ILLUMINANTS[ +CCS_ILLUMINANT_COLORCHECKER1976: NDArrayFloat = CCS_ILLUMINANTS[ "CIE 1931 2 Degree Standard Observer" ]["C"] """*ColorChecker Classic 1976* illuminant.""" @@ -179,7 +179,7 @@ class ColourChecker( Division of Kollmorgen. """ -DATA_COLORCHECKER2005: Dict = dict( +DATA_COLORCHECKER2005: dict = dict( zip( SAMPLE_LABELS_COLORCHECKER_CLASSIC, [ @@ -211,7 +211,7 @@ class ColourChecker( ) ) -CCS_ILLUMINANT_COLORCHECKER2005: NDArray = CCS_ILLUMINANTS[ +CCS_ILLUMINANT_COLORCHECKER2005: NDArrayFloat = CCS_ILLUMINANTS[ "CIE 1931 2 Degree Standard Observer" ]["ICC D50"] """*ColorChecker Classic 2005* illuminant.""" @@ -220,7 +220,7 @@ class ColourChecker( "ColorChecker 2005", DATA_COLORCHECKER2005, CCS_ILLUMINANT_COLORCHECKER2005 ) """*ColorChecker Classic* data from *GretagMacbeth (2005)*.""" -DATA_BABELCOLOR_AVERAGE: Dict = dict( +DATA_BABELCOLOR_AVERAGE: dict = dict( zip( SAMPLE_LABELS_COLORCHECKER_CLASSIC, [ @@ -252,7 +252,7 @@ class ColourChecker( ) ) -CCS_ILLUMINANT_BABELCOLOR_AVERAGE: NDArray = CCS_ILLUMINANTS[ +CCS_ILLUMINANT_BABELCOLOR_AVERAGE: NDArrayFloat = CCS_ILLUMINANTS[ "CIE 1931 2 Degree Standard Observer" ]["ICC D50"] """*BabelColor Average* illuminant.""" @@ -264,7 +264,7 @@ class ColourChecker( ) """Average data derived from measurements of 30 *ColorChecker Classic* charts.""" -DATA_COLORCHECKER24_BEFORE_NOV2014_CIE_LAB: Dict = dict( +DATA_COLORCHECKER24_BEFORE_NOV2014_CIE_LAB: dict = dict( zip( SAMPLE_LABELS_COLORCHECKER_CLASSIC, [ @@ -296,7 +296,7 @@ class ColourChecker( ) ) -DATA_COLORCHECKER24_BEFORE_NOV2014: Dict = dict( +DATA_COLORCHECKER24_BEFORE_NOV2014: dict = dict( zip( SAMPLE_LABELS_COLORCHECKER_CLASSIC, XYZ_to_xyY( @@ -310,7 +310,7 @@ class ColourChecker( ) ) -CCS_ILLUMINANT_COLORCHECKER24_BEFORE_NOV2014: NDArray = CCS_ILLUMINANTS[ +CCS_ILLUMINANT_COLORCHECKER24_BEFORE_NOV2014: NDArrayFloat = CCS_ILLUMINANTS[ "CIE 1931 2 Degree Standard Observer" ]["ICC D50"] """*ColorChecker24 - Before November 2014* illuminant.""" @@ -330,7 +330,7 @@ class ColourChecker( original *CIE L\\*a\\*b\\** colourspace values. """ -DATA_COLORCHECKER24_AFTER_NOV2014_CIE_LAB: Dict = dict( +DATA_COLORCHECKER24_AFTER_NOV2014_CIE_LAB: dict = dict( [ ("dark skin", np.array([37.54, 14.37, 14.92])), ("light skin", np.array([64.66, 19.27, 17.5])), @@ -359,7 +359,7 @@ class ColourChecker( ] ) -DATA_COLORCHECKER24_AFTER_NOV2014: Dict = dict( +DATA_COLORCHECKER24_AFTER_NOV2014: dict = dict( zip( SAMPLE_LABELS_COLORCHECKER_CLASSIC, XYZ_to_xyY( @@ -373,7 +373,7 @@ class ColourChecker( ) ) -CCS_ILLUMINANT_COLORCHECKER24_AFTER_NOV2014: NDArray = CCS_ILLUMINANTS[ +CCS_ILLUMINANT_COLORCHECKER24_AFTER_NOV2014: NDArrayFloat = CCS_ILLUMINANTS[ "CIE 1931 2 Degree Standard Observer" ]["ICC D50"] """*ColorChecker24 - After November 2014* illuminant.""" diff --git a/colour/characterisation/datasets/colour_checkers/sds.py b/colour/characterisation/datasets/colour_checkers/sds.py index 507ee62dbd..0d1c9be3a9 100644 --- a/colour/characterisation/datasets/colour_checkers/sds.py +++ b/colour/characterisation/datasets/colour_checkers/sds.py @@ -48,7 +48,6 @@ from functools import partial from colour.colorimetry import SpectralDistribution -from colour.hints import Dict from colour.utilities import CanonicalMapping, LazyCanonicalMapping __author__ = "Colour Developers" @@ -71,7 +70,7 @@ "SDS_COLOURCHECKERS", ] -DATA_BABELCOLOR_AVERAGE: Dict = dict( +DATA_BABELCOLOR_AVERAGE: dict = dict( [ ( "dark skin", diff --git a/colour/characterisation/datasets/displays/crt/primaries.py b/colour/characterisation/datasets/displays/crt/primaries.py index 04631b11c4..4d4f58ffb2 100644 --- a/colour/characterisation/datasets/displays/crt/primaries.py +++ b/colour/characterisation/datasets/displays/crt/primaries.py @@ -30,7 +30,6 @@ from functools import partial from colour.characterisation import RGB_DisplayPrimaries -from colour.hints import Dict from colour.utilities import LazyCanonicalMapping __author__ = "Colour Developers" @@ -45,7 +44,7 @@ "MSDS_DISPLAY_PRIMARIES_CRT", ] -DATA_DISPLAY_PRIMARIES_CRT: Dict = { +DATA_DISPLAY_PRIMARIES_CRT: dict = { "Typical CRT Brainard 1997": { 380.0: (0.0025, 0.0018, 0.0219), 385.0: (0.0017, 0.0016, 0.0336), diff --git a/colour/characterisation/datasets/displays/lcd/primaries.py b/colour/characterisation/datasets/displays/lcd/primaries.py index b7ad255c33..d01da294cc 100644 --- a/colour/characterisation/datasets/displays/lcd/primaries.py +++ b/colour/characterisation/datasets/displays/lcd/primaries.py @@ -34,7 +34,6 @@ from functools import partial from colour.characterisation import RGB_DisplayPrimaries -from colour.hints import Dict from colour.utilities import LazyCanonicalMapping __author__ = "Colour Developers" @@ -49,7 +48,7 @@ "MSDS_DISPLAY_PRIMARIES_LCD", ] -DATA_DISPLAY_PRIMARIES_LCD: Dict = { +DATA_DISPLAY_PRIMARIES_LCD: dict = { "Apple Studio Display": { 380: (0.0000, 0.0000, 0.0000), 385: (0.0000, 0.0000, 0.0000), diff --git a/colour/characterisation/datasets/filters/sds.py b/colour/characterisation/datasets/filters/sds.py index 0bb408cbdf..d2b62f192b 100644 --- a/colour/characterisation/datasets/filters/sds.py +++ b/colour/characterisation/datasets/filters/sds.py @@ -26,7 +26,6 @@ from functools import partial from colour.colorimetry import SpectralDistribution -from colour.hints import Dict from colour.utilities import LazyCanonicalMapping __author__ = "Colour Developers" @@ -42,7 +41,7 @@ "SDS_FILTERS", ] -DATA_FILTERS_ISO: Dict = { +DATA_FILTERS_ISO: dict = { "ISO 7589 Diffuser": { 350: 0.00, 360: 0.00, diff --git a/colour/characterisation/datasets/lenses/sds.py b/colour/characterisation/datasets/lenses/sds.py index ca19ec8e40..245c367b6e 100644 --- a/colour/characterisation/datasets/lenses/sds.py +++ b/colour/characterisation/datasets/lenses/sds.py @@ -26,7 +26,6 @@ from functools import partial from colour.colorimetry import SpectralDistribution -from colour.hints import Dict from colour.utilities import LazyCanonicalMapping __author__ = "Colour Developers" @@ -42,7 +41,7 @@ "SDS_LENSES", ] -DATA_LENSES_ISO: Dict = { +DATA_LENSES_ISO: dict = { "ISO Standard Lens": { 350: 0.00, 360: 0.07, diff --git a/colour/characterisation/displays.py b/colour/characterisation/displays.py index 9f987c77f3..5c7541a758 100644 --- a/colour/characterisation/displays.py +++ b/colour/characterisation/displays.py @@ -18,16 +18,26 @@ SpectralShape, ) from colour.continuous import MultiSignals, Signal -from colour.hints import ArrayLike, Any, Optional, Sequence, Union +from colour.hints import ( + ArrayLike, + Any, + Optional, + Sequence, + TYPE_CHECKING, + Union, +) from colour.utilities import is_pandas_installed -if is_pandas_installed(): +if TYPE_CHECKING: from pandas import DataFrame, Series -else: # pragma: no cover - from unittest import mock +else: + if is_pandas_installed(): + from pandas import DataFrame, Series + else: # pragma: no cover + from unittest import mock - DataFrame = mock.MagicMock() - Series = mock.MagicMock() + DataFrame = mock.MagicMock() + Series = mock.MagicMock() __author__ = "Colour Developers" __copyright__ = "Copyright 2013 Colour Developers" diff --git a/colour/characterisation/tests/test_correction.py b/colour/characterisation/tests/test_correction.py index e7607be83b..e9c0dd9c9d 100644 --- a/colour/characterisation/tests/test_correction.py +++ b/colour/characterisation/tests/test_correction.py @@ -22,7 +22,7 @@ colour_correction_Finlayson2015, colour_correction_Vandermonde, ) -from colour.hints import NDArray +from colour.hints import NDArrayFloat from colour.utilities import ignore_numpy_errors __author__ = "Colour Developers" @@ -46,7 +46,7 @@ "TestColourCorrectionVandermonde", ] -MATRIX_TEST: NDArray = np.array( +MATRIX_TEST: NDArrayFloat = np.array( [ [0.17224810, 0.09170660, 0.06416938], [0.49189645, 0.27802050, 0.21923399], @@ -75,7 +75,7 @@ ] ) -MATRIX_REFERENCE: NDArray = np.array( +MATRIX_REFERENCE: NDArrayFloat = np.array( [ [0.15579559, 0.09715755, 0.07514556], [0.39113140, 0.25943419, 0.21266708], diff --git a/colour/colorimetry/blackbody.py b/colour/colorimetry/blackbody.py index f000f1b138..d864609883 100644 --- a/colour/colorimetry/blackbody.py +++ b/colour/colorimetry/blackbody.py @@ -25,13 +25,7 @@ SpectralShape, ) from colour.constants import CONSTANT_BOLTZMANN, CONSTANT_LIGHT_SPEED -from colour.hints import ( - Floating, - FloatingOrArrayLike, - FloatingOrNDArray, - NDArray, - cast, -) +from colour.hints import ArrayLike, NDArrayFloat from colour.utilities import as_float, as_float_array __author__ = "Colour Developers" @@ -62,12 +56,12 @@ def planck_law( - wavelength: FloatingOrArrayLike, - temperature: FloatingOrArrayLike, - c1: Floating = CONSTANT_C1, - c2: Floating = CONSTANT_C2, - n: Floating = CONSTANT_N, -) -> FloatingOrNDArray: + wavelength: ArrayLike, + temperature: ArrayLike, + c1: float = CONSTANT_C1, + c2: float = CONSTANT_C2, + n: float = CONSTANT_N, +) -> NDArrayFloat: """ Return the spectral radiance of a blackbody as a function of wavelength at thermodynamic temperature :math:`T[K]` in a medium having index of @@ -97,7 +91,7 @@ def planck_law( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Radiance in *watts per steradian per square metre* (:math:`W/sr/m^2`). Warnings @@ -134,7 +128,7 @@ def planck_law( t = np.ravel(t)[None, ...] with sdiv_mode(): - d = cast(NDArray, sdiv(c2, (n * l * t))) + d = sdiv(c2, (n * l * t)) d[d != 0] = np.expm1(d[d != 0]) ** -1 p = ((c1 * n**-2 * l**-5) / np.pi) * d @@ -146,11 +140,11 @@ def planck_law( def sd_blackbody( - temperature: Floating, + temperature: float, shape: SpectralShape = SPECTRAL_SHAPE_DEFAULT, - c1: Floating = CONSTANT_C1, - c2: Floating = CONSTANT_C2, - n: Floating = CONSTANT_N, + c1: float = CONSTANT_C1, + c2: float = CONSTANT_C2, + n: float = CONSTANT_N, ) -> SpectralDistribution: """ Return the spectral distribution of the planckian radiator for given @@ -224,8 +218,8 @@ def sd_blackbody( def rayleigh_jeans_law( - wavelength: FloatingOrArrayLike, temperature: FloatingOrArrayLike -) -> FloatingOrNDArray: + wavelength: ArrayLike, temperature: ArrayLike +) -> NDArrayFloat: """ Return the approximation of the spectral radiance of a blackbody as a function of wavelength at thermodynamic temperature :math:`T[K]` according @@ -240,7 +234,7 @@ def rayleigh_jeans_law( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Radiance in *watts per steradian per square metre* (:math:`W/sr/m^2`). Warnings @@ -291,7 +285,7 @@ def rayleigh_jeans_law( def sd_rayleigh_jeans( - temperature: Floating, + temperature: float, shape: SpectralShape = SPECTRAL_SHAPE_DEFAULT, ) -> SpectralDistribution: """ diff --git a/colour/colorimetry/cmfs.py b/colour/colorimetry/cmfs.py index 1296561c72..1828dc7008 100644 --- a/colour/colorimetry/cmfs.py +++ b/colour/colorimetry/cmfs.py @@ -22,16 +22,26 @@ SpectralShape, ) from colour.continuous import MultiSignals, Signal -from colour.hints import ArrayLike, Any, Optional, Sequence, Union +from colour.hints import ( + ArrayLike, + Any, + Optional, + Sequence, + TYPE_CHECKING, + Union, +) from colour.utilities import is_pandas_installed -if is_pandas_installed(): +if TYPE_CHECKING: from pandas import DataFrame, Series -else: # pragma: no cover - from unittest import mock +else: + if is_pandas_installed(): + from pandas import DataFrame, Series + else: # pragma: no cover + from unittest import mock - DataFrame = mock.MagicMock() - Series = mock.MagicMock() + DataFrame = mock.MagicMock() + Series = mock.MagicMock() __author__ = "Colour Developers" __copyright__ = "Copyright 2013 Colour Developers" diff --git a/colour/colorimetry/correction.py b/colour/colorimetry/correction.py index 690e2d8c99..36e45b9e65 100644 --- a/colour/colorimetry/correction.py +++ b/colour/colorimetry/correction.py @@ -29,7 +29,7 @@ import numpy as np from colour.colorimetry import SpectralDistribution -from colour.hints import Floating, Literal, Union +from colour.hints import Literal, Union from colour.utilities import CanonicalMapping, validate_method __author__ = "Colour Developers" @@ -45,7 +45,7 @@ "bandpass_correction", ] -CONSTANT_ALPHA_STEARNS: Floating = 0.083 +CONSTANT_ALPHA_STEARNS: float = 0.083 def bandpass_correction_Stearns1988( diff --git a/colour/colorimetry/datasets/cmfs.py b/colour/colorimetry/datasets/cmfs.py index 52f56f0dde..eea0d92807 100644 --- a/colour/colorimetry/datasets/cmfs.py +++ b/colour/colorimetry/datasets/cmfs.py @@ -70,7 +70,6 @@ RGB_ColourMatchingFunctions, XYZ_ColourMatchingFunctions, ) -from colour.hints import Dict from colour.utilities import LazyCanonicalMapping, usage_warning __author__ = "Colour Developers" @@ -92,7 +91,7 @@ # *S-cone* spectral sensitivity data wasn't measurable after 615 nm and has # been set to zero. -DATA_CMFS_LMS: Dict = { +DATA_CMFS_LMS: dict = { "Stockman & Sharpe 2 Degree Cone Fundamentals": { 390: (4.15003e-04, 3.68349e-04, 9.54729e-03), 391: (5.02650e-04, 4.48015e-04, 1.14794e-02), @@ -1094,7 +1093,7 @@ :cite:`CVRLu`, :cite:`Machado2010a` """ -DATA_CMFS_RGB: Dict = { +DATA_CMFS_RGB: dict = { "Wright & Guild 1931 2 Degree RGB CMFs": { 380: (0.00003, -0.00001, 0.00117), 385: (0.00005, -0.00002, 0.00189), @@ -1372,7 +1371,7 @@ :cite:`Broadbent2009a`, :cite:`CVRLt`, :cite:`CVRLw` """ -DATA_CMFS_STANDARD_OBSERVER: Dict = { +DATA_CMFS_STANDARD_OBSERVER: dict = { "CIE 1931 2 Degree Standard Observer": { 360: (0.000129900000, 0.000003917000, 0.000606100000), 361: (0.000145847000, 0.000004393581, 0.000680879200), diff --git a/colour/colorimetry/datasets/illuminants/hunterlab.py b/colour/colorimetry/datasets/illuminants/hunterlab.py index c0e7ff7d7f..ac2e99c6b7 100644 --- a/colour/colorimetry/datasets/illuminants/hunterlab.py +++ b/colour/colorimetry/datasets/illuminants/hunterlab.py @@ -25,7 +25,6 @@ import numpy as np from collections import namedtuple -from colour.hints import Tuple from colour.utilities import CanonicalMapping __author__ = "Colour Developers" @@ -48,7 +47,7 @@ "Illuminant_Specification_HunterLab", ("name", "XYZ_n", "K_ab") ) -DATA_ILLUMINANTS_HUNTERLAB_STANDARD_OBSERVER_2_DEGREE_CIE1931: Tuple = ( +DATA_ILLUMINANTS_HUNTERLAB_STANDARD_OBSERVER_2_DEGREE_CIE1931: tuple = ( ("A", np.array([109.83, 100.00, 35.55]), np.array([185.20, 38.40])), ("C", np.array([98.04, 100.00, 118.11]), np.array([175.00, 70.00])), ("D50", np.array([96.38, 100.00, 82.45]), np.array([173.51, 58.48])), @@ -77,7 +76,7 @@ :cite:`HunterLab2008b`, :cite:`HunterLab2008c` """ -DATA_ILLUMINANTS_HUNTERLAB_STANDARD_OBSERVER_10_DEGREE_CIE1964: Tuple = ( +DATA_ILLUMINANTS_HUNTERLAB_STANDARD_OBSERVER_10_DEGREE_CIE1964: tuple = ( ("A", np.array([111.16, 100.00, 35.19]), np.array([186.30, 38.20])), ("C", np.array([97.30, 100.00, 116.14]), np.array([174.30, 69.40])), ("D50", np.array([96.72, 100.00, 81.45]), np.array([173.82, 58.13])), diff --git a/colour/colorimetry/datasets/illuminants/sds.py b/colour/colorimetry/datasets/illuminants/sds.py index 0c6ea4c5a6..64951f5749 100644 --- a/colour/colorimetry/datasets/illuminants/sds.py +++ b/colour/colorimetry/datasets/illuminants/sds.py @@ -62,7 +62,6 @@ from colour.algebra import LinearInterpolator from colour.colorimetry.spectrum import SpectralDistribution -from colour.hints import Dict from colour.utilities import LazyCanonicalMapping __author__ = "Colour Developers" @@ -80,7 +79,7 @@ "SDS_ILLUMINANTS", ] -DATA_ILLUMINANTS_CIE: Dict = { +DATA_ILLUMINANTS_CIE: dict = { "A": { 300: 0.930483, 305: 1.128210, @@ -4610,7 +4609,7 @@ :cite:`Carter2018`, :cite:`CIEce`, :cite:`CIEcf` """ -DATA_ILLUMINANTS_ISO: Dict = { +DATA_ILLUMINANTS_ISO: dict = { "ISO 7589 Photographic Daylight": { 350: 28, 360: 31, diff --git a/colour/colorimetry/datasets/illuminants/sds_d_illuminant_series.py b/colour/colorimetry/datasets/illuminants/sds_d_illuminant_series.py index 0d62016027..7fa8962bf8 100644 --- a/colour/colorimetry/datasets/illuminants/sds_d_illuminant_series.py +++ b/colour/colorimetry/datasets/illuminants/sds_d_illuminant_series.py @@ -22,7 +22,6 @@ from functools import partial from colour.colorimetry import SpectralDistribution -from colour.hints import Dict from colour.utilities import LazyCanonicalMapping __author__ = "Colour Developers" @@ -37,7 +36,7 @@ "SDS_BASIS_FUNCTIONS_CIE_ILLUMINANT_D_SERIES", ] -DATA_BASIS_FUNCTIONS_CIE_ILLUMINANT_D_SERIES: Dict = { +DATA_BASIS_FUNCTIONS_CIE_ILLUMINANT_D_SERIES: dict = { "S0": { 300: 0.04, 305: 3.02, diff --git a/colour/colorimetry/datasets/lefs.py b/colour/colorimetry/datasets/lefs.py index 2150ee52fb..6ad6af3589 100644 --- a/colour/colorimetry/datasets/lefs.py +++ b/colour/colorimetry/datasets/lefs.py @@ -46,7 +46,6 @@ from functools import partial from colour.colorimetry import SpectralDistribution -from colour.hints import Dict from colour.utilities import CanonicalMapping, LazyCanonicalMapping __author__ = "Colour Developers" @@ -65,7 +64,7 @@ "DATA_MESOPIC_X", ] -DATA_LEFS_PHOTOPIC: Dict = { +DATA_LEFS_PHOTOPIC: dict = { "CIE 1924 Photopic Standard Observer": { 360: 0.0000039170000, 361: 0.0000043935810, @@ -2412,7 +2411,7 @@ "CIE 1964 Photopic 10 Degree Standard Observer" ] -DATA_LEFS_SCOTOPIC: Dict = { +DATA_LEFS_SCOTOPIC: dict = { "CIE 1951 Scotopic Standard Observer": { 380: 0.0005890000, 381: 0.0006650000, @@ -2852,7 +2851,7 @@ """ SDS_LEFS.update(SDS_LEFS_SCOTOPIC) -DATA_MESOPIC_X: Dict = { +DATA_MESOPIC_X: dict = { 0.01: CanonicalMapping( { "Blue Heavy": CanonicalMapping({"MOVE": 0.13, "LRC": 0.04}), diff --git a/colour/colorimetry/datasets/light_sources/sds.py b/colour/colorimetry/datasets/light_sources/sds.py index e9b85feb98..4fb050a1fd 100644 --- a/colour/colorimetry/datasets/light_sources/sds.py +++ b/colour/colorimetry/datasets/light_sources/sds.py @@ -54,7 +54,6 @@ from colour.algebra import LinearInterpolator from colour.colorimetry.spectrum import SpectralDistribution -from colour.hints import Dict from colour.utilities import LazyCanonicalMapping __author__ = "Colour Developers" @@ -78,7 +77,7 @@ "SDS_LIGHT_SOURCES", ] -DATA_LIGHT_SOURCES_RIT: Dict = { +DATA_LIGHT_SOURCES_RIT: dict = { "Natural": { 380: 1.88, 385: 2.24, @@ -772,7 +771,7 @@ :cite:`Pointer1980a` """ -DATA_LIGHT_SOURCES_NIST_TRADITIONAL: Dict = { +DATA_LIGHT_SOURCES_NIST_TRADITIONAL: dict = { "Cool White FL": { 380: 0.03353465, 385: 0.04082136, @@ -1628,7 +1627,7 @@ :cite:`Ohno2008a` """ -DATA_LIGHT_SOURCES_NIST_LED: Dict = { +DATA_LIGHT_SOURCES_NIST_LED: dict = { "3-LED-1 (457/540/605)": { 380: 8.47479023841784e-08, 385: 5.45760813791522e-07, @@ -2893,7 +2892,7 @@ *NIST CQS simulation 7.4.xls* spreadsheet. """ -DATA_LIGHT_SOURCES_NIST_PHILIPS: Dict = { +DATA_LIGHT_SOURCES_NIST_PHILIPS: dict = { "60 A/W (Soft White)": { 380: 0.0221129274, 385: 0.0257550191, @@ -4739,7 +4738,7 @@ *NIST CQS simulation 7.4.xls* spreadsheet. """ -DATA_LIGHT_SOURCES_COMMON: Dict = { +DATA_LIGHT_SOURCES_COMMON: dict = { "Kinoton 75P": { 380: 0.0001099667, 382: 0.0001415667, diff --git a/colour/colorimetry/dominant.py b/colour/colorimetry/dominant.py index 061279253e..e07465ec42 100644 --- a/colour/colorimetry/dominant.py +++ b/colour/colorimetry/dominant.py @@ -41,11 +41,8 @@ ) from colour.hints import ( ArrayLike, - Boolean, - FloatingOrNDArray, - NDArray, + NDArrayFloat, Optional, - Tuple, ) from colour.models import XYZ_to_xy from colour.utilities import as_float_array @@ -67,8 +64,8 @@ def closest_spectral_locus_wavelength( - xy: ArrayLike, xy_n: ArrayLike, xy_s: ArrayLike, inverse: Boolean = False -) -> Tuple[NDArray, NDArray]: + xy: ArrayLike, xy_n: ArrayLike, xy_s: ArrayLike, inverse: bool = False +) -> tuple[NDArrayFloat, NDArrayFloat]: """ Return the coordinates and closest spectral locus wavelength index to the point where the line defined by the given achromatic stimulus :math:`xy_n` @@ -145,7 +142,7 @@ def dominant_wavelength( xy_n: ArrayLike, cmfs: Optional[MultiSpectralDistributions] = None, inverse: bool = False, -) -> Tuple[NDArray, NDArray, NDArray]: +) -> tuple[NDArrayFloat, NDArrayFloat, NDArrayFloat]: """ Return the *dominant wavelength* :math:`\\lambda_d` for given colour stimulus :math:`xy` and the related :math:`xy_wl` first and :math:`xy_{cw}` @@ -245,7 +242,7 @@ def complementary_wavelength( xy: ArrayLike, xy_n: ArrayLike, cmfs: Optional[MultiSpectralDistributions] = None, -) -> Tuple[NDArray, NDArray, NDArray]: +) -> tuple[NDArrayFloat, NDArrayFloat, NDArrayFloat]: """ Return the *complementary wavelength* :math:`\\lambda_c` for given colour stimulus :math:`xy` and the related :math:`xy_wl` first and :math:`xy_{cw}` @@ -313,7 +310,7 @@ def excitation_purity( xy: ArrayLike, xy_n: ArrayLike, cmfs: Optional[MultiSpectralDistributions] = None, -) -> FloatingOrNDArray: +) -> NDArrayFloat: """ Return the *excitation purity* :math:`P_e` for given colour stimulus :math:`xy`. @@ -330,7 +327,7 @@ def excitation_purity( Returns ------- - :class:`np.floating` or :class:`numpy.ndarray` + :class:`np.float` or :class:`numpy.ndarray` *Excitation purity* :math:`P_e`. References @@ -362,7 +359,7 @@ def colorimetric_purity( xy: ArrayLike, xy_n: ArrayLike, cmfs: Optional[MultiSpectralDistributions] = None, -) -> FloatingOrNDArray: +) -> NDArrayFloat: """ Return the *colorimetric purity* :math:`P_c` for given colour stimulus :math:`xy`. @@ -379,7 +376,7 @@ def colorimetric_purity( Returns ------- - :class:`np.floating` or :class:`numpy.ndarray` + :class:`np.float` or :class:`numpy.ndarray` *Colorimetric purity* :math:`P_c`. References diff --git a/colour/colorimetry/generation.py b/colour/colorimetry/generation.py index 49abb96655..4a43d3f4da 100644 --- a/colour/colorimetry/generation.py +++ b/colour/colorimetry/generation.py @@ -45,9 +45,8 @@ from colour.hints import ( Any, ArrayLike, - Floating, Literal, - NDArray, + NDArrayFloat, Optional, Sequence, Union, @@ -88,7 +87,7 @@ def sd_constant( - k: Floating, shape: SpectralShape = SPECTRAL_SHAPE_DEFAULT, **kwargs: Any + k: float, shape: SpectralShape = SPECTRAL_SHAPE_DEFAULT, **kwargs: Any ) -> SpectralDistribution: """ Return a spectral distribution of given spectral shape filled with @@ -213,7 +212,7 @@ def sd_ones( def msds_constant( - k: Floating, + k: float, labels: Sequence, shape: SpectralShape = SPECTRAL_SHAPE_DEFAULT, **kwargs: Any, @@ -365,8 +364,8 @@ def msds_ones( def sd_gaussian_normal( - mu: Floating, - sigma: Floating, + mu: float, + sigma: float, shape: SpectralShape = SPECTRAL_SHAPE_DEFAULT, **kwargs: Any, ) -> SpectralDistribution: @@ -420,8 +419,8 @@ def sd_gaussian_normal( def sd_gaussian_fwhm( - peak_wavelength: Floating, - fwhm: Floating, + peak_wavelength: float, + fwhm: float, shape: SpectralShape = SPECTRAL_SHAPE_DEFAULT, **kwargs: Any, ) -> SpectralDistribution: @@ -484,8 +483,8 @@ def sd_gaussian_fwhm( def sd_gaussian( - mu_peak_wavelength: Floating, - sigma_fwhm: Floating, + mu_peak_wavelength: float, + sigma_fwhm: float, shape: SpectralShape = SPECTRAL_SHAPE_DEFAULT, method: Union[Literal["Normal", "FWHM"], str] = "Normal", **kwargs: Any, @@ -552,8 +551,8 @@ def sd_gaussian( def sd_single_led_Ohno2005( - peak_wavelength: Floating, - fwhm: Floating, + peak_wavelength: float, + fwhm: float, shape: SpectralShape = SPECTRAL_SHAPE_DEFAULT, **kwargs: Any, ) -> SpectralDistribution: @@ -623,8 +622,8 @@ def sd_single_led_Ohno2005( def sd_single_led( - peak_wavelength: Floating, - fwhm: Floating, + peak_wavelength: float, + fwhm: float, shape: SpectralShape = SPECTRAL_SHAPE_DEFAULT, method: Union[Literal["Ohno 2005"], str] = "Ohno 2005", **kwargs: Any, @@ -761,12 +760,12 @@ def sd_multi_leds_Ohno2005( for (peak_wavelength, fwhm_s, peak_power_ratio) in zip( peak_wavelengths, fwhm, peak_power_ratios ): - sd += ( # type: ignore[misc] + sd += ( sd_single_led_Ohno2005(peak_wavelength, fwhm_s, **kwargs) * peak_power_ratio ) - def _format_array(a: NDArray) -> str: + def _format_array(a: NDArrayFloat) -> str: """Format given array :math:`a`.""" return ", ".join([str(e) for e in a]) diff --git a/colour/colorimetry/illuminants.py b/colour/colorimetry/illuminants.py index 4d938da739..1371910109 100644 --- a/colour/colorimetry/illuminants.py +++ b/colour/colorimetry/illuminants.py @@ -35,12 +35,7 @@ SpectralDistribution, SpectralShape, ) -from colour.hints import ( - ArrayLike, - Boolean, - FloatingOrArrayLike, - FloatingOrNDArray, -) +from colour.hints import ArrayLike, NDArrayFloat from colour.utilities import as_float_array, as_float, tsplit __author__ = "Colour Developers" @@ -141,7 +136,7 @@ def sd_CIE_standard_illuminant_A( def sd_CIE_illuminant_D_series( - xy: ArrayLike, M1_M2_rounding: Boolean = True + xy: ArrayLike, M1_M2_rounding: bool = True ) -> SpectralDistribution: """ Return the spectral distribution of given *CIE Illuminant D Series* using @@ -321,7 +316,7 @@ def sd_CIE_illuminant_D_series( ) -def daylight_locus_function(x_D: FloatingOrArrayLike) -> FloatingOrNDArray: +def daylight_locus_function(x_D: ArrayLike) -> NDArrayFloat: """ Return the daylight locus as *CIE xy* chromaticity coordinates. @@ -332,7 +327,7 @@ def daylight_locus_function(x_D: FloatingOrArrayLike) -> FloatingOrNDArray: Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Daylight locus as *CIE xy* chromaticity coordinates. References diff --git a/colour/colorimetry/lefs.py b/colour/colorimetry/lefs.py index a820efb19e..c23dc79ffd 100644 --- a/colour/colorimetry/lefs.py +++ b/colour/colorimetry/lefs.py @@ -20,15 +20,7 @@ SpectralShape, ) from colour.colorimetry.datasets.lefs import DATA_MESOPIC_X -from colour.hints import ( - Floating, - FloatingOrArrayLike, - FloatingOrNDArray, - Literal, - Optional, - Union, - cast, -) +from colour.hints import ArrayLike, NDArrayFloat, Literal, Optional, Union from colour.utilities import closest, optional, validate_method __author__ = "Colour Developers" @@ -45,13 +37,13 @@ def mesopic_weighting_function( - wavelength: FloatingOrArrayLike, - L_p: Floating, + wavelength: ArrayLike, + L_p: float, source: Union[Literal["Blue Heavy", "Red Heavy"], str] = "Blue Heavy", method: Union[Literal["MOVE", "LRC"], str] = "MOVE", photopic_lef: Optional[SpectralDistribution] = None, scotopic_lef: Optional[SpectralDistribution] = None, -) -> FloatingOrNDArray: +) -> NDArrayFloat: """ Calculate the mesopic weighting function factor :math:`V_m` at given wavelength :math:`\\lambda` using the photopic luminance :math:`L_p`. @@ -76,7 +68,7 @@ def mesopic_weighting_function( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Mesopic weighting function factor :math:`V_m`. References @@ -89,20 +81,14 @@ def mesopic_weighting_function( 0.7052200... """ - photopic_lef = cast( - SpectralDistribution, - optional( - photopic_lef, - SDS_LEFS_PHOTOPIC["CIE 1924 Photopic Standard Observer"], - ), + photopic_lef = optional( + photopic_lef, + SDS_LEFS_PHOTOPIC["CIE 1924 Photopic Standard Observer"], ) - scotopic_lef = cast( - SpectralDistribution, - optional( - scotopic_lef, - SDS_LEFS_SCOTOPIC["CIE 1951 Scotopic Standard Observer"], - ), + scotopic_lef = optional( + scotopic_lef, + SDS_LEFS_SCOTOPIC["CIE 1951 Scotopic Standard Observer"], ) source = validate_method( @@ -125,7 +111,7 @@ def mesopic_weighting_function( def sd_mesopic_luminous_efficiency_function( - L_p: Floating, + L_p: float, source: Union[Literal["Blue Heavy", "Red Heavy"], str] = "Blue Heavy", method: Union[Literal["MOVE", "LRC"], str] = "MOVE", photopic_lef: Optional[SpectralDistribution] = None, @@ -572,20 +558,14 @@ def sd_mesopic_luminous_efficiency_function( {'method': 'Constant', 'left': None, 'right': None}) """ - photopic_lef = cast( - SpectralDistribution, - optional( - photopic_lef, - SDS_LEFS_PHOTOPIC["CIE 1924 Photopic Standard Observer"], - ), + photopic_lef = optional( + photopic_lef, + SDS_LEFS_PHOTOPIC["CIE 1924 Photopic Standard Observer"], ) - scotopic_lef = cast( - SpectralDistribution, - optional( - scotopic_lef, - SDS_LEFS_SCOTOPIC["CIE 1951 Scotopic Standard Observer"], - ), + scotopic_lef = optional( + scotopic_lef, + SDS_LEFS_SCOTOPIC["CIE 1951 Scotopic Standard Observer"], ) shape = SpectralShape( diff --git a/colour/colorimetry/lightness.py b/colour/colorimetry/lightness.py index 26b01bcb93..c2685f409d 100644 --- a/colour/colorimetry/lightness.py +++ b/colour/colorimetry/lightness.py @@ -71,8 +71,8 @@ ) from colour.hints import ( Any, - FloatingOrArrayLike, - FloatingOrNDArray, + ArrayLike, + NDArrayFloat, Literal, Union, ) @@ -109,7 +109,7 @@ ] -def lightness_Glasser1958(Y: FloatingOrArrayLike) -> FloatingOrNDArray: +def lightness_Glasser1958(Y: ArrayLike) -> NDArrayFloat: """ Return the *Lightness* :math:`L` of given *luminance* :math:`Y` using *Glasser et al. (1958)* method. @@ -121,7 +121,7 @@ def lightness_Glasser1958(Y: FloatingOrArrayLike) -> FloatingOrNDArray: Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` *Lightness* :math:`L`. Notes @@ -155,7 +155,7 @@ def lightness_Glasser1958(Y: FloatingOrArrayLike) -> FloatingOrNDArray: return as_float(from_range_100(L)) -def lightness_Wyszecki1963(Y: FloatingOrArrayLike) -> FloatingOrNDArray: +def lightness_Wyszecki1963(Y: ArrayLike) -> NDArrayFloat: """ Return the *Lightness* :math:`W` of given *luminance* :math:`Y` using *Wyszecki (1963)* method. @@ -168,7 +168,7 @@ def lightness_Wyszecki1963(Y: FloatingOrArrayLike) -> FloatingOrNDArray: Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` *Lightness* :math:`W`. Notes @@ -209,8 +209,8 @@ def lightness_Wyszecki1963(Y: FloatingOrArrayLike) -> FloatingOrNDArray: def intermediate_lightness_function_CIE1976( - Y: FloatingOrArrayLike, Y_n: FloatingOrArrayLike = 100 -) -> FloatingOrNDArray: + Y: ArrayLike, Y_n: ArrayLike = 100 +) -> NDArrayFloat: """ Return the intermediate value :math:`f(Y/Yn)` in the *Lightness* :math:`L^*` computation for given *luminance* :math:`Y` using given @@ -225,7 +225,7 @@ def intermediate_lightness_function_CIE1976( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Intermediate value :math:`f(Y/Yn)`. Notes @@ -270,9 +270,7 @@ def intermediate_lightness_function_CIE1976( return as_float(f_Y_Y_n) -def lightness_CIE1976( - Y: FloatingOrArrayLike, Y_n: FloatingOrArrayLike = 100 -) -> FloatingOrNDArray: +def lightness_CIE1976(Y: ArrayLike, Y_n: ArrayLike = 100) -> NDArrayFloat: """ Return the *Lightness* :math:`L^*` of given *luminance* :math:`Y` using given reference white *luminance* :math:`Y_n` as per *CIE 1976* @@ -287,7 +285,7 @@ def lightness_CIE1976( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` *Lightness* :math:`L^*`. Notes @@ -323,8 +321,8 @@ def lightness_CIE1976( def lightness_Fairchild2010( - Y: FloatingOrArrayLike, epsilon: FloatingOrArrayLike = 1.836 -) -> FloatingOrNDArray: + Y: ArrayLike, epsilon: ArrayLike = 1.836 +) -> NDArrayFloat: """ Compute *Lightness* :math:`L_{hdr}` of given *luminance* :math:`Y` using *Fairchild and Wyble (2010)* method according to *Michaelis-Menten* @@ -339,7 +337,7 @@ def lightness_Fairchild2010( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` *Lightness* :math:`L_{hdr}`. Notes @@ -381,10 +379,10 @@ def lightness_Fairchild2010( def lightness_Fairchild2011( - Y: FloatingOrArrayLike, - epsilon: FloatingOrArrayLike = 0.474, + Y: ArrayLike, + epsilon: ArrayLike = 0.474, method: Union[Literal["hdr-CIELAB", "hdr-IPT"], str] = "hdr-CIELAB", -) -> FloatingOrNDArray: +) -> NDArrayFloat: """ Compute *Lightness* :math:`L_{hdr}` of given *luminance* :math:`Y` using *Fairchild and Chen (2011)* method according to *Michaelis-Menten* @@ -401,7 +399,7 @@ def lightness_Fairchild2011( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` *Lightness* :math:`L_{hdr}`. Notes @@ -450,12 +448,12 @@ def lightness_Fairchild2011( def lightness_Abebe2017( - Y: FloatingOrArrayLike, - Y_n: FloatingOrArrayLike = 100, + Y: ArrayLike, + Y_n: ArrayLike = 100, method: Union[ Literal["Michaelis-Menten", "Stevens"], str ] = "Michaelis-Menten", -) -> FloatingOrNDArray: +) -> NDArrayFloat: """ Compute *Lightness* :math:`L` of given *luminance* :math:`Y` using *Abebe, Pouli, Larabi and Reinhard (2017)* method according to @@ -472,7 +470,7 @@ def lightness_Abebe2017( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` *Lightness* :math:`L`. Notes @@ -560,7 +558,7 @@ def lightness_Abebe2017( def lightness( - Y: FloatingOrArrayLike, + Y: ArrayLike, method: Union[ Literal[ "Abebe 2017", @@ -573,7 +571,7 @@ def lightness( str, ] = "CIE 1976", **kwargs: Any, -) -> FloatingOrNDArray: +) -> NDArrayFloat: """ Return the *Lightness* :math:`L` of given *luminance* :math:`Y` using given method. @@ -598,7 +596,7 @@ def lightness( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` *Lightness* :math:`L`. Notes diff --git a/colour/colorimetry/luminance.py b/colour/colorimetry/luminance.py index 6d989f0218..3844264c4c 100644 --- a/colour/colorimetry/luminance.py +++ b/colour/colorimetry/luminance.py @@ -72,8 +72,8 @@ ) from colour.hints import ( Any, - FloatingOrArrayLike, - FloatingOrNDArray, + ArrayLike, + NDArrayFloat, Literal, Union, ) @@ -110,7 +110,7 @@ ] -def luminance_Newhall1943(V: FloatingOrArrayLike) -> FloatingOrNDArray: +def luminance_Newhall1943(V: ArrayLike) -> NDArrayFloat: """ Return the *luminance* :math:`R_Y` of given *Munsell* value :math:`V` using *Newhall et al. (1943)* method. @@ -122,7 +122,7 @@ def luminance_Newhall1943(V: FloatingOrArrayLike) -> FloatingOrNDArray: Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` *Luminance* :math:`R_Y`. Notes @@ -162,7 +162,7 @@ def luminance_Newhall1943(V: FloatingOrArrayLike) -> FloatingOrNDArray: return as_float(from_range_100(R_Y)) -def luminance_ASTMD1535(V: FloatingOrArrayLike) -> FloatingOrNDArray: +def luminance_ASTMD1535(V: ArrayLike) -> NDArrayFloat: """ Return the *luminance* :math:`Y` of given *Munsell* value :math:`V` using *ASTM D1535-08e1* method. @@ -174,7 +174,7 @@ def luminance_ASTMD1535(V: FloatingOrArrayLike) -> FloatingOrNDArray: Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` *Luminance* :math:`Y`. Notes @@ -215,8 +215,8 @@ def luminance_ASTMD1535(V: FloatingOrArrayLike) -> FloatingOrNDArray: def intermediate_luminance_function_CIE1976( - f_Y_Y_n: FloatingOrArrayLike, Y_n: FloatingOrArrayLike = 100 -) -> FloatingOrNDArray: + f_Y_Y_n: ArrayLike, Y_n: ArrayLike = 100 +) -> NDArrayFloat: """ Return the *luminance* :math:`Y` in the *luminance* :math:`Y` computation for given intermediate value :math:`f(Y/Yn)` using given @@ -231,7 +231,7 @@ def intermediate_luminance_function_CIE1976( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` *Luminance* :math:`Y`. Notes @@ -274,9 +274,7 @@ def intermediate_luminance_function_CIE1976( return as_float(Y) -def luminance_CIE1976( - L_star: FloatingOrArrayLike, Y_n: FloatingOrArrayLike = 100 -) -> FloatingOrNDArray: +def luminance_CIE1976(L_star: ArrayLike, Y_n: ArrayLike = 100) -> NDArrayFloat: """ Return the *luminance* :math:`Y` of given *Lightness* :math:`L^*` with given reference white *luminance* :math:`Y_n`. @@ -290,7 +288,7 @@ def luminance_CIE1976( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` *Luminance* :math:`Y`. Notes @@ -330,8 +328,8 @@ def luminance_CIE1976( def luminance_Fairchild2010( - L_hdr: FloatingOrArrayLike, epsilon: FloatingOrArrayLike = 1.836 -) -> FloatingOrNDArray: + L_hdr: ArrayLike, epsilon: ArrayLike = 1.836 +) -> NDArrayFloat: """ Compute *luminance* :math:`Y` of given *Lightness* :math:`L_{hdr}` using *Fairchild and Wyble (2010)* method according to *Michaelis-Menten* @@ -346,7 +344,7 @@ def luminance_Fairchild2010( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` *Luminance* :math:`Y`. Notes @@ -389,10 +387,10 @@ def luminance_Fairchild2010( def luminance_Fairchild2011( - L_hdr: FloatingOrArrayLike, - epsilon: FloatingOrArrayLike = 0.474, + L_hdr: ArrayLike, + epsilon: ArrayLike = 0.474, method: Union[Literal["hdr-CIELAB", "hdr-IPT"], str] = "hdr-CIELAB", -) -> FloatingOrNDArray: +) -> NDArrayFloat: """ Compute *luminance* :math:`Y` of given *Lightness* :math:`L_{hdr}` using *Fairchild and Chen (2011)* method according to *Michaelis-Menten* @@ -409,7 +407,7 @@ def luminance_Fairchild2011( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` *Luminance* :math:`Y`. Notes @@ -460,12 +458,12 @@ def luminance_Fairchild2011( def luminance_Abebe2017( - L: FloatingOrArrayLike, - Y_n: FloatingOrArrayLike = 100, + L: ArrayLike, + Y_n: ArrayLike = 100, method: Union[ Literal["Michaelis-Menten", "Stevens"], str ] = "Michaelis-Menten", -) -> FloatingOrNDArray: +) -> NDArrayFloat: """ Compute *luminance* :math:`Y` of *Lightness* :math:`L` using *Abebe, Pouli, Larabi and Reinhard (2017)* method according to @@ -482,7 +480,7 @@ def luminance_Abebe2017( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` *Luminance* :math:`Y` in :math:`cd/m^2`. Notes @@ -578,7 +576,7 @@ def luminance_Abebe2017( def luminance( - LV: FloatingOrArrayLike, + LV: ArrayLike, method: Union[ Literal[ "Abebe 2017", @@ -591,7 +589,7 @@ def luminance( str, ] = "CIE 1976", **kwargs: Any, -) -> FloatingOrNDArray: +) -> NDArrayFloat: """ Return the *luminance* :math:`Y` of given *Lightness* :math:`L^*` or given *Munsell* value :math:`V`. @@ -616,7 +614,7 @@ def luminance( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` *Luminance* :math:`Y`. Notes diff --git a/colour/colorimetry/photometry.py b/colour/colorimetry/photometry.py index d19beb6603..ee0f373e2a 100644 --- a/colour/colorimetry/photometry.py +++ b/colour/colorimetry/photometry.py @@ -23,7 +23,7 @@ reshape_sd, ) from colour.constants import CONSTANT_K_M -from colour.hints import Floating, Optional, cast +from colour.hints import Optional from colour.utilities import as_float_scalar, optional __author__ = "Colour Developers" @@ -43,8 +43,8 @@ def luminous_flux( sd: SpectralDistribution, lef: Optional[SpectralDistribution] = None, - K_m: Floating = CONSTANT_K_M, -) -> Floating: + K_m: float = CONSTANT_K_M, +) -> float: """ Return the *luminous flux* for given spectral distribution using given luminous efficiency function. @@ -61,7 +61,7 @@ def luminous_flux( Returns ------- - :class:`numpy.floating` + :class:`float` Luminous flux. References @@ -76,11 +76,8 @@ def luminous_flux( 23807.6555273... """ - lef = cast( - SpectralDistribution, - optional( - lef, SDS_LEFS_PHOTOPIC["CIE 1924 Photopic Standard Observer"] - ), + lef = optional( + lef, SDS_LEFS_PHOTOPIC["CIE 1924 Photopic Standard Observer"] ) lef = reshape_sd( @@ -96,7 +93,7 @@ def luminous_flux( def luminous_efficiency( sd: SpectralDistribution, lef: Optional[SpectralDistribution] = None -) -> Floating: +) -> float: """ Return the *luminous efficiency* of given spectral distribution using given luminous efficiency function. @@ -111,7 +108,7 @@ def luminous_efficiency( Returns ------- - :class:`numpy.floating` + :class:`float` Luminous efficiency. References @@ -126,11 +123,8 @@ def luminous_efficiency( 0.1994393... """ - lef = cast( - SpectralDistribution, - optional( - lef, SDS_LEFS_PHOTOPIC["CIE 1924 Photopic Standard Observer"] - ), + lef = optional( + lef, SDS_LEFS_PHOTOPIC["CIE 1924 Photopic Standard Observer"] ) lef = reshape_sd( @@ -148,7 +142,7 @@ def luminous_efficiency( def luminous_efficacy( sd: SpectralDistribution, lef: Optional[SpectralDistribution] = None -) -> Floating: +) -> float: """ Return the *luminous efficacy* in :math:`lm\\cdot W^{-1}` of given spectral distribution using given luminous efficiency function. @@ -163,7 +157,7 @@ def luminous_efficacy( Returns ------- - :class:`numpy.floating` + :class:`float` Luminous efficacy in :math:`lm\\cdot W^{-1}`. References diff --git a/colour/colorimetry/spectrum.py b/colour/colorimetry/spectrum.py index 83508f1709..924dd47aaa 100644 --- a/colour/colorimetry/spectrum.py +++ b/colour/colorimetry/spectrum.py @@ -30,6 +30,8 @@ import numpy as np from collections.abc import Mapping +# from typing import TypeVar + from colour.algebra import ( Extrapolator, CubicSplineInterpolator, @@ -42,27 +44,26 @@ from colour.hints import ( ArrayLike, Any, - Dict, - DTypeFloating, - FloatingOrArrayLike, + DTypeFloat, Generator, - Integer, - List, Literal, - NDArray, + NDArrayFloat, Number, Optional, Sequence, - Tuple, + Self, + TYPE_CHECKING, Type, TypeExtrapolator, TypeInterpolator, + TypeVar, Union, cast, ) from colour.utilities import ( CACHE_REGISTRY, as_float_array, + as_float_scalar, as_int, attest, filter_kwargs, @@ -81,13 +82,16 @@ ) from colour.utilities.deprecation import ObjectRenamed -if is_pandas_installed(): +if TYPE_CHECKING: from pandas import DataFrame, Series -else: # pragma: no cover - from unittest import mock +else: + if is_pandas_installed(): + from pandas import DataFrame, Series + else: # pragma: no cover + from unittest import mock - DataFrame = mock.MagicMock() - Series = mock.MagicMock() + DataFrame = mock.MagicMock() + Series = mock.MagicMock() __author__ = "Colour Developers" __copyright__ = "Copyright 2013 Colour Developers" @@ -107,7 +111,7 @@ "sds_and_msds_to_msds", ] -_CACHE_SHAPE_RANGE: Dict = CACHE_REGISTRY.register_cache( +_CACHE_SHAPE_RANGE: dict = CACHE_REGISTRY.register_cache( f"{__name__}._CACHE_SHAPE_RANGE" ) @@ -260,7 +264,7 @@ def interval(self, value: Number): self._interval = value @property - def boundaries(self) -> Tuple: + def boundaries(self) -> tuple: """ Getter and setter property for the spectral shape boundaries. @@ -292,7 +296,7 @@ def boundaries(self, value: ArrayLike): self.start, self.end = value @property - def wavelengths(self) -> NDArray: + def wavelengths(self) -> NDArrayFloat: """ Getter property for the spectral shape wavelengths. @@ -328,13 +332,13 @@ def __repr__(self) -> str: return f"SpectralShape({self._start}, {self._end}, {self._interval})" - def __hash__(self) -> Integer: + def __hash__(self) -> int: """ Return the spectral shape hash. Returns ------- - :class:`numpy.integer` + :class:`int` Object hash. """ @@ -370,7 +374,7 @@ def __iter__(self) -> Generator: yield from self.wavelengths - def __contains__(self, wavelength: FloatingOrArrayLike) -> bool: + def __contains__(self, wavelength: ArrayLike) -> bool: """ Return if the spectral shape contains given wavelength :math:`\\lambda`. @@ -400,13 +404,13 @@ def __contains__(self, wavelength: FloatingOrArrayLike) -> bool: False """ - decimals = np.finfo(DEFAULT_FLOAT_DTYPE).precision + decimals = np.finfo(cast(Any, DEFAULT_FLOAT_DTYPE)).precision return bool( np.all( np.in1d( np.around( - wavelength, # type: ignore[arg-type] + wavelength, # pyright: ignore decimals, ), np.around( @@ -417,13 +421,13 @@ def __contains__(self, wavelength: FloatingOrArrayLike) -> bool: ) ) - def __len__(self) -> Integer: + def __len__(self) -> int: """ Return the spectral shape wavelength :math:`\\lambda_n` count. Returns ------- - :class:`numpy.integer` + :class:`int` Spectral shape wavelength :math:`\\lambda_n` count. Examples @@ -485,7 +489,7 @@ def __ne__(self, other: Any) -> bool: return not (self == other) - def range(self, dtype: Optional[Type[DTypeFloating]] = None) -> NDArray: + def range(self, dtype: Optional[Type[DTypeFloat]] = None) -> NDArrayFloat: """ Return an iterable range for the spectral shape. @@ -516,7 +520,7 @@ def range(self, dtype: Optional[Type[DTypeFloating]] = None) -> NDArray: 9.9, 10. ]) """ - dtype = cast(Type[DTypeFloating], optional(dtype, DEFAULT_FLOAT_DTYPE)) + dtype = optional(dtype, DEFAULT_FLOAT_DTYPE) hash_key = tuple(hash(arg) for arg in (self, dtype)) if hash_key in _CACHE_SHAPE_RANGE: @@ -536,7 +540,7 @@ def range(self, dtype: Optional[Type[DTypeFloating]] = None) -> NDArray: _CACHE_SHAPE_RANGE[hash_key] = range_ if interval_effective != self._interval: - self._interval = interval_effective + self._interval = as_float_scalar(interval_effective) runtime_warning( f'"{(start, end, interval)}" shape could not be honoured, ' f'using "{self}"!' @@ -684,9 +688,7 @@ class SpectralDistribution(Signal): def __init__( self, - data: Optional[ - Union[ArrayLike, dict, Series, Signal, SpectralDistribution] - ] = None, + data: Optional[Union[ArrayLike, dict, Self, Series, Signal]] = None, domain: Optional[Union[ArrayLike, SpectralShape]] = None, **kwargs: Any, ) -> None: @@ -746,7 +748,7 @@ def display_name(self, value: str): self._display_name = value @property - def wavelengths(self) -> NDArray: + def wavelengths(self) -> NDArrayFloat: """ Getter and setter property for the spectral distribution wavelengths :math:`\\lambda_n`. @@ -772,7 +774,7 @@ def wavelengths(self, value: ArrayLike): self.domain = as_float_array(value, self.dtype) @property - def values(self) -> NDArray: + def values(self) -> NDArrayFloat: """ Getter and setter property for the spectral distribution values. @@ -852,8 +854,8 @@ def interpolate( self, shape: SpectralShape, interpolator: Optional[Type[TypeInterpolator]] = None, - interpolator_kwargs: Optional[Dict] = None, - ) -> SpectralDistribution: + interpolator_kwargs: Optional[dict] = None, + ) -> Self: """ Interpolate the spectral distribution in-place according to *CIE 167:2005* recommendation (if the interpolator has not been changed @@ -1222,8 +1224,8 @@ def extrapolate( self, shape: SpectralShape, extrapolator: Optional[Type[TypeExtrapolator]] = None, - extrapolator_kwargs: Optional[Dict] = None, - ) -> SpectralDistribution: + extrapolator_kwargs: Optional[dict] = None, + ) -> Self: """ Extrapolate the spectral distribution in-place according to *CIE 15:2004* and *CIE 167:2005* recommendations or given extrapolation @@ -1323,10 +1325,10 @@ def align( self, shape: SpectralShape, interpolator: Optional[Type[TypeInterpolator]] = None, - interpolator_kwargs: Optional[Dict] = None, + interpolator_kwargs: Optional[dict] = None, extrapolator: Optional[Type[TypeExtrapolator]] = None, - extrapolator_kwargs: Optional[Dict] = None, - ) -> SpectralDistribution: + extrapolator_kwargs: Optional[dict] = None, + ) -> Self: """ Align the spectral distribution in-place to given spectral shape: Interpolates first then extrapolates to fit the given range. @@ -1465,7 +1467,7 @@ def align( return self - def trim(self, shape: SpectralShape) -> SpectralDistribution: + def trim(self, shape: SpectralShape) -> Self: """ Trim the spectral distribution wavelengths to given spectral shape. @@ -1574,7 +1576,7 @@ def trim(self, shape: SpectralShape) -> SpectralDistribution: return self - def normalise(self, factor: Number = 1) -> SpectralDistribution: + def normalise(self, factor: Number = 1) -> Self: """ Normalise the spectral distribution using given normalization factor. @@ -1612,7 +1614,7 @@ def normalise(self, factor: Number = 1) -> SpectralDistribution: """ with sdiv_mode(): - self *= sdiv(1, max(self.values)) * factor # type: ignore[misc] + self *= sdiv(1, max(self.values)) * factor return self @@ -1826,7 +1828,7 @@ def __init__( DataFrame, dict, MultiSignals, - MultiSpectralDistributions, + Self, Sequence, Series, Signal, @@ -1865,7 +1867,7 @@ def __init__( self._display_name: str = self.name self.display_name = kwargs.get("display_name", self._display_name) - self._display_labels: List = list(self.signals.keys()) + self._display_labels: list = list(self.signals.keys()) self.display_labels = kwargs.get( "display_labels", self._display_labels ) @@ -1901,7 +1903,7 @@ def display_name(self, value: str): self._display_name = value @property - def display_labels(self) -> List[str]: + def display_labels(self) -> list[str]: """ Getter and setter property for the multi-spectral distributions display labels. @@ -1946,7 +1948,7 @@ def display_labels(self, value: Sequence): ).display_name = self._display_labels[i] @property - def wavelengths(self) -> NDArray: + def wavelengths(self) -> NDArrayFloat: """ Getter and setter property for the multi-spectral distributions wavelengths :math:`\\lambda_n`. @@ -1972,7 +1974,7 @@ def wavelengths(self, value: ArrayLike): self.domain = as_float_array(value, self.dtype) @property - def values(self) -> NDArray: + def values(self) -> NDArrayFloat: """ Getter and setter property for the multi-spectral distributions values. @@ -2045,8 +2047,8 @@ def interpolate( self, shape: SpectralShape, interpolator: Optional[Type[TypeInterpolator]] = None, - interpolator_kwargs: Optional[Dict] = None, - ) -> MultiSpectralDistributions: + interpolator_kwargs: Optional[dict] = None, + ) -> Self: """ Interpolate the multi-spectral distributions in-place according to *CIE 167:2005* recommendation (if the interpolator has not been changed @@ -2273,8 +2275,8 @@ def extrapolate( self, shape: SpectralShape, extrapolator: Optional[Type[TypeExtrapolator]] = None, - extrapolator_kwargs: Optional[Dict] = None, - ) -> MultiSpectralDistributions: + extrapolator_kwargs: Optional[dict] = None, + ) -> Self: """ Extrapolate the multi-spectral distributions in-place according to *CIE 15:2004* and *CIE 167:2005* recommendations or given extrapolation @@ -2360,10 +2362,10 @@ def align( self, shape: SpectralShape, interpolator: Optional[Type[TypeInterpolator]] = None, - interpolator_kwargs: Optional[Dict] = None, + interpolator_kwargs: Optional[dict] = None, extrapolator: Optional[Type[TypeExtrapolator]] = None, - extrapolator_kwargs: Optional[Dict] = None, - ) -> MultiSpectralDistributions: + extrapolator_kwargs: Optional[dict] = None, + ) -> Self: """ Align the multi-spectral distributions in-place to given spectral shape: Interpolates first then extrapolates to fit the given range. @@ -2509,7 +2511,7 @@ def align( return self - def trim(self, shape: SpectralShape) -> MultiSpectralDistributions: + def trim(self, shape: SpectralShape) -> Self: """ Trim the multi-spectral distributions wavelengths to given shape. @@ -2589,7 +2591,7 @@ def trim(self, shape: SpectralShape) -> MultiSpectralDistributions: return self - def normalise(self, factor: Number = 1) -> MultiSpectralDistributions: + def normalise(self, factor: Number = 1) -> Self: """ Normalise the multi-spectral distributions with given normalization factor. @@ -2639,7 +2641,7 @@ def normalise(self, factor: Number = 1) -> MultiSpectralDistributions: return self - def to_sds(self) -> List[SpectralDistribution]: + def to_sds(self) -> list[SpectralDistribution]: """ Convert the multi-spectral distributions to a list of spectral distributions. @@ -2647,7 +2649,7 @@ def to_sds(self) -> List[SpectralDistribution]: Returns ------- :class:`list` - List of spectral distributions. + list of spectral distributions. Examples -------- @@ -2754,19 +2756,24 @@ def strict_labels(self, value): # pragma: no cover # noqa: D102 self.display_labels = value -_CACHE_RESHAPED_SDS_AND_MSDS: Dict = CACHE_REGISTRY.register_cache( +_CACHE_RESHAPED_SDS_AND_MSDS: dict = CACHE_REGISTRY.register_cache( f"{__name__}._CACHE_RESHAPED_SDS_AND_MSDS" ) +TypeSpectralDistribution = TypeVar( + "TypeSpectralDistribution", bound="SpectralDistribution" +) + + def reshape_sd( - sd: SpectralDistribution, + sd: TypeSpectralDistribution, shape: SpectralShape = SPECTRAL_SHAPE_DEFAULT, method: Union[ Literal["Align", "Extrapolate", "Interpolate", "Trim"], str ] = "Align", **kwargs: Any, -) -> SpectralDistribution: +) -> TypeSpectralDistribution: """ Reshape given spectral distribution with given spectral shape. @@ -2827,14 +2834,19 @@ def reshape_sd( return reshaped_sd +TypeMultiSpectralDistributions = TypeVar( + "TypeMultiSpectralDistributions", bound="MultiSpectralDistributions" +) + + def reshape_msds( - msds: MultiSpectralDistributions, + msds: TypeMultiSpectralDistributions, shape: SpectralShape = SPECTRAL_SHAPE_DEFAULT, method: Union[ Literal["Align", "Extrapolate", "Interpolate", "Trim"], str ] = "Align", **kwargs: Any, -) -> MultiSpectralDistributions: +) -> TypeMultiSpectralDistributions: """ Reshape given multi-spectral distributions with given spectral shape. @@ -2869,9 +2881,7 @@ def reshape_msds( data! """ - return reshape_sd( - msds, shape, method, **kwargs # type: ignore[arg-type] - ) # type: ignore[return-value] + return reshape_sd(msds, shape, method, **kwargs) # pyright: ignore def sds_and_msds_to_sds( @@ -2879,7 +2889,7 @@ def sds_and_msds_to_sds( Sequence[Union[SpectralDistribution, MultiSpectralDistributions]], MultiSpectralDistributions, ] -) -> List[SpectralDistribution]: +) -> list[SpectralDistribution]: """ Convert given spectral and multi-spectral distributions to a list of spectral distributions. @@ -2893,7 +2903,7 @@ def sds_and_msds_to_sds( Returns ------- :class:`list` - List of spectral distributions. + list of spectral distributions. Examples -------- diff --git a/colour/colorimetry/tests/test_blackbody.py b/colour/colorimetry/tests/test_blackbody.py index 50e3afdbe6..775f48e7cc 100644 --- a/colour/colorimetry/tests/test_blackbody.py +++ b/colour/colorimetry/tests/test_blackbody.py @@ -14,7 +14,7 @@ rayleigh_jeans_law, sd_rayleigh_jeans, ) -from colour.hints import Dict, NDArray +from colour.hints import NDArrayFloat from colour.utilities import ignore_numpy_errors __author__ = "Colour Developers" @@ -36,7 +36,7 @@ ] -DATA_PLANCK_LAW: Dict = { +DATA_PLANCK_LAW: dict = { 1667: np.array( [ 0.000000000000000e000, @@ -139,7 +139,7 @@ ), } -DATA_BLACKBODY: NDArray = np.array( +DATA_BLACKBODY: NDArrayFloat = np.array( [ 6654.27827064, 6709.60527925, @@ -615,7 +615,7 @@ ] ) -DATA_RAYLEIGH_JEANS_LAW: Dict = { +DATA_RAYLEIGH_JEANS_LAW: dict = { 1667: np.array( [ 1.379970796097092e25, @@ -718,7 +718,7 @@ ), } -DATA_RAYLEIGH_JEANS: NDArray = np.array( +DATA_RAYLEIGH_JEANS: NDArrayFloat = np.array( [ 2464304.08580116, 2437112.02495309, diff --git a/colour/colorimetry/tests/test_correction.py b/colour/colorimetry/tests/test_correction.py index c45c12396c..4a90556817 100644 --- a/colour/colorimetry/tests/test_correction.py +++ b/colour/colorimetry/tests/test_correction.py @@ -8,7 +8,6 @@ SpectralDistribution, bandpass_correction_Stearns1988, ) -from colour.hints import Tuple __author__ = "Colour Developers" __copyright__ = "Copyright 2013 Colour Developers" @@ -23,7 +22,7 @@ "TestBandpassCorrectionStearns1988", ] -DATA_NON_BANDPASS_CORRECTED: Tuple = ( +DATA_NON_BANDPASS_CORRECTED: tuple = ( 9.3700, 12.3200, 12.4600, @@ -42,7 +41,7 @@ 86.0500, ) -DATA_BANDPASS_CORRECTED: Tuple = ( +DATA_BANDPASS_CORRECTED: tuple = ( 9.12515000, 12.57355255, 12.69542514, diff --git a/colour/colorimetry/tests/test_illuminants.py b/colour/colorimetry/tests/test_illuminants.py index df5f870bc5..d7e6a65ec8 100644 --- a/colour/colorimetry/tests/test_illuminants.py +++ b/colour/colorimetry/tests/test_illuminants.py @@ -13,7 +13,7 @@ sd_CIE_illuminant_D_series, daylight_locus_function, ) -from colour.hints import NDArray +from colour.hints import NDArrayFloat from colour.temperature import CCT_to_xy_CIE_D from colour.utilities import ignore_numpy_errors @@ -31,7 +31,7 @@ "TestDaylightLocusFunction", ] -DATA_A: NDArray = np.array( +DATA_A: NDArrayFloat = np.array( [ 6.14461778, 6.94719899, diff --git a/colour/colorimetry/tests/test_lefs.py b/colour/colorimetry/tests/test_lefs.py index a2b3b53d14..b4046faf27 100644 --- a/colour/colorimetry/tests/test_lefs.py +++ b/colour/colorimetry/tests/test_lefs.py @@ -8,7 +8,6 @@ mesopic_weighting_function, sd_mesopic_luminous_efficiency_function, ) -from colour.hints import Tuple from colour.utilities import ignore_numpy_errors __author__ = "Colour Developers" @@ -24,7 +23,7 @@ "TestSdMesopicLuminousEfficiencyFunction", ] -DATA_MESOPIC_LEF: Tuple = ( +DATA_MESOPIC_LEF: tuple = ( 0.000423996221042, 0.000478105586021, 0.000539901310829, diff --git a/colour/colorimetry/tests/test_spectrum.py b/colour/colorimetry/tests/test_spectrum.py index 2c6b26aa26..974a2db3f3 100644 --- a/colour/colorimetry/tests/test_spectrum.py +++ b/colour/colorimetry/tests/test_spectrum.py @@ -16,7 +16,6 @@ sds_and_msds_to_sds, sds_and_msds_to_msds, ) -from colour.hints import Dict, Tuple from colour.utilities import tstack __author__ = "Colour Developers" @@ -44,7 +43,7 @@ "TestSdsAndMsdsToMsds", ] -DATA_SAMPLE: Dict = { +DATA_SAMPLE: dict = { 340: 0.0000, 360: 0.0000, 380: 0.0000, @@ -72,7 +71,7 @@ 820: 0.0000, } -DATA_SAMPLE_NON_UNIFORM: Dict = { +DATA_SAMPLE_NON_UNIFORM: dict = { 391.898: 16.331740, 392.069: 16.333122, 405.606: 40.197224, @@ -129,7 +128,7 @@ 805.862: 8.850659, } -DATA_SAMPLE_INTERPOLATED: Tuple = ( +DATA_SAMPLE_INTERPOLATED: tuple = ( 0.000000000000000, 0.000230709627131, 0.000384144814593, @@ -613,7 +612,7 @@ 0.000000000000000, ) -DATA_SAMPLE_INTERPOLATED_NON_UNIFORM: Tuple = ( +DATA_SAMPLE_INTERPOLATED_NON_UNIFORM: tuple = ( 16.329808636577400, 16.722487609243078, 17.780769796558388, @@ -1030,7 +1029,7 @@ 7.652991396265083, ) -DATA_SAMPLE_NORMALISED: Tuple = ( +DATA_SAMPLE_NORMALISED: tuple = ( 0.000000000000000, 0.000000000000000, 0.000000000000000, @@ -1058,7 +1057,7 @@ 0.000000000000000, ) -DATA_STANDARD_OBSERVER_2_DEGREE_CIE1931: Dict = { +DATA_STANDARD_OBSERVER_2_DEGREE_CIE1931: dict = { 380: (0.001368, 0.000039, 0.006450), 385: (0.002236, 0.000064, 0.010550), 390: (0.004243, 0.000120, 0.020050), @@ -1142,7 +1141,7 @@ 780: (0.000042, 0.000015, 0.000000), } -DATA_CMFS: Dict = { +DATA_CMFS: dict = { 380: np.array([0.001368, 3.90e-05, 0.006450]), 385: np.array([0.002236, 6.40e-05, 0.010550]), 390: np.array([0.004243, 0.000120, 0.020050]), @@ -1226,7 +1225,7 @@ 780: np.array([4.20e-05, 1.50e-05, 0.000000]), } -DATA_SAMPLE_ABRIDGED: Dict = { +DATA_SAMPLE_ABRIDGED: dict = { 500: 0.0651, 520: 0.0705, 540: 0.0772, @@ -1235,7 +1234,7 @@ 600: 0.1360, } -DATA_MULTI_SAMPLE_ABRIDGED: Dict = { +DATA_MULTI_SAMPLE_ABRIDGED: dict = { 500: (0.004900, 0.323000, 0.272000), 510: (0.009300, 0.503000, 0.158200), 520: (0.063270, 0.710000, 0.078250), diff --git a/colour/colorimetry/tests/test_tristimulus_values.py b/colour/colorimetry/tests/test_tristimulus_values.py index 1b64d549b9..159350805f 100644 --- a/colour/colorimetry/tests/test_tristimulus_values.py +++ b/colour/colorimetry/tests/test_tristimulus_values.py @@ -41,7 +41,7 @@ msds_to_XYZ_ASTME308, wavelength_to_XYZ, ) -from colour.hints import NDArray +from colour.hints import NDArrayFloat from colour.utilities import domain_range_scale __author__ = "Colour Developers" @@ -184,7 +184,7 @@ } ) -LAGRANGE_COEFFICIENTS_A: NDArray = np.array( +LAGRANGE_COEFFICIENTS_A: NDArrayFloat = np.array( [ [-0.0285, 0.9405, 0.1045, -0.0165], [-0.0480, 0.8640, 0.2160, -0.0320], @@ -198,7 +198,7 @@ ] ) -LAGRANGE_COEFFICIENTS_B: NDArray = np.array( +LAGRANGE_COEFFICIENTS_B: NDArrayFloat = np.array( [ [0.8550, 0.1900, -0.0450], [0.7200, 0.3600, -0.0800], @@ -212,7 +212,7 @@ ] ) -TWF_A_CIE_1964_10_10: NDArray = np.array( +TWF_A_CIE_1964_10_10: NDArrayFloat = np.array( [ [-0.000, -0.000, -0.000], [-0.000, -0.000, -0.000], @@ -265,7 +265,7 @@ ] ) -TWF_A_CIE_1964_10_20: NDArray = np.array( +TWF_A_CIE_1964_10_20: NDArrayFloat = np.array( [ [-0.000, -0.000, -0.001], [-0.009, -0.001, -0.041], @@ -294,7 +294,7 @@ ] ) -TWF_D65_CIE_1931_2_20: NDArray = np.array( +TWF_D65_CIE_1931_2_20: NDArrayFloat = np.array( [ [-0.001, -0.000, -0.005], [-0.008, -0.000, -0.039], @@ -323,7 +323,7 @@ ] ) -TWF_D65_CIE_1931_2_20_K1: NDArray = np.array( +TWF_D65_CIE_1931_2_20_K1: NDArrayFloat = np.array( [ [-0.10095678, -0.00265636, -0.48295051], [-0.83484763, -0.02190274, -4.11563004], @@ -352,7 +352,7 @@ ] ) -TWF_D65_CIE_1931_2_20_A: NDArray = np.array( +TWF_D65_CIE_1931_2_20_A: NDArrayFloat = np.array( [ [0.170, 0.002, 0.785], [2.542, 0.071, 12.203], @@ -373,7 +373,7 @@ ] ) -DATA_TWO: NDArray = np.array( +DATA_TWO: NDArrayFloat = np.array( [ [ [ @@ -483,7 +483,7 @@ SpectralShape(400, 700, 60).wavelengths, ) -TVS_D65_INTEGRATION_MSDS: NDArray = np.array( +TVS_D65_INTEGRATION_MSDS: NDArrayFloat = np.array( [ [7.50219602, 3.95048275, 8.40152163], [26.92629005, 15.07170066, 28.71020457], @@ -500,7 +500,7 @@ ] ) -TVS_D65_ARRAY_INTEGRATION: NDArray = np.array( +TVS_D65_ARRAY_INTEGRATION: NDArrayFloat = np.array( [ [ [7.19510558, 3.86227393, 10.09950719], @@ -521,7 +521,7 @@ ] ) -TVS_D65_ARRAY_K1_INTEGRATION: NDArray = np.array( +TVS_D65_ARRAY_K1_INTEGRATION: NDArrayFloat = np.array( [ [ [7.7611755347, 4.1661356647, 10.8940789347], @@ -542,7 +542,7 @@ ] ) -TVS_D65_ASTME308_MSDS: NDArray = np.array( +TVS_D65_ASTME308_MSDS: NDArrayFloat = np.array( [ [7.50450425, 3.95744742, 8.38735462], [26.94116124, 15.09801442, 28.66753115], @@ -559,7 +559,7 @@ ] ) -TVS_D65_ASTME308_K1_MSDS: NDArray = np.array( +TVS_D65_ASTME308_K1_MSDS: NDArrayFloat = np.array( [ [7.9300584037, 4.1818604067, 8.8629721234], [28.4689001419, 15.9541699464, 30.2931664392], diff --git a/colour/colorimetry/tests/test_uniformity.py b/colour/colorimetry/tests/test_uniformity.py index 009a887511..5c4739bfd4 100644 --- a/colour/colorimetry/tests/test_uniformity.py +++ b/colour/colorimetry/tests/test_uniformity.py @@ -7,7 +7,7 @@ import unittest from colour.colorimetry import spectral_uniformity -from colour.hints import NDArray +from colour.hints import NDArrayFloat __author__ = "Colour Developers" __copyright__ = "Copyright 2013 Colour Developers" @@ -21,7 +21,7 @@ "TestSpectralUniformity", ] -DATA_UNIFORMITY_FIRST_ORDER_DERIVATIVES: NDArray = np.array( +DATA_UNIFORMITY_FIRST_ORDER_DERIVATIVES: NDArrayFloat = np.array( [ 9.55142857e-06, 1.14821429e-05, @@ -121,7 +121,7 @@ ] ) -DATA_UNIFORMITY_SECOND_ORDER_DERIVATIVES: NDArray = np.array( +DATA_UNIFORMITY_SECOND_ORDER_DERIVATIVES: NDArrayFloat = np.array( [ 7.97142857e-09, 3.69285714e-08, diff --git a/colour/colorimetry/transformations.py b/colour/colorimetry/transformations.py index 4b7b11de6d..16262589fd 100644 --- a/colour/colorimetry/transformations.py +++ b/colour/colorimetry/transformations.py @@ -41,7 +41,7 @@ SDS_LEFS_PHOTOPIC, reshape_sd, ) -from colour.hints import FloatingOrArrayLike, NDArray +from colour.hints import ArrayLike, NDArrayFloat from colour.utilities import tstack __author__ = "Colour Developers" @@ -61,8 +61,8 @@ def RGB_2_degree_cmfs_to_XYZ_2_degree_cmfs( - wavelength: FloatingOrArrayLike, -) -> NDArray: + wavelength: ArrayLike, +) -> NDArrayFloat: """ Convert *Wright & Guild 1931 2 Degree RGB CMFs* colour matching functions into the *CIE 1931 2 Degree Standard Observer* colour matching functions. @@ -136,8 +136,8 @@ def RGB_2_degree_cmfs_to_XYZ_2_degree_cmfs( def RGB_10_degree_cmfs_to_XYZ_10_degree_cmfs( - wavelength: FloatingOrArrayLike, -) -> NDArray: + wavelength: ArrayLike, +) -> NDArrayFloat: """ Convert *Stiles & Burch 1959 10 Degree RGB CMFs* colour matching functions into the *CIE 1964 10 Degree Standard Observer* colour matching @@ -189,8 +189,8 @@ def RGB_10_degree_cmfs_to_XYZ_10_degree_cmfs( def RGB_10_degree_cmfs_to_LMS_10_degree_cmfs( - wavelength: FloatingOrArrayLike, -) -> NDArray: + wavelength: ArrayLike, +) -> NDArrayFloat: """ Convert *Stiles & Burch 1959 10 Degree RGB CMFs* colour matching functions into the *Stockman & Sharpe 10 Degree Cone Fundamentals* @@ -244,8 +244,8 @@ def RGB_10_degree_cmfs_to_LMS_10_degree_cmfs( def LMS_2_degree_cmfs_to_XYZ_2_degree_cmfs( - wavelength: FloatingOrArrayLike, -) -> NDArray: + wavelength: ArrayLike, +) -> NDArrayFloat: """ Convert *Stockman & Sharpe 2 Degree Cone Fundamentals* colour matching functions into the *CIE 2015 2 Degree Standard Observer* colour matching @@ -297,8 +297,8 @@ def LMS_2_degree_cmfs_to_XYZ_2_degree_cmfs( def LMS_10_degree_cmfs_to_XYZ_10_degree_cmfs( - wavelength: FloatingOrArrayLike, -) -> NDArray: + wavelength: ArrayLike, +) -> NDArrayFloat: """ Convert *Stockman & Sharpe 10 Degree Cone Fundamentals* colour matching functions into the *CIE 2015 10 Degree Standard Observer* colour matching diff --git a/colour/colorimetry/tristimulus_values.py b/colour/colorimetry/tristimulus_values.py index 70935b7ffd..fde4a1df4b 100644 --- a/colour/colorimetry/tristimulus_values.py +++ b/colour/colorimetry/tristimulus_values.py @@ -50,15 +50,10 @@ from colour.hints import ( Any, ArrayLike, - Boolean, - Dict, - FloatingOrNDArray, - Integer, Literal, - NDArray, + NDArrayFloat, Number, Optional, - Tuple, Union, cast, ) @@ -110,17 +105,17 @@ :cite:`ASTMInternational2015b` """ -_CACHE_LAGRANGE_INTERPOLATING_COEFFICIENTS: Dict = ( +_CACHE_LAGRANGE_INTERPOLATING_COEFFICIENTS: dict = ( CACHE_REGISTRY.register_cache( f"{__name__}._CACHE_LAGRANGE_INTERPOLATING_COEFFICIENTS" ) ) -_CACHE_TRISTIMULUS_WEIGHTING_FACTORS: Dict = CACHE_REGISTRY.register_cache( +_CACHE_TRISTIMULUS_WEIGHTING_FACTORS: dict = CACHE_REGISTRY.register_cache( f"{__name__}._CACHE_TRISTIMULUS_WEIGHTING_FACTORS" ) -_CACHE_SD_TO_XYZ: Dict = CACHE_REGISTRY.register_cache( +_CACHE_SD_TO_XYZ: dict = CACHE_REGISTRY.register_cache( f"{__name__}._CACHE_SD_TO_XYZ" ) @@ -132,7 +127,7 @@ def handle_spectral_arguments( illuminant_default: str = "D65", shape_default: SpectralShape = SPECTRAL_SHAPE_DEFAULT, issue_runtime_warnings: bool = True, -) -> Tuple[MultiSpectralDistributions, SpectralDistribution]: +) -> tuple[MultiSpectralDistributions, SpectralDistribution]: """ Handle the spectral arguments of various *Colour* definitions performing spectral computations. @@ -202,9 +197,9 @@ def handle_spectral_arguments( def lagrange_coefficients_ASTME2022( - interval: Integer = 10, + interval: int = 10, interval_type: Union[Literal["Boundary", "Inner"], str] = "Inner", -) -> NDArray: +) -> NDArrayFloat: """ Compute the *Lagrange Coefficients* for given interval size using practise *ASTM E2022-11* method. @@ -282,7 +277,7 @@ def tristimulus_weighting_factors_ASTME2022( illuminant: SpectralDistribution, shape: SpectralShape, k: Optional[Number] = None, -) -> NDArray: +) -> NDArrayFloat: """ Return a table of tristimulus weighting factors for given colour matching functions and illuminant using practise *ASTM E2022-11* method. @@ -461,7 +456,7 @@ def tristimulus_weighting_factors_ASTME2022( def adjust_tristimulus_weighting_factors_ASTME308( W: ArrayLike, shape_r: SpectralShape, shape_t: SpectralShape -) -> NDArray: +) -> NDArrayFloat: """ Adjust given table of tristimulus weighting factors to account for a shorter wavelengths range of the test spectral shape compared to the @@ -545,7 +540,7 @@ def sd_to_XYZ_integration( illuminant: Optional[SpectralDistribution] = None, k: Optional[Number] = None, shape: Optional[SpectralShape] = None, -) -> NDArray: +) -> NDArrayFloat: """ Convert given spectral distribution to *CIE XYZ* tristimulus values using given colour matching functions and illuminant according to classical @@ -745,7 +740,7 @@ def sd_to_XYZ_tristimulus_weighting_factors_ASTME308( cmfs: Optional[MultiSpectralDistributions] = None, illuminant: Optional[SpectralDistribution] = None, k: Optional[Number] = None, -) -> NDArray: +) -> NDArrayFloat: """ Convert given spectral distribution to *CIE XYZ* tristimulus values using given colour matching functions and illuminant using a table of @@ -886,11 +881,11 @@ def sd_to_XYZ_ASTME308( sd: SpectralDistribution, cmfs: Optional[MultiSpectralDistributions] = None, illuminant: Optional[SpectralDistribution] = None, - use_practice_range: Boolean = True, - mi_5nm_omission_method: Boolean = True, - mi_20nm_interpolation_method: Boolean = True, + use_practice_range: bool = True, + mi_5nm_omission_method: bool = True, + mi_20nm_interpolation_method: bool = True, k: Optional[Number] = None, -) -> NDArray: +) -> NDArrayFloat: """ Convert given spectral distribution to *CIE XYZ* tristimulus values using given colour matching functions and illuminant according to practise @@ -1027,7 +1022,7 @@ def sd_to_XYZ_ASTME308( ) method = sd_to_XYZ_integration elif sd.shape.interval == 20 and mi_20nm_interpolation_method: - sd = cast(SpectralDistribution, sd.copy()) + sd = sd.copy() if sd.shape.boundaries != cmfs.shape.boundaries: runtime_warning( f'Trimming "{illuminant.name}" spectral distribution shape to ' @@ -1095,7 +1090,7 @@ def sd_to_XYZ( k: Optional[Number] = None, method: Union[Literal["ASTM E308", "Integration"], str] = "ASTM E308", **kwargs: Any, -) -> NDArray: +) -> NDArrayFloat: """ Convert given spectral distribution to *CIE XYZ* tristimulus values using given colour matching functions, illuminant and method. @@ -1253,7 +1248,7 @@ def sd_to_XYZ( if isinstance( sd, (SpectralDistribution, MultiSpectralDistributions) ) - else sd.tobytes(), # type: ignore[union-attr] + else sd.tobytes(), # pyright: ignore cmfs, illuminant, k, @@ -1282,7 +1277,7 @@ def msds_to_XYZ_integration( illuminant: Optional[SpectralDistribution] = None, k: Optional[Number] = None, shape: Optional[SpectralShape] = None, -) -> NDArray: +) -> NDArrayFloat: """ Convert given multi-spectral distributions to *CIE XYZ* tristimulus values using given colour matching functions and illuminant. @@ -1517,10 +1512,10 @@ def msds_to_XYZ_ASTME308( cmfs: Optional[MultiSpectralDistributions] = None, illuminant: Optional[SpectralDistribution] = None, k: Optional[Number] = None, - use_practice_range: Boolean = True, - mi_5nm_omission_method: Boolean = True, - mi_20nm_interpolation_method: Boolean = True, -) -> NDArray: + use_practice_range: bool = True, + mi_5nm_omission_method: bool = True, + mi_20nm_interpolation_method: bool = True, +) -> NDArrayFloat: """ Convert given multi-spectral distributions to *CIE XYZ* tristimulus values using given colour matching functions and illuminant according to practise @@ -1770,7 +1765,7 @@ def msds_to_XYZ( k: Optional[Number] = None, method: Union[Literal["ASTM E308", "Integration"], str] = "ASTM E308", **kwargs: Any, -) -> NDArray: +) -> NDArrayFloat: """ Convert given multi-spectral distributions to *CIE XYZ* tristimulus values using given colour matching functions and illuminant. For the *Integration* @@ -2028,9 +2023,9 @@ class on the last / tail axis as follows: def wavelength_to_XYZ( - wavelength: FloatingOrNDArray, + wavelength: ArrayLike, cmfs: Optional[MultiSpectralDistributions] = None, -) -> NDArray: +) -> NDArrayFloat: """ Convert given wavelength :math:`\\lambda` to *CIE XYZ* tristimulus values using given colour matching functions. diff --git a/colour/colorimetry/uniformity.py b/colour/colorimetry/uniformity.py index 5e55f66c5b..d3449264ca 100644 --- a/colour/colorimetry/uniformity.py +++ b/colour/colorimetry/uniformity.py @@ -22,7 +22,7 @@ SpectralDistribution, sds_and_msds_to_msds, ) -from colour.hints import Boolean, List, NDArray, Union +from colour.hints import NDArrayFloat, Union __author__ = "Colour Developers" __copyright__ = "Copyright 2013 Colour Developers" @@ -38,11 +38,11 @@ def spectral_uniformity( sds: Union[ - List[Union[SpectralDistribution, MultiSpectralDistributions]], + list[Union[SpectralDistribution, MultiSpectralDistributions]], MultiSpectralDistributions, ], - use_second_order_derivatives: Boolean = False, -) -> NDArray: + use_second_order_derivatives: bool = False, +) -> NDArrayFloat: """ Compute the *spectral uniformity* (or *spectral flatness*) of given spectral distributions. diff --git a/colour/colorimetry/whiteness.py b/colour/colorimetry/whiteness.py index d680efabe4..931a2bebea 100644 --- a/colour/colorimetry/whiteness.py +++ b/colour/colorimetry/whiteness.py @@ -47,9 +47,8 @@ from colour.hints import ( Any, ArrayLike, - FloatingOrNDArray, Literal, - NDArray, + NDArrayFloat, Union, ) from colour.utilities import ( @@ -84,9 +83,7 @@ ] -def whiteness_Berger1959( - XYZ: ArrayLike, XYZ_0: ArrayLike -) -> FloatingOrNDArray: +def whiteness_Berger1959(XYZ: ArrayLike, XYZ_0: ArrayLike) -> NDArrayFloat: """ Return the *whiteness* index :math:`WI` of given sample *CIE XYZ* tristimulus values using *Berger (1959)* method. @@ -100,7 +97,7 @@ def whiteness_Berger1959( Returns ------- - :class:`np.floating` or :class:`numpy.ndarray` + :class:`np.float` or :class:`numpy.ndarray` *Whiteness* :math:`WI`. Notes @@ -143,7 +140,7 @@ def whiteness_Berger1959( return as_float(from_range_100(WI)) -def whiteness_Taube1960(XYZ: ArrayLike, XYZ_0: ArrayLike) -> FloatingOrNDArray: +def whiteness_Taube1960(XYZ: ArrayLike, XYZ_0: ArrayLike) -> NDArrayFloat: """ Return the *whiteness* index :math:`WI` of given sample *CIE XYZ* tristimulus values using *Taube (1960)* method. @@ -157,7 +154,7 @@ def whiteness_Taube1960(XYZ: ArrayLike, XYZ_0: ArrayLike) -> FloatingOrNDArray: Returns ------- - :class:`np.floating` or :class:`numpy.ndarray` + :class:`np.float` or :class:`numpy.ndarray` *Whiteness* :math:`WI`. Notes @@ -200,7 +197,7 @@ def whiteness_Taube1960(XYZ: ArrayLike, XYZ_0: ArrayLike) -> FloatingOrNDArray: return as_float(from_range_100(WI)) -def whiteness_Stensby1968(Lab: ArrayLike) -> FloatingOrNDArray: +def whiteness_Stensby1968(Lab: ArrayLike) -> NDArrayFloat: """ Return the *whiteness* index :math:`WI` of given sample *CIE L\\*a\\*b\\** colourspace array using *Stensby (1968)* method. @@ -212,7 +209,7 @@ def whiteness_Stensby1968(Lab: ArrayLike) -> FloatingOrNDArray: Returns ------- - :class:`np.floating` or :class:`numpy.ndarray` + :class:`np.float` or :class:`numpy.ndarray` *Whiteness* :math:`WI`. Notes @@ -255,7 +252,7 @@ def whiteness_Stensby1968(Lab: ArrayLike) -> FloatingOrNDArray: return as_float(from_range_100(WI)) -def whiteness_ASTME313(XYZ: ArrayLike) -> FloatingOrNDArray: +def whiteness_ASTME313(XYZ: ArrayLike) -> NDArrayFloat: """ Return the *whiteness* index :math:`WI` of given sample *CIE XYZ* tristimulus values using *ASTM E313* method. @@ -267,7 +264,7 @@ def whiteness_ASTME313(XYZ: ArrayLike) -> FloatingOrNDArray: Returns ------- - :class:`np.floating` or :class:`numpy.ndarray` + :class:`np.float` or :class:`numpy.ndarray` *Whiteness* :math:`WI`. Notes @@ -303,7 +300,7 @@ def whiteness_ASTME313(XYZ: ArrayLike) -> FloatingOrNDArray: return as_float(from_range_100(WI)) -def whiteness_Ganz1979(xy: ArrayLike, Y: FloatingOrNDArray) -> NDArray: +def whiteness_Ganz1979(xy: ArrayLike, Y: ArrayLike) -> NDArrayFloat: """ Return the *whiteness* index :math:`W` and *tint* :math:`T` of given sample *CIE xy* chromaticity coordinates using *Ganz and Griesser (1979)* @@ -370,13 +367,13 @@ def whiteness_Ganz1979(xy: ArrayLike, Y: FloatingOrNDArray) -> NDArray: def whiteness_CIE2004( xy: ArrayLike, - Y: FloatingOrNDArray, + Y: ArrayLike, xy_n: ArrayLike, observer: Literal[ "CIE 1931 2 Degree Standard Observer", "CIE 1964 10 Degree Standard Observer", ] = ("CIE 1931 2 Degree Standard Observer"), -) -> NDArray: +) -> NDArrayFloat: """ Return the *whiteness* :math:`W` or :math:`W_{10}` and *tint* :math:`T` or :math:`T_{10}` of given sample *CIE xy* chromaticity coordinates using @@ -490,7 +487,7 @@ def whiteness( str, ] = "CIE 2004", **kwargs: Any, -) -> FloatingOrNDArray: +) -> NDArrayFloat: """ Return the *whiteness* :math:`W` using given method. @@ -512,7 +509,7 @@ def whiteness( Returns ------- - :class:`np.floating` or :class:`numpy.ndarray` + :class:`np.float` or :class:`numpy.ndarray` *Whiteness* :math:`W`. Notes diff --git a/colour/colorimetry/yellowness.py b/colour/colorimetry/yellowness.py index c57f545b46..6c302d3783 100644 --- a/colour/colorimetry/yellowness.py +++ b/colour/colorimetry/yellowness.py @@ -37,7 +37,7 @@ from colour.hints import ( Any, ArrayLike, - FloatingOrNDArray, + NDArrayFloat, Literal, Union, ) @@ -68,7 +68,7 @@ ] -def yellowness_ASTMD1925(XYZ: ArrayLike) -> FloatingOrNDArray: +def yellowness_ASTMD1925(XYZ: ArrayLike) -> NDArrayFloat: """ Return the *yellowness* index :math:`YI` of given sample *CIE XYZ* tristimulus values using *ASTM D1925* method. @@ -86,7 +86,7 @@ def yellowness_ASTMD1925(XYZ: ArrayLike) -> FloatingOrNDArray: Returns ------- - :class:`np.floating` or :class:`numpy.ndarray` + :class:`np.float` or :class:`numpy.ndarray` *Yellowness* :math:`YI`. Notes @@ -125,7 +125,7 @@ def yellowness_ASTMD1925(XYZ: ArrayLike) -> FloatingOrNDArray: return as_float(from_range_100(YI)) -def yellowness_ASTME313_alternative(XYZ: ArrayLike) -> FloatingOrNDArray: +def yellowness_ASTME313_alternative(XYZ: ArrayLike) -> NDArrayFloat: """ Return the *yellowness* index :math:`YI` of given sample *CIE XYZ* tristimulus values using the alternative *ASTM E313* method. @@ -145,7 +145,7 @@ def yellowness_ASTME313_alternative(XYZ: ArrayLike) -> FloatingOrNDArray: Returns ------- - :class:`np.floating` or :class:`numpy.ndarray` + :class:`np.float` or :class:`numpy.ndarray` *Yellowness* :math:`YI`. Notes @@ -226,7 +226,7 @@ def yellowness_ASTME313( C_XZ: ArrayLike = YELLOWNESS_COEFFICIENTS_ASTME313[ "CIE 1931 2 Degree Standard Observer" ]["D65"], -) -> FloatingOrNDArray: +) -> NDArrayFloat: """ Return the *yellowness* index :math:`YI` of given sample *CIE XYZ* tristimulus values using *ASTM E313* method. @@ -246,7 +246,7 @@ def yellowness_ASTME313( Returns ------- - :class:`np.floating` or :class:`numpy.ndarray` + :class:`np.float` or :class:`numpy.ndarray` *Yellowness* :math:`YI`. Notes @@ -305,7 +305,7 @@ def yellowness( Literal["ASTM D1925", "ASTM E313", "ASTM E313 Alternative"], str ] = "ASTM E313", **kwargs: Any, -) -> FloatingOrNDArray: +) -> NDArrayFloat: """ Return the *yellowness* :math:`W` using given method. @@ -327,7 +327,7 @@ def yellowness( Returns ------- - :class:`np.floating` or :class:`numpy.ndarray` + :class:`np.float` or :class:`numpy.ndarray` *Yellowness* :math:`Y`. Notes diff --git a/colour/constants/common.py b/colour/constants/common.py index fce6c88810..1224db9fbc 100644 --- a/colour/constants/common.py +++ b/colour/constants/common.py @@ -15,7 +15,7 @@ DocstringFloat, is_documentation_building, ) -from colour.hints import DTypeFloating, Floating, Type, Union, cast +from colour.hints import DTypeFloat, Type, Union, cast __author__ = "Colour Developers" __copyright__ = "Copyright 2013 Colour Developers" @@ -33,17 +33,17 @@ ] FLOATING_POINT_NUMBER_PATTERN: str = "[0-9]*\\.?[0-9]+([eE][-+]?[0-9]+)?" -"""Floating point number regex matching pattern.""" +"""float point number regex matching pattern.""" INTEGER_THRESHOLD: float = 1e-3 if is_documentation_building(): # pragma: no cover INTEGER_THRESHOLD = DocstringFloat(INTEGER_THRESHOLD) INTEGER_THRESHOLD.__doc__ = """ -Integer threshold value when checking if a floating point number is almost an -integer. +int threshold value when checking if a float point number is almost an +int. """ -EPSILON: Floating = cast(Floating, np.finfo(np.float_).eps) +EPSILON: float = cast(float, np.finfo(np.float_).eps) """ Default epsilon value for tolerance and singularities avoidance in various computations. @@ -55,14 +55,14 @@ os.environ.get("COLOUR_SCIENCE__DEFAULT_INT_DTYPE", "int64"), np.int64 ), ) -"""Default integer number dtype.""" +"""Default int number dtype.""" -DEFAULT_FLOAT_DTYPE: Type[DTypeFloating] = cast( - Type[DTypeFloating], +DEFAULT_FLOAT_DTYPE: Type[DTypeFloat] = cast( + Type[DTypeFloat], np.sctypeDict.get( os.environ.get("COLOUR_SCIENCE__DEFAULT_FLOAT_DTYPE", "float64"), np.float64, ), ) -"""Default floating point number dtype.""" +"""Default float point number dtype.""" diff --git a/colour/continuous/abstract.py b/colour/continuous/abstract.py index 9c279ff359..ba48e8c5d3 100644 --- a/colour/continuous/abstract.py +++ b/colour/continuous/abstract.py @@ -17,17 +17,13 @@ from colour.hints import ( ArrayLike, Any, - Boolean, Callable, - Dict, - DTypeFloating, - FloatingOrArrayLike, - FloatingOrNDArray, - Integer, + DTypeFloat, Literal, - NDArray, + NDArrayFloat, Number, Optional, + Self, Type, TypeExtrapolator, TypeInterpolator, @@ -156,7 +152,7 @@ def name(self, value: str): @property @abstractmethod - def dtype(self) -> Type[DTypeFloating]: + def dtype(self) -> Type[DTypeFloat]: """ Getter and setter property for the abstract continuous function dtype, must be reimplemented by sub-classes. @@ -168,7 +164,7 @@ def dtype(self) -> Type[DTypeFloating]: Returns ------- - Type[DTypeFloating] + Type[DTypeFloat] Abstract continuous function dtype. """ @@ -176,7 +172,7 @@ def dtype(self) -> Type[DTypeFloating]: @dtype.setter @abstractmethod - def dtype(self, value: Type[DTypeFloating]): + def dtype(self, value: Type[DTypeFloat]): """ Setter for the **self.dtype** property, must be reimplemented by sub-classes. @@ -186,7 +182,7 @@ def dtype(self, value: Type[DTypeFloating]): @property @abstractmethod - def domain(self) -> NDArray: + def domain(self) -> NDArrayFloat: """ Getter and setter property for the abstract continuous function independent domain variable :math:`x`, must be reimplemented by @@ -218,7 +214,7 @@ def domain(self, value: ArrayLike): @property @abstractmethod - def range(self) -> NDArray: + def range(self) -> NDArrayFloat: """ Getter and setter property for the abstract continuous function corresponding range variable :math:`y`, must be reimplemented by @@ -282,7 +278,7 @@ def interpolator(self, value: Type[TypeInterpolator]): @property @abstractmethod - def interpolator_kwargs(self) -> Dict: + def interpolator_kwargs(self) -> dict: """ Getter and setter property for the abstract continuous function interpolator instantiation time arguments, must be reimplemented by @@ -346,7 +342,7 @@ def extrapolator(self, value: Type[TypeExtrapolator]): @property @abstractmethod - def extrapolator_kwargs(self) -> Dict: + def extrapolator_kwargs(self) -> dict: """ Getter and setter property for the abstract continuous function extrapolator instantiation time arguments, must be reimplemented by @@ -421,22 +417,20 @@ def __repr__(self) -> str: return super().__repr__() # pragma: no cover @abstractmethod - def __hash__(self) -> Integer: + def __hash__(self) -> int: """ Return the abstract continuous function hash. Returns ------- - :class:`numpy.integer` + :class:`int` Object hash. """ ... # pragma: no cover @abstractmethod - def __getitem__( - self, x: Union[FloatingOrArrayLike, slice] - ) -> FloatingOrNDArray: + def __getitem__(self, x: Union[ArrayLike, slice]) -> NDArrayFloat: """ Return the corresponding range variable :math:`y` for independent domain variable :math:`x`, must be reimplemented by sub-classes. @@ -448,16 +442,14 @@ def __getitem__( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Variable :math:`y` range value. """ ... # pragma: no cover @abstractmethod - def __setitem__( - self, x: Union[FloatingOrArrayLike, slice], y: FloatingOrArrayLike - ): + def __setitem__(self, x: Union[ArrayLike, slice], y: ArrayLike): """ Set the corresponding range variable :math:`y` for independent domain variable :math:`x`, must be reimplemented by sub-classes. @@ -473,7 +465,7 @@ def __setitem__( ... # pragma: no cover @abstractmethod - def __contains__(self, x: Union[FloatingOrArrayLike, slice]) -> bool: + def __contains__(self, x: Union[ArrayLike, slice]) -> bool: """ Return whether the abstract continuous function contains given independent domain variable :math:`x`, must be reimplemented by @@ -492,7 +484,7 @@ def __contains__(self, x: Union[FloatingOrArrayLike, slice]) -> bool: ... # pragma: no cover - def __len__(self) -> Integer: + def __len__(self) -> int: """ Return the abstract continuous function independent domain :math:`x` variable elements count. @@ -500,7 +492,7 @@ def __len__(self) -> Integer: Returns ------- - :class:`numpy.integer` + :class:`int` Independent domain variable :math:`x` elements count. """ @@ -547,9 +539,7 @@ def __ne__(self, other: Any) -> bool: ... # pragma: no cover - def __add__( - self, a: Union[FloatingOrArrayLike, AbstractContinuousFunction] - ) -> AbstractContinuousFunction: + def __add__(self, a: Union[ArrayLike, Self]) -> Self: """ Implement support for addition. @@ -566,9 +556,7 @@ def __add__( return self.arithmetical_operation(a, "+") - def __iadd__( - self, a: Union[FloatingOrArrayLike, AbstractContinuousFunction] - ) -> AbstractContinuousFunction: + def __iadd__(self, a: Union[ArrayLike, Self]) -> Self: """ Implement support for in-place addition. @@ -585,9 +573,7 @@ def __iadd__( return self.arithmetical_operation(a, "+", True) - def __sub__( - self, a: Union[FloatingOrArrayLike, AbstractContinuousFunction] - ) -> AbstractContinuousFunction: + def __sub__(self, a: Union[ArrayLike, Self]) -> Self: """ Implement support for subtraction. @@ -604,9 +590,7 @@ def __sub__( return self.arithmetical_operation(a, "-") - def __isub__( - self, a: Union[FloatingOrArrayLike, AbstractContinuousFunction] - ) -> AbstractContinuousFunction: + def __isub__(self, a: Union[ArrayLike, Self]) -> Self: """ Implement support for in-place subtraction. @@ -623,9 +607,7 @@ def __isub__( return self.arithmetical_operation(a, "-", True) - def __mul__( - self, a: Union[FloatingOrArrayLike, AbstractContinuousFunction] - ) -> AbstractContinuousFunction: + def __mul__(self, a: Union[ArrayLike, Self]) -> Self: """ Implement support for multiplication. @@ -642,9 +624,7 @@ def __mul__( return self.arithmetical_operation(a, "*") - def __imul__( - self, a: Union[FloatingOrArrayLike, AbstractContinuousFunction] - ) -> AbstractContinuousFunction: + def __imul__(self, a: Union[ArrayLike, Self]) -> Self: """ Implement support for in-place multiplication. @@ -661,9 +641,7 @@ def __imul__( return self.arithmetical_operation(a, "*", True) - def __div__( - self, a: Union[FloatingOrArrayLike, AbstractContinuousFunction] - ) -> AbstractContinuousFunction: + def __div__(self, a: Union[ArrayLike, Self]) -> Self: """ Implement support for division. @@ -680,9 +658,7 @@ def __div__( return self.arithmetical_operation(a, "/") - def __idiv__( - self, a: Union[FloatingOrArrayLike, AbstractContinuousFunction] - ) -> AbstractContinuousFunction: + def __idiv__(self, a: Union[ArrayLike, Self]) -> Self: """ Implement support for in-place division. @@ -702,9 +678,7 @@ def __idiv__( __itruediv__ = __idiv__ __truediv__ = __div__ - def __pow__( - self, a: Union[FloatingOrArrayLike, AbstractContinuousFunction] - ) -> AbstractContinuousFunction: + def __pow__(self, a: Union[ArrayLike, Self]) -> Self: """ Implement support for exponentiation. @@ -721,9 +695,7 @@ def __pow__( return self.arithmetical_operation(a, "**") - def __ipow__( - self, a: Union[FloatingOrArrayLike, AbstractContinuousFunction] - ) -> AbstractContinuousFunction: + def __ipow__(self, a: Union[ArrayLike, Self]) -> Self: """ Implement support for in-place exponentiation. @@ -743,10 +715,10 @@ def __ipow__( @abstractmethod def arithmetical_operation( self, - a: Union[FloatingOrArrayLike, AbstractContinuousFunction], + a: Union[ArrayLike, Self], operation: Literal["+", "-", "*", "/", "**"], - in_place: Boolean = False, - ) -> AbstractContinuousFunction: + in_place: bool = False, + ) -> Self: """ Perform given arithmetical operation with operand :math:`a`, the operation can be either performed on a copy or in-place, must be @@ -776,7 +748,7 @@ def fill_nan( Literal["Constant", "Interpolation"], str ] = "Interpolation", default: Number = 0, - ) -> AbstractContinuousFunction: + ) -> Self: """ Fill NaNs in independent domain variable :math:`x` and corresponding range variable :math:`y` using given method, must be reimplemented by @@ -798,7 +770,7 @@ def fill_nan( ... # pragma: no cover - def domain_distance(self, a: FloatingOrArrayLike) -> FloatingOrNDArray: + def domain_distance(self, a: ArrayLike) -> NDArrayFloat: """ Return the euclidean distance between given array and independent domain :math:`x` closest element. @@ -811,7 +783,7 @@ def domain_distance(self, a: FloatingOrArrayLike) -> FloatingOrNDArray: Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Euclidean distance between independent domain variable :math:`x` and given variable :math:`a`. """ @@ -820,7 +792,7 @@ def domain_distance(self, a: FloatingOrArrayLike) -> FloatingOrNDArray: return as_float(np.abs(a - n)) - def is_uniform(self) -> Boolean: + def is_uniform(self) -> bool: """ Return if independent domain variable :math:`x` is uniform. @@ -832,7 +804,7 @@ def is_uniform(self) -> Boolean: return is_uniform(self.domain) - def copy(self) -> AbstractContinuousFunction: + def copy(self) -> Self: """ Return a copy of the sub-class instance. diff --git a/colour/continuous/multi_signals.py b/colour/continuous/multi_signals.py index 37d1d035ab..3f17996418 100644 --- a/colour/continuous/multi_signals.py +++ b/colour/continuous/multi_signals.py @@ -17,19 +17,15 @@ from colour.hints import ( Any, ArrayLike, - Boolean, Callable, - Dict, - DTypeFloating, - FloatingOrArrayLike, - FloatingOrNDArray, - Integer, - List, + DTypeFloat, Literal, - NDArray, + NDArrayFloat, Number, Optional, Sequence, + Self, + TYPE_CHECKING, Type, TypeExtrapolator, TypeInterpolator, @@ -51,13 +47,16 @@ ) from colour.utilities.documentation import is_documentation_building -if is_pandas_installed(): +if TYPE_CHECKING: from pandas import DataFrame, Series -else: # pragma: no cover - from unittest import mock +else: + if is_pandas_installed(): + from pandas import DataFrame, Series + else: # pragma: no cover + from unittest import mock - DataFrame = mock.MagicMock() - Series = mock.MagicMock() + DataFrame = mock.MagicMock() + Series = mock.MagicMock() __author__ = "Colour Developers" __copyright__ = "Copyright 2013 Colour Developers" @@ -99,7 +98,7 @@ class MultiSignals(AbstractContinuousFunction): Other Parameters ---------------- dtype - Floating point data type. + float point data type. extrapolator Extrapolator class type to use as extrapolating function for the :class:`colour.continuous.Signal` sub-class instances. @@ -309,7 +308,7 @@ def __init__( ArrayLike, DataFrame, dict, - MultiSignals, + Self, Sequence, Series, Signal, @@ -323,12 +322,12 @@ def __init__( self._signal_type: Type[Signal] = kwargs.get("signal_type", Signal) - self._signals: Dict[str, Signal] = self.multi_signals_unpack_data( + self._signals: dict[str, Signal] = self.multi_signals_unpack_data( data, domain, labels, **kwargs ) @property - def dtype(self) -> Type[DTypeFloating]: + def dtype(self) -> Type[DTypeFloat]: """ Getter and setter property for the continuous signal dtype. @@ -339,21 +338,21 @@ def dtype(self) -> Type[DTypeFloating]: Returns ------- - Type[DTypeFloating] + Type[DTypeFloat] Continuous signal dtype. """ return first_item(self._signals.values()).dtype @dtype.setter - def dtype(self, value: Type[DTypeFloating]): + def dtype(self, value: Type[DTypeFloat]): """Setter for the **self.dtype** property.""" for signal in self._signals.values(): signal.dtype = value @property - def domain(self) -> NDArray: + def domain(self) -> NDArrayFloat: """ Getter and setter property for the :class:`colour.continuous.Signal` sub-class instances independent domain variable :math:`x`. @@ -381,7 +380,7 @@ def domain(self, value: ArrayLike): signal.domain = as_float_array(value, self.dtype) @property - def range(self) -> NDArray: + def range(self) -> NDArrayFloat: """ Getter and setter property for the :class:`colour.continuous.Signal` sub-class instances corresponding range variable :math:`y`. @@ -450,7 +449,7 @@ def interpolator(self, value: Type[TypeInterpolator]): signal.interpolator = value @property - def interpolator_kwargs(self) -> Dict: + def interpolator_kwargs(self) -> dict: """ Getter and setter property for the :class:`colour.continuous.Signal` sub-class instances interpolator instantiation time arguments. @@ -506,7 +505,7 @@ def extrapolator(self, value: Type[TypeExtrapolator]): signal.extrapolator = value @property - def extrapolator_kwargs(self) -> Dict: + def extrapolator_kwargs(self) -> dict: """ Getter and setter property for the :class:`colour.continuous.Signal` sub-class instances extrapolator instantiation time arguments. @@ -548,7 +547,7 @@ def function(self) -> Callable: return first_item(self._signals.values()).function @property - def signals(self) -> Dict[str, Signal]: + def signals(self) -> dict[str, Signal]: """ Getter and setter property for the :class:`colour.continuous.Signal` sub-class instances. @@ -570,7 +569,7 @@ def signals(self) -> Dict[str, Signal]: def signals( self, value: Optional[ - Union[ArrayLike, DataFrame, dict, MultiSignals, Signal, Series] + Union[ArrayLike, DataFrame, dict, Self, Series, Signal] ], ): """Setter for the **self.signals** property.""" @@ -580,7 +579,7 @@ def signals( ) @property - def labels(self) -> List[str]: + def labels(self) -> list[str]: """ Getter and setter property for the :class:`colour.continuous.Signal` sub-class instance names. @@ -725,13 +724,13 @@ def __repr__(self) -> str: ], ) - def __hash__(self) -> Integer: + def __hash__(self) -> int: """ Return the abstract continuous function hash. Returns ------- - :class:`numpy.integer` + :class:`int` Object hash. """ @@ -746,9 +745,7 @@ def __hash__(self) -> Integer: ) ) - def __getitem__( - self, x: Union[FloatingOrArrayLike, slice] - ) -> FloatingOrNDArray: + def __getitem__(self, x: Union[ArrayLike, slice]) -> NDArrayFloat: """ Return the corresponding range variable :math:`y` for independent domain variable :math:`x`. @@ -760,7 +757,7 @@ def __getitem__( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Variable :math:`y` range value. Examples @@ -810,13 +807,11 @@ def __getitem__( x_r, x_c = (x[0], x[1]) if isinstance(x, tuple) else (x, slice(None)) - return tstack([signal[x_r] for signal in self._signals.values()])[ - ..., x_c - ] + values = tstack([signal[x_r] for signal in self._signals.values()]) - def __setitem__( - self, x: Union[FloatingOrArrayLike, slice], y: FloatingOrArrayLike - ): + return values[..., x_c] # pyright: ignore + + def __setitem__(self, x: Union[ArrayLike, slice], y: ArrayLike): """ Set the corresponding range variable :math:`y` for independent domain variable :math:`x`. @@ -942,10 +937,12 @@ def __setitem__( 'underlying "Signal" components!', ) - for signal, y in list(zip(self._signals.values(), tsplit(y)))[x_c]: + values = list(zip(self._signals.values(), tsplit(y))) + + for signal, y in values[x_c]: # pyright: ignore signal[x_r] = y - def __contains__(self, x: Union[FloatingOrArrayLike, slice]) -> bool: + def __contains__(self, x: Union[ArrayLike, slice]) -> bool: """ Return whether the multi-continuous signals contains given independent domain variable :math:`x`. @@ -1062,9 +1059,9 @@ def __ne__(self, other: Any) -> bool: def arithmetical_operation( self, - a: Union[FloatingOrArrayLike, AbstractContinuousFunction], + a: Union[ArrayLike, AbstractContinuousFunction], operation: Literal["+", "-", "*", "/", "**"], - in_place: Boolean = False, + in_place: bool = False, ) -> AbstractContinuousFunction: """ Perform given arithmetical operation with operand :math:`a`, the @@ -1190,7 +1187,7 @@ def arithmetical_operation( ): signal_a.arithmetical_operation(signal_b, operation, True) else: - a = as_float_array(a) # type: ignore[arg-type] + a = as_float_array(cast(ArrayLike, a)) attest( a.ndim in range(3), @@ -1230,10 +1227,10 @@ def multi_signals_unpack_data( ] = None, domain: Optional[ArrayLike] = None, labels: Optional[Sequence] = None, - dtype: Optional[Type[DTypeFloating]] = None, + dtype: Optional[Type[DTypeFloat]] = None, signal_type: Type[Signal] = Signal, **kwargs: Any, - ) -> Dict[str, Signal]: + ) -> dict[str, Signal]: """ Unpack given data for multi-continuous signals instantiation. @@ -1251,7 +1248,7 @@ def multi_signals_unpack_data( Names to use for the :class:`colour.continuous.Signal` sub-class instances. dtype - Floating point data type. + float point data type. signal_type A :class:`colour.continuous.Signal` sub-class type. @@ -1439,7 +1436,7 @@ def multi_signals_unpack_data( [ 1000. 120.]] """ - dtype = cast(Type[DTypeFloating], optional(dtype, DEFAULT_FLOAT_DTYPE)) + dtype = optional(dtype, DEFAULT_FLOAT_DTYPE) settings = {} settings.update(kwargs) @@ -1457,7 +1454,7 @@ def multi_signals_unpack_data( elif issubclass(type(data), Sequence) or isinstance( data, (tuple, list, np.ndarray, Iterator, ValuesView) ): - data_sequence = list(data) # type: ignore[arg-type] + data_sequence = list(cast(Sequence, data)) is_signal = True for i in data_sequence: @@ -1485,7 +1482,7 @@ def multi_signals_unpack_data( range_unpacked, domain, **settings ) elif issubclass(type(data), Mapping) or isinstance(data, dict): - data_mapping = dict(data) # type: ignore[arg-type] + data_mapping = dict(cast(Mapping, data)) is_signal = all( [ @@ -1511,16 +1508,19 @@ def multi_signals_unpack_data( if isinstance(data, Series): signals["0"] = signal_type(data, **settings) elif isinstance(data, DataFrame): - domain_unpacked = data.index.values + dataframe = cast(DataFrame, data) + domain_unpacked = dataframe.index.values signals = { label: signal_type( - data[label], domain_unpacked, **settings + data[label], # pyright: ignore + domain_unpacked, + **settings, ) - for label in data + for label in data # pyright: ignore } if domain is not None: - domain_array = as_float_array(list(domain), dtype) # type: ignore[arg-type] + domain_array = as_float_array(domain, dtype) for signal in signals.values(): attest( diff --git a/colour/continuous/signal.py b/colour/continuous/signal.py index b7cc88860e..7dc8da98a9 100644 --- a/colour/continuous/signal.py +++ b/colour/continuous/signal.py @@ -29,18 +29,14 @@ from colour.hints import ( Any, ArrayLike, - Boolean, Callable, - DTypeFloating, - Dict, - FloatingOrArrayLike, - FloatingOrNDArray, - Integer, + DTypeFloat, Literal, - NDArray, + NDArrayFloat, Number, Optional, - Tuple, + Self, + TYPE_CHECKING, Type, TypeExtrapolator, TypeInterpolator, @@ -63,12 +59,15 @@ ) from colour.utilities.documentation import is_documentation_building -if is_pandas_installed(): +if TYPE_CHECKING: from pandas import Series -else: # pragma: no cover - from unittest import mock +else: + if is_pandas_installed(): + from pandas import Series + else: # pragma: no cover + from unittest import mock - Series = mock.MagicMock() + Series = mock.MagicMock() __author__ = "Colour Developers" __copyright__ = "Copyright 2013 Colour Developers" @@ -114,7 +113,7 @@ class Signal(AbstractContinuousFunction): Other Parameters ---------------- dtype - Floating point data type. + float point data type. extrapolator Extrapolator class type to use as extrapolating function. extrapolator_kwargs @@ -244,19 +243,19 @@ class Signal(AbstractContinuousFunction): def __init__( self, - data: Optional[Union[ArrayLike, dict, Series, Signal]] = None, + data: Optional[Union[ArrayLike, dict, Self, Series]] = None, domain: Optional[ArrayLike] = None, **kwargs: Any, ) -> None: super().__init__(kwargs.get("name")) - self._dtype: Type[DTypeFloating] = DEFAULT_FLOAT_DTYPE - self._domain: NDArray = np.array([]) - self._range: NDArray = np.array([]) + self._dtype: Type[DTypeFloat] = DEFAULT_FLOAT_DTYPE + self._domain: NDArrayFloat = np.array([]) + self._range: NDArrayFloat = np.array([]) self._interpolator: Type[TypeInterpolator] = KernelInterpolator - self._interpolator_kwargs: Dict = {} + self._interpolator_kwargs: dict = {} self._extrapolator: Type[TypeExtrapolator] = Extrapolator - self._extrapolator_kwargs: Dict = { + self._extrapolator_kwargs: dict = { "method": "Constant", "left": np.nan, "right": np.nan, @@ -278,7 +277,7 @@ def __init__( self._function: Union[Callable, None] = None @property - def dtype(self) -> Type[DTypeFloating]: + def dtype(self) -> Type[DTypeFloat]: """ Getter and setter property for the continuous signal dtype. @@ -289,14 +288,14 @@ def dtype(self) -> Type[DTypeFloating]: Returns ------- - DTypeFloating + DTypeFloat Continuous signal dtype. """ return self._dtype @dtype.setter - def dtype(self, value: Type[DTypeFloating]): + def dtype(self, value: Type[DTypeFloat]): """Setter for the **self.dtype** property.""" attest( @@ -313,7 +312,7 @@ def dtype(self, value: Type[DTypeFloating]): self.range = self.range @property - def domain(self) -> NDArray: + def domain(self) -> NDArrayFloat: """ Getter and setter property for the continuous signal independent domain variable :math:`x`. @@ -356,7 +355,7 @@ def domain(self, value: ArrayLike): self._function = None # Invalidate the underlying continuous function. @property - def range(self) -> NDArray: + def range(self) -> NDArrayFloat: """ Getter and setter property for the continuous signal corresponding range variable :math:`y`. @@ -423,7 +422,7 @@ def interpolator(self, value: Type[TypeInterpolator]): self._function = None # Invalidate the underlying continuous function. @property - def interpolator_kwargs(self) -> Dict: + def interpolator_kwargs(self) -> dict: """ Getter and setter property for the continuous signal interpolator instantiation time arguments. @@ -483,7 +482,7 @@ def extrapolator(self, value: Type[TypeExtrapolator]): self._function = None # Invalidate the underlying continuous function. @property - def extrapolator_kwargs(self) -> Dict: + def extrapolator_kwargs(self) -> dict: """ Getter and setter property for the continuous signal extrapolator instantiation time arguments. @@ -644,13 +643,13 @@ def __repr__(self) -> str: ], ) - def __hash__(self) -> Integer: + def __hash__(self) -> int: """ Return the abstract continuous function hash. Returns ------- - :class:`numpy.integer` + :class:`int` Object hash. """ @@ -665,9 +664,7 @@ def __hash__(self) -> Integer: ) ) - def __getitem__( - self, x: Union[FloatingOrArrayLike, slice] - ) -> FloatingOrNDArray: + def __getitem__(self, x: Union[ArrayLike, slice]) -> NDArrayFloat: """ Return the corresponding range variable :math:`y` for independent domain variable :math:`x`. @@ -679,7 +676,7 @@ def __getitem__( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Variable :math:`y` range value. Examples @@ -713,9 +710,7 @@ def __getitem__( else: return self.function(x) - def __setitem__( - self, x: Union[FloatingOrArrayLike, slice], y: FloatingOrArrayLike - ): + def __setitem__(self, x: Union[ArrayLike, slice], y: ArrayLike): """ Set the corresponding range variable :math:`y` for independent domain variable :math:`x`. @@ -805,7 +800,7 @@ def __setitem__( self._function = None # Invalidate the underlying continuous function. - def __contains__(self, x: Union[FloatingOrArrayLike, slice]) -> bool: + def __contains__(self, x: ArrayLike) -> bool: """ Return whether the continuous signal contains given independent domain variable :math:`x`. @@ -836,7 +831,8 @@ def __contains__(self, x: Union[FloatingOrArrayLike, slice]) -> bool: np.all( np.where( np.logical_and( - x >= np.min(self._domain), x <= np.max(self._domain) + x >= np.min(self._domain), # pyright: ignore + x <= np.max(self._domain), # pyright: ignore ), True, False, @@ -985,9 +981,9 @@ def _fill_range_nan( def arithmetical_operation( self, - a: Union[FloatingOrArrayLike, AbstractContinuousFunction], + a: Union[ArrayLike, AbstractContinuousFunction], operation: Literal["+", "-", "*", "/", "**"], - in_place: Boolean = False, + in_place: bool = False, ) -> AbstractContinuousFunction: """ Perform given arithmetical operation with operand :math:`a`, the @@ -1093,8 +1089,8 @@ def arithmetical_operation( def signal_unpack_data( data=Optional[Union[ArrayLike, dict, Series, "Signal"]], domain: Optional[ArrayLike] = None, - dtype: Optional[Type[DTypeFloating]] = None, - ) -> Tuple: + dtype: Optional[Type[DTypeFloat]] = None, + ) -> tuple: """ Unpack given data for continuous signal instantiation. @@ -1108,7 +1104,7 @@ def signal_unpack_data( defined, the latter will be used to initialise the :attr:`colour.continuous.Signal.domain` property. dtype - Floating point data type. + float point data type. Returns ------- @@ -1170,10 +1166,10 @@ def signal_unpack_data( [ 10. 20. 30. 40. 50. 60. 70. 80. 90. 100.] """ - dtype = cast(Type[DTypeFloating], optional(dtype, DEFAULT_FLOAT_DTYPE)) + dtype = optional(dtype, DEFAULT_FLOAT_DTYPE) - domain_unpacked: NDArray = np.array([]) - range_unpacked: NDArray = np.array([]) + domain_unpacked: NDArrayFloat = np.array([]) + range_unpacked: NDArrayFloat = np.array([]) if isinstance(data, Signal): domain_unpacked = data.domain @@ -1181,7 +1177,7 @@ def signal_unpack_data( elif issubclass(type(data), Sequence) or isinstance( data, (tuple, list, np.ndarray, Iterator, ValuesView) ): - data_array = tsplit(list(data)) + data_array = tsplit(list(cast(Sequence, data))) attest(data_array.ndim == 1, 'User "data" must be 1-dimensional!') @@ -1190,14 +1186,17 @@ def signal_unpack_data( data_array, ) elif issubclass(type(data), Mapping) or isinstance(data, dict): - domain_unpacked, range_unpacked = tsplit(sorted(data.items())) + domain_unpacked, range_unpacked = tsplit( + sorted(cast(Mapping, data).items()) + ) elif is_pandas_installed(): if isinstance(data, Series): - domain_unpacked = data.index.values - range_unpacked = data.values + series = cast(Series, data) + domain_unpacked = series.index.values + range_unpacked = series.values if domain is not None: - domain_array = as_float_array(list(domain), dtype) # type: ignore[arg-type] + domain_array = as_float_array(domain, dtype) attest( len(domain_array) == len(range_unpacked), diff --git a/colour/contrast/__init__.py b/colour/contrast/__init__.py index f3ea3656d8..738bd09d62 100644 --- a/colour/contrast/__init__.py +++ b/colour/contrast/__init__.py @@ -18,7 +18,7 @@ from __future__ import annotations -from colour.hints import FloatingOrNDArray, Literal, Union +from colour.hints import NDArrayFloat, Literal, Union from colour.utilities import ( CanonicalMapping, filter_kwargs, @@ -60,7 +60,7 @@ def contrast_sensitivity_function( method: Union[Literal["Barten 1999"], str] = "Barten 1999", **kwargs -) -> FloatingOrNDArray: +) -> NDArrayFloat: """ Return the contrast sensitivity :math:`S` of the human eye according to the contrast sensitivity function (CSF) described by given method. @@ -126,7 +126,7 @@ def contrast_sensitivity_function( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Contrast sensitivity :math:`S`. References diff --git a/colour/contrast/barten1999.py b/colour/contrast/barten1999.py index ef37807cc5..7a3b141cd5 100644 --- a/colour/contrast/barten1999.py +++ b/colour/contrast/barten1999.py @@ -31,9 +31,8 @@ import numpy as np from colour.hints import ( - Boolean, - FloatingOrArrayLike, - FloatingOrNDArray, + ArrayLike, + NDArrayFloat, Optional, ) from colour.utilities import as_float_array, as_float @@ -56,8 +55,8 @@ def optical_MTF_Barten1999( - u: FloatingOrArrayLike, sigma: FloatingOrArrayLike = 0.01 -) -> FloatingOrNDArray: + u: ArrayLike, sigma: ArrayLike = 0.01 +) -> NDArrayFloat: """ Return the optical modulation transfer function (MTF) :math:`M_{opt}` of the eye using *Barten (1999)* method. @@ -73,7 +72,7 @@ def optical_MTF_Barten1999( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Optical modulation transfer function (MTF) :math:`M_{opt}` of the eye. References @@ -94,10 +93,10 @@ def optical_MTF_Barten1999( def pupil_diameter_Barten1999( - L: FloatingOrArrayLike, - X_0: FloatingOrArrayLike = 60, - Y_0: Optional[FloatingOrArrayLike] = None, -) -> FloatingOrNDArray: + L: ArrayLike, + X_0: ArrayLike = 60, + Y_0: Optional[ArrayLike] = None, +) -> NDArrayFloat: """ Return the pupil diameter for given luminance and object or stimulus angular size using *Barten (1999)* method. @@ -113,7 +112,7 @@ def pupil_diameter_Barten1999( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Pupil diameter. References @@ -139,10 +138,10 @@ def pupil_diameter_Barten1999( def sigma_Barten1999( - sigma_0: FloatingOrArrayLike = 0.5 / 60, - C_ab: FloatingOrArrayLike = 0.08 / 60, - d: FloatingOrArrayLike = 2.1, -) -> FloatingOrNDArray: + sigma_0: ArrayLike = 0.5 / 60, + C_ab: ArrayLike = 0.08 / 60, + d: ArrayLike = 2.1, +) -> NDArrayFloat: """ Return the standard deviation :math:`\\sigma` of the line-spread function resulting from the convolution of the different elements of the convolution @@ -166,7 +165,7 @@ def sigma_Barten1999( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Standard deviation :math:`\\sigma` of the line-spread function resulting from the convolution of the different elements of the convolution process. @@ -198,10 +197,10 @@ def sigma_Barten1999( def retinal_illuminance_Barten1999( - L: FloatingOrArrayLike, - d: FloatingOrArrayLike = 2.1, - apply_stiles_crawford_effect_correction: Boolean = True, -) -> FloatingOrNDArray: + L: ArrayLike, + d: ArrayLike = 2.1, + apply_stiles_crawford_effect_correction: bool = True, +) -> NDArrayFloat: """ Return the retinal illuminance :math:`E` in Trolands for given average luminance :math:`L` and pupil diameter :math:`d` using *Barten (1999)* @@ -218,7 +217,7 @@ def retinal_illuminance_Barten1999( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Retinal illuminance :math:`E` in Trolands. Notes @@ -253,11 +252,11 @@ def retinal_illuminance_Barten1999( def maximum_angular_size_Barten1999( - u: FloatingOrArrayLike, - X_0: FloatingOrArrayLike = 60, - X_max: FloatingOrArrayLike = 12, - N_max: FloatingOrArrayLike = 15, -) -> FloatingOrNDArray: + u: ArrayLike, + X_0: ArrayLike = 60, + X_max: ArrayLike = 12, + N_max: ArrayLike = 15, +) -> NDArrayFloat: """ Return the maximum angular size :math:`X` of the object considered using *Barten (1999)* method. @@ -277,7 +276,7 @@ def maximum_angular_size_Barten1999( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Maximum angular size :math:`X` of the object considered. References @@ -302,21 +301,21 @@ def maximum_angular_size_Barten1999( def contrast_sensitivity_function_Barten1999( - u: FloatingOrArrayLike, - sigma: FloatingOrArrayLike = sigma_Barten1999(0.5 / 60, 0.08 / 60, 2.1), - k: FloatingOrArrayLike = 3.0, - T: FloatingOrArrayLike = 0.1, - X_0: FloatingOrArrayLike = 60, - Y_0: Optional[FloatingOrArrayLike] = None, - X_max: FloatingOrArrayLike = 12, - Y_max: Optional[FloatingOrArrayLike] = None, - N_max: FloatingOrArrayLike = 15, - n: FloatingOrArrayLike = 0.03, - p: FloatingOrArrayLike = 1.2274 * 10**6, - E: FloatingOrArrayLike = retinal_illuminance_Barten1999(20, 2.1), - phi_0: FloatingOrArrayLike = 3 * 10**-8, - u_0: FloatingOrArrayLike = 7, -) -> FloatingOrNDArray: + u: ArrayLike, + sigma: ArrayLike = sigma_Barten1999(0.5 / 60, 0.08 / 60, 2.1), + k: ArrayLike = 3.0, + T: ArrayLike = 0.1, + X_0: ArrayLike = 60, + Y_0: Optional[ArrayLike] = None, + X_max: ArrayLike = 12, + Y_max: Optional[ArrayLike] = None, + N_max: ArrayLike = 15, + n: ArrayLike = 0.03, + p: ArrayLike = 1.2274 * 10**6, + E: ArrayLike = retinal_illuminance_Barten1999(20, 2.1), + phi_0: ArrayLike = 3 * 10**-8, + u_0: ArrayLike = 7, +) -> NDArrayFloat: """ Return the contrast sensitivity :math:`S` of the human eye according to the contrast sensitivity function (CSF) described by *Barten (1999)*. @@ -372,7 +371,7 @@ def contrast_sensitivity_function_Barten1999( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Contrast sensitivity :math:`S`. Warnings diff --git a/colour/corresponding/prediction.py b/colour/corresponding/prediction.py index 75de251f2d..0b3cbf8dd5 100644 --- a/colour/corresponding/prediction.py +++ b/colour/corresponding/prediction.py @@ -55,10 +55,8 @@ from colour.hints import ( Any, ArrayLike, - FloatingOrArrayLike, Literal, Union, - Tuple, ) from colour.models import ( Luv_to_uv, @@ -306,7 +304,7 @@ def corresponding_chromaticities_prediction_Fairchild1990( experiment: Union[ Literal[1, 2, 3, 4, 6, 8, 9, 11, 12], CorrespondingColourDataset ] = 1 -) -> Tuple[CorrespondingChromaticitiesPrediction, ...]: +) -> tuple[CorrespondingChromaticitiesPrediction, ...]: """ Return the corresponding chromaticities prediction for *Fairchild (1990)* chromatic adaptation model. @@ -377,7 +375,7 @@ def corresponding_chromaticities_prediction_CIE1994( experiment: Union[ Literal[1, 2, 3, 4, 6, 8, 9, 11, 12], CorrespondingColourDataset ] = 1 -) -> Tuple[CorrespondingChromaticitiesPrediction, ...]: +) -> tuple[CorrespondingChromaticitiesPrediction, ...]: """ Return the corresponding chromaticities prediction for *CIE 1994* chromatic adaptation model. @@ -451,7 +449,7 @@ def corresponding_chromaticities_prediction_CMCCAT2000( experiment: Union[ Literal[1, 2, 3, 4, 6, 8, 9, 11, 12], CorrespondingColourDataset ] = 1 -) -> Tuple[CorrespondingChromaticitiesPrediction, ...]: +) -> tuple[CorrespondingChromaticitiesPrediction, ...]: """ Return the corresponding chromaticities prediction for *CMCCAT2000* chromatic adaptation model. @@ -542,7 +540,7 @@ def corresponding_chromaticities_prediction_VonKries( ], str, ] = "CAT02", -) -> Tuple[CorrespondingChromaticitiesPrediction, ...]: +) -> tuple[CorrespondingChromaticitiesPrediction, ...]: """ Return the corresponding chromaticities prediction for *Von Kries* chromatic adaptation model using given transform. @@ -613,8 +611,8 @@ def corresponding_chromaticities_prediction_Zhai2018( experiment: Union[ Literal[1, 2, 3, 4, 6, 8, 9, 11, 12], CorrespondingColourDataset ] = 1, - D_b: FloatingOrArrayLike = 1, - D_d: FloatingOrArrayLike = 1, + D_b: ArrayLike = 1, + D_d: ArrayLike = 1, XYZ_wo: ArrayLike = np.array([1, 1, 1]), transform: Union[ Literal[ @@ -623,7 +621,7 @@ def corresponding_chromaticities_prediction_Zhai2018( ], str, ] = "CAT02", -) -> Tuple[CorrespondingChromaticitiesPrediction, ...]: +) -> tuple[CorrespondingChromaticitiesPrediction, ...]: """ Return the corresponding chromaticities prediction for *Zhai and Luo (2018)* chromatic adaptation model using given transform. @@ -742,7 +740,7 @@ def corresponding_chromaticities_prediction( str, ] = "Von Kries", **kwargs: Any, -) -> Tuple[CorrespondingChromaticitiesPrediction, ...]: +) -> tuple[CorrespondingChromaticitiesPrediction, ...]: """ Return the corresponding chromaticities prediction for given chromatic adaptation model. diff --git a/colour/corresponding/tests/test_prediction.py b/colour/corresponding/tests/test_prediction.py index f1e135ca23..fe46b9b8c9 100644 --- a/colour/corresponding/tests/test_prediction.py +++ b/colour/corresponding/tests/test_prediction.py @@ -17,7 +17,7 @@ corresponding_chromaticities_prediction_VonKries, corresponding_chromaticities_prediction_Zhai2018, ) -from colour.hints import NDArray +from colour.hints import NDArrayFloat __author__ = "Colour Developers" @@ -138,7 +138,7 @@ ) ) -DATA_PREDICTION_FAIRCHILD1990: NDArray = np.array( +DATA_PREDICTION_FAIRCHILD1990: NDArrayFloat = np.array( [ [(0.199, 0.487), (0.200554934448681, 0.470155699619516)], [(0.420, 0.509), (0.389214449896027, 0.514002881379267)], @@ -155,7 +155,7 @@ ] ) -DATA_PREDICTION_CIE1994: NDArray = np.array( +DATA_PREDICTION_CIE1994: NDArrayFloat = np.array( [ [(0.199, 0.487), (0.261386136420622, 0.533662817418878)], [(0.420, 0.509), (0.451546322781523, 0.521730655299867)], @@ -172,7 +172,7 @@ ] ) -DATA_PREDICTION_CMCCAT2000: NDArray = np.array( +DATA_PREDICTION_CMCCAT2000: NDArrayFloat = np.array( [ [(0.199, 0.487), (0.200011273633451, 0.470539230354398)], [(0.420, 0.509), (0.407637147823942, 0.504672206472439)], @@ -189,7 +189,7 @@ ] ) -DATA_PREDICTION_VONKRIES: NDArray = np.array( +DATA_PREDICTION_VONKRIES: NDArrayFloat = np.array( [ [(0.199, 0.487), (0.199994235295863, 0.470596132542110)], [(0.420, 0.509), (0.414913855668385, 0.503766204685646)], @@ -206,7 +206,7 @@ ] ) -DATA_PREDICTION_ZHAI2018: NDArray = np.array( +DATA_PREDICTION_ZHAI2018: NDArrayFloat = np.array( [ [(0.199, 0.487), (0.199994235295863, 0.470596132542110)], [(0.420, 0.509), (0.414913855668385, 0.503766204685646)], diff --git a/colour/difference/__init__.py b/colour/difference/__init__.py index 8e44e2335d..6519f6d980 100644 --- a/colour/difference/__init__.py +++ b/colour/difference/__init__.py @@ -37,7 +37,7 @@ from __future__ import annotations -from colour.hints import Any, ArrayLike, FloatingOrNDArray, Literal, Union +from colour.hints import Any, ArrayLike, NDArrayFloat, Literal, Union from colour.utilities import ( CanonicalMapping, filter_kwargs, @@ -145,7 +145,7 @@ def delta_E( str, ] = "CIE 2000", **kwargs: Any, -) -> FloatingOrNDArray: +) -> NDArrayFloat: """ Return the difference :math:`\\Delta E_{ab}` between two given *CIE L\\*a\\*b\\**, :math:`IC_TC_P`, or :math:`J'a'b'` colourspace arrays @@ -181,7 +181,7 @@ def delta_E( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Colour difference :math:`\\Delta E_{ab}`. References diff --git a/colour/difference/cam02_ucs.py b/colour/difference/cam02_ucs.py index e9b6eae8d7..aa13b2a353 100644 --- a/colour/difference/cam02_ucs.py +++ b/colour/difference/cam02_ucs.py @@ -21,7 +21,7 @@ import numpy as np from colour.models.cam02_ucs import COEFFICIENTS_UCS_LUO2006 -from colour.hints import ArrayLike, FloatingOrNDArray +from colour.hints import ArrayLike, NDArrayFloat from colour.utilities import as_float, tsplit __author__ = "Colour Developers" @@ -41,7 +41,7 @@ def delta_E_Luo2006( Jpapbp_1: ArrayLike, Jpapbp_2: ArrayLike, coefficients: ArrayLike -) -> FloatingOrNDArray: +) -> NDArrayFloat: """ Return the difference :math:`\\Delta E'` between two given *Luo et al. (2006)* *CAM02-LCD*, *CAM02-SCD*, or *CAM02-UCS* colourspaces @@ -61,7 +61,7 @@ def delta_E_Luo2006( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Colour difference :math:`\\Delta E'`. Warnings @@ -112,9 +112,7 @@ def delta_E_Luo2006( return as_float(d_E) -def delta_E_CAM02LCD( - Jpapbp_1: ArrayLike, Jpapbp_2: ArrayLike -) -> FloatingOrNDArray: +def delta_E_CAM02LCD(Jpapbp_1: ArrayLike, Jpapbp_2: ArrayLike) -> NDArrayFloat: """ Return the difference :math:`\\Delta E'` between two given *Luo et al. (2006)* *CAM02-LCD* colourspaces :math:`J'a'b'` arrays. @@ -130,7 +128,7 @@ def delta_E_CAM02LCD( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Colour difference :math:`\\Delta E'`. Warnings @@ -174,9 +172,7 @@ def delta_E_CAM02LCD( ) -def delta_E_CAM02SCD( - Jpapbp_1: ArrayLike, Jpapbp_2: ArrayLike -) -> FloatingOrNDArray: +def delta_E_CAM02SCD(Jpapbp_1: ArrayLike, Jpapbp_2: ArrayLike) -> NDArrayFloat: """ Return the difference :math:`\\Delta E'` between two given *Luo et al. (2006)* *CAM02-SCD* colourspaces :math:`J'a'b'` arrays. @@ -192,7 +188,7 @@ def delta_E_CAM02SCD( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Colour difference :math:`\\Delta E'`. Warnings @@ -236,9 +232,7 @@ def delta_E_CAM02SCD( ) -def delta_E_CAM02UCS( - Jpapbp_1: ArrayLike, Jpapbp_2: ArrayLike -) -> FloatingOrNDArray: +def delta_E_CAM02UCS(Jpapbp_1: ArrayLike, Jpapbp_2: ArrayLike) -> NDArrayFloat: """ Return the difference :math:`\\Delta E'` between two given *Luo et al. (2006)* *CAM02-UCS* colourspaces :math:`J'a'b'` arrays. @@ -254,7 +248,7 @@ def delta_E_CAM02UCS( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Colour difference :math:`\\Delta E'`. Warnings diff --git a/colour/difference/delta_e.py b/colour/difference/delta_e.py index ee0ffdfc0a..5c8f8282a8 100644 --- a/colour/difference/delta_e.py +++ b/colour/difference/delta_e.py @@ -43,7 +43,7 @@ import numpy as np from colour.algebra import euclidean_distance -from colour.hints import ArrayLike, Boolean, Floating, FloatingOrNDArray +from colour.hints import ArrayLike, NDArrayFloat from colour.utilities import as_float, to_domain_100, tsplit from colour.utilities.documentation import ( DocstringFloat, @@ -91,7 +91,7 @@ """ -def delta_E_CIE1976(Lab_1: ArrayLike, Lab_2: ArrayLike) -> FloatingOrNDArray: +def delta_E_CIE1976(Lab_1: ArrayLike, Lab_2: ArrayLike) -> NDArrayFloat: """ Return the difference :math:`\\Delta E_{76}` between two given *CIE L\\*a\\*b\\** colourspace arrays using *CIE 1976* recommendation. @@ -105,7 +105,7 @@ def delta_E_CIE1976(Lab_1: ArrayLike, Lab_2: ArrayLike) -> FloatingOrNDArray: Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Colour difference :math:`\\Delta E_{76}`. Notes @@ -144,8 +144,8 @@ def delta_E_CIE1976(Lab_1: ArrayLike, Lab_2: ArrayLike) -> FloatingOrNDArray: def delta_E_CIE1994( - Lab_1: ArrayLike, Lab_2: ArrayLike, textiles: Boolean = False -) -> FloatingOrNDArray: + Lab_1: ArrayLike, Lab_2: ArrayLike, textiles: bool = False +) -> NDArrayFloat: """ Return the difference :math:`\\Delta E_{94}` between two given *CIE L\\*a\\*b\\** colourspace arrays using *CIE 1994* recommendation. @@ -163,7 +163,7 @@ def delta_E_CIE1994( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Colour difference :math:`\\Delta E_{94}`. Notes @@ -236,8 +236,8 @@ def delta_E_CIE1994( def delta_E_CIE2000( - Lab_1: ArrayLike, Lab_2: ArrayLike, textiles: Boolean = False -) -> FloatingOrNDArray: + Lab_1: ArrayLike, Lab_2: ArrayLike, textiles: bool = False +) -> NDArrayFloat: """ Return the difference :math:`\\Delta E_{00}` between two given *CIE L\\*a\\*b\\** colourspace arrays using *CIE 2000* recommendation. @@ -255,7 +255,7 @@ def delta_E_CIE2000( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Colour difference :math:`\\Delta E_{00}`. Notes @@ -388,9 +388,9 @@ def delta_E_CIE2000( def delta_E_CMC( Lab_1: ArrayLike, Lab_2: ArrayLike, - l: Floating = 2, # noqa - c: Floating = 1, -) -> FloatingOrNDArray: + l: float = 2, # noqa + c: float = 1, +) -> NDArrayFloat: """ Return the difference :math:`\\Delta E_{CMC}` between two given *CIE L\\*a\\*b\\** colourspace arrays using *Colour Measurement Committee* @@ -414,7 +414,7 @@ def delta_E_CMC( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Colour difference :math:`\\Delta E_{CMC}`. Notes @@ -481,7 +481,7 @@ def delta_E_CMC( return as_float(d_E) -def delta_E_ITP(ICtCp_1: ArrayLike, ICtCp_2: ArrayLike) -> FloatingOrNDArray: +def delta_E_ITP(ICtCp_1: ArrayLike, ICtCp_2: ArrayLike) -> NDArrayFloat: """ Return the difference :math:`\\Delta E_{ITP}` between two given :math:`IC_TC_P` colour encoding arrays using @@ -496,7 +496,7 @@ def delta_E_ITP(ICtCp_1: ArrayLike, ICtCp_2: ArrayLike) -> FloatingOrNDArray: Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Colour difference :math:`\\Delta E_{ITP}`. Notes diff --git a/colour/difference/din99.py b/colour/difference/din99.py index 762e3e4731..6ea2f3e5bc 100644 --- a/colour/difference/din99.py +++ b/colour/difference/din99.py @@ -17,7 +17,7 @@ from __future__ import annotations from colour.algebra import euclidean_distance -from colour.hints import ArrayLike, Boolean, FloatingOrNDArray +from colour.hints import ArrayLike, NDArrayFloat from colour.models import Lab_to_DIN99 from colour.utilities import get_domain_range_scale @@ -34,8 +34,8 @@ def delta_E_DIN99( - Lab_1: ArrayLike, Lab_2: ArrayLike, textiles: Boolean = False -) -> FloatingOrNDArray: + Lab_1: ArrayLike, Lab_2: ArrayLike, textiles: bool = False +) -> NDArrayFloat: """ Return the difference :math:`\\Delta E_{DIN99}` between two given *CIE L\\*a\\*b\\** colourspace arrays using *DIN99* formula. @@ -53,7 +53,7 @@ def delta_E_DIN99( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Colour difference :math:`\\Delta E_{DIN99}`. Notes diff --git a/colour/difference/huang2015.py b/colour/difference/huang2015.py index b92f8f30c9..e7bd36dc12 100644 --- a/colour/difference/huang2015.py +++ b/colour/difference/huang2015.py @@ -23,7 +23,7 @@ import numpy as np -from colour.hints import FloatingOrArrayLike, FloatingOrNDArray, Literal, Union +from colour.hints import ArrayLike, NDArrayFloat, Literal, Union from colour.utilities import CanonicalMapping, tsplit, validate_method __author__ = "Colour Developers" @@ -78,7 +78,7 @@ def power_function_Huang2015( - d_E: FloatingOrArrayLike, + d_E: ArrayLike, coefficients: Union[ Literal[ "CIE 1976", @@ -95,7 +95,7 @@ def power_function_Huang2015( ], str, ] = "CIE 2000", -) -> FloatingOrNDArray: +) -> NDArrayFloat: """ Improve the performance of the :math:`\\Delta E` value for given coefficients using @@ -111,7 +111,7 @@ def power_function_Huang2015( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Improved math:`\\Delta E` value. References diff --git a/colour/difference/stress.py b/colour/difference/stress.py index ad2bd35cb0..fe71f2e95b 100644 --- a/colour/difference/stress.py +++ b/colour/difference/stress.py @@ -23,7 +23,7 @@ import numpy as np from colour.algebra import sdiv, sdiv_mode -from colour.hints import FloatingOrArrayLike, FloatingOrNDArray, Literal, Union +from colour.hints import ArrayLike, NDArrayFloat, Literal, Union from colour.utilities import ( CanonicalMapping, as_float, @@ -45,9 +45,7 @@ ] -def index_stress_Garcia2007( - d_E: FloatingOrArrayLike, d_V: FloatingOrArrayLike -) -> FloatingOrNDArray: +def index_stress_Garcia2007(d_E: ArrayLike, d_V: ArrayLike) -> NDArrayFloat: """ Compute the *Kruskal's Standardized Residual Sum of Squares (:math:`STRESS`)* @@ -62,7 +60,7 @@ def index_stress_Garcia2007( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` :math:`STRESS` index. References @@ -105,10 +103,10 @@ def index_stress_Garcia2007( def index_stress( - d_E: FloatingOrArrayLike, - d_V: FloatingOrArrayLike, + d_E: ArrayLike, + d_V: ArrayLike, method: Union[Literal["Garcia 2007"], str] = "Garcia 2007", -) -> FloatingOrNDArray: +) -> NDArrayFloat: """ Compute the *Kruskal's Standardized Residual Sum of Squares (:math:`STRESS`)* @@ -125,7 +123,7 @@ def index_stress( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` :math:`STRESS` index. References diff --git a/colour/examples/colorimetry/examples_spectrum.py b/colour/examples/colorimetry/examples_spectrum.py index 8bc9945046..c080cf7119 100644 --- a/colour/examples/colorimetry/examples_spectrum.py +++ b/colour/examples/colorimetry/examples_spectrum.py @@ -3,7 +3,6 @@ import numpy as np import colour -from colour.hints import cast from colour.utilities import message_box message_box("Spectrum Computations") @@ -111,7 +110,7 @@ "distribution, this an important feature because some operations happen " "in place." ) -sd_clone = cast(colour.SpectralDistribution, sd_sample.copy()) +sd_clone = sd_sample.copy() print(id(sd_sample), id(sd_clone)) print("\n") @@ -124,30 +123,25 @@ print("\n") message_box("Regular arithmetical operation: adding an array.") -print( - cast( - colour.SpectralDistribution, - sd_clone + np.linspace(0, 1, len(sd_clone.wavelengths)), - ).values -) +print((sd_clone + np.linspace(0, 1, len(sd_clone.wavelengths))).values) print("\n") message_box( "Regular arithmetical operation: adding a spectral " "distribution." ) -print(cast(colour.SpectralDistribution, sd_clone + sd_clone).values) +print((sd_clone + sd_clone).values) print("\n") message_box("In-place arithmetical operation: adding a constant.") -sd_clone += 10 # type: ignore[misc] +sd_clone += 10 print(sd_clone[380]) print("\n") message_box("In-place arithmetical operation: adding an array.") -sd_clone += np.linspace(0, 1, len(sd_clone.wavelengths)) # type: ignore[misc] +sd_clone += np.linspace(0, 1, len(sd_clone.wavelengths)) print(sd_clone.values) print("\n") @@ -155,7 +149,7 @@ message_box( "In-place arithmetical operation: adding a spectral " "distribution." ) -sd_clone += sd_clone # type: ignore[misc] +sd_clone += sd_clone print(sd_clone.values) print("\n") diff --git a/colour/examples/contrast/examples_contrast.py b/colour/examples/contrast/examples_contrast.py index 11c223eb4a..02697bb7ef 100644 --- a/colour/examples/contrast/examples_contrast.py +++ b/colour/examples/contrast/examples_contrast.py @@ -6,8 +6,8 @@ from scipy.optimize import fmin import colour -from colour.hints import FloatingOrArrayLike, FloatingOrNDArray -from colour.utilities import as_float, message_box +from colour.hints import ArrayLike, NDArrayFloat +from colour.utilities import as_float, as_float_array, message_box from colour.plotting import colour_style, plot_single_function message_box("Contrast Sensitivity Computations") @@ -44,7 +44,7 @@ } -def maximise_spatial_frequency(L: FloatingOrArrayLike) -> FloatingOrNDArray: +def maximise_spatial_frequency(L: ArrayLike) -> NDArrayFloat: """ Maximise the spatial frequency :math:`u` for given luminance value. @@ -55,11 +55,11 @@ def maximise_spatial_frequency(L: FloatingOrArrayLike) -> FloatingOrNDArray: Returns ------- - :class:`np.floating` or :class:`numpy.ndarray` + :class:`np.float` or :class:`numpy.ndarray` Maximised spatial frequency :math:`u`. """ - L = colour.utilities.as_float_array(L) + L = as_float_array(L) maximised_spatial_frequency = [] for L_v in L: @@ -92,12 +92,7 @@ def maximise_spatial_frequency(L: FloatingOrArrayLike) -> FloatingOrNDArray: pprint( 1 / colour.contrast_sensitivity_function( - u=u, - sigma=sigma, - E=E, - X_0=X_0, - Y_0=Y_0, - **settings_BT2246 # type: ignore[arg-type] + u=u, sigma=sigma, E=E, X_0=X_0, Y_0=Y_0, **settings_BT2246 ) * 2 * (1 / 1.27) diff --git a/colour/examples/graph/examples_graph.py b/colour/examples/graph/examples_graph.py index eac73f7938..3cf1d364d6 100644 --- a/colour/examples/graph/examples_graph.py +++ b/colour/examples/graph/examples_graph.py @@ -68,7 +68,9 @@ verbose_kwargs={"describe": "Extended", "width": 75}, ) ) -J, M, h = colour.utilities.tsplit(colour.CAM16UCS_to_JMh_CAM16(Jpapbp * 100)) +J, M, h = colour.utilities.tsplit( # pyright: ignore + colour.CAM16UCS_to_JMh_CAM16(Jpapbp * 100) +) specification = colour.CAM_Specification_CAM16(J=J, M=M, h=h) print( colour.XYZ_to_sRGB( diff --git a/colour/examples/io/examples_ctl.py b/colour/examples/io/examples_ctl.py index 434337db88..382e43f488 100644 --- a/colour/examples/io/examples_ctl.py +++ b/colour/examples/io/examples_ctl.py @@ -62,7 +62,7 @@ ) print(os.path.join(ROOT_RESOURCES, "Adjust_Exposure_Float.ctl")) -a = colour.utilities.full((4, 2, 3), 0.18) +a = colour.utilities.full((4, 2, 3), 0.18) # pyright: ignore print( colour.io.process_image_ctl( a, diff --git a/colour/examples/models/examples_ycbcr.py b/colour/examples/models/examples_ycbcr.py index 2cb0376dac..23d5a4bcae 100644 --- a/colour/examples/models/examples_ycbcr.py +++ b/colour/examples/models/examples_ycbcr.py @@ -18,7 +18,7 @@ message_box( f'Converting to the "Y\'CbCr" colour encoding from given"ITU-R BT.601" ' - f"colourspace values using legal range and integer output:\n\n\t{RGB}" + f"colourspace values using legal range and int output:\n\n\t{RGB}" ) print( colour.RGB_to_YCbCr( @@ -31,7 +31,7 @@ YCbCr = np.array([101, 111, 124]) message_box( f'Converting to the "ITU-R BT.601" colourspace from given "Y\'CbCr" ' - f"values using legal range and integer input:\n\n\t{RGB}" + f"values using legal range and int input:\n\n\t{RGB}" ) print(colour.YCbCr_to_RGB(YCbCr, in_legal=True, in_int=True)) @@ -40,7 +40,7 @@ RGB = np.array([0.18, 0.18, 0.18]) message_box( f"Converting to the \"Yc'Cbc'Crc'\" colour encoding from given " - f'"ITU-R BT.2020" values using legal range, integer output on a 10-bit ' + f'"ITU-R BT.2020" values using legal range, int output on a 10-bit ' f"system:\n\n\t{RGB}" ) print( @@ -54,7 +54,7 @@ YcCbcCrc = np.array([422, 512, 512]) message_box( f'Converting to the "ITU-R BT.2020" colourspace from given "RGB" values ' - f"using legal range, integer input on a 10-bit system:\n\n\t{RGB}" + f"using legal range, int input on a 10-bit system:\n\n\t{RGB}" ) print( colour.YcCbcCrc_to_RGB( diff --git a/colour/examples/plotting/examples_colorimetry_plots.py b/colour/examples/plotting/examples_colorimetry_plots.py index be9bc7c887..9cbfeeaaa9 100644 --- a/colour/examples/plotting/examples_colorimetry_plots.py +++ b/colour/examples/plotting/examples_colorimetry_plots.py @@ -3,7 +3,6 @@ from pprint import pprint import colour -from colour.hints import cast from colour.plotting import ( SD_ASTMG173_ETR, plot_blackbody_colours, @@ -834,9 +833,7 @@ data_street_light, name="Street Light" ) -sd_bandpass_corrected_street_light = cast( - colour.SpectralDistribution, sd_street_light.copy() -) +sd_bandpass_corrected_street_light = sd_street_light.copy() sd_bandpass_corrected_street_light.name = "Street Light (Bandpass Corrected)" sd_bandpass_corrected_street_light = colour.bandpass_correction( sd_bandpass_corrected_street_light, method="Stearns 1988" @@ -914,7 +911,7 @@ message_box("Plotting photopic luminous efficiency functions.") plot_multi_sds( - colour.colorimetry.SDS_LEFS_PHOTOPIC.values(), + list(colour.colorimetry.SDS_LEFS_PHOTOPIC.values()), title="Luminous Efficiency Functions", y_label="Luminous Efficiency", ) @@ -979,7 +976,7 @@ print("\n") message_box('Comparing theoretical and measured "Sun" spectral distributions.') -sd_ASTMG173 = cast(colour.SpectralDistribution, SD_ASTMG173_ETR.copy()) +sd_ASTMG173 = SD_ASTMG173_ETR.copy() sd_ASTMG173.interpolate( colour.SpectralShape(sd_ASTMG173.shape.start, sd_ASTMG173.shape.end, 5), @@ -989,8 +986,8 @@ sd_blackbody = colour.sd_blackbody(5778, sd_ASTMG173.shape) sd_blackbody.name = "The Sun - 5778K" -sd_blackbody /= colour.sd_to_XYZ(sd_blackbody)[1] # type: ignore[misc] -sd_blackbody *= colour.sd_to_XYZ(sd_ASTMG173)[1] # type: ignore[misc] +sd_blackbody /= colour.sd_to_XYZ(sd_blackbody)[1] +sd_blackbody *= colour.sd_to_XYZ(sd_ASTMG173)[1] plot_multi_sds([sd_ASTMG173, sd_blackbody], y_label="W / (sr m$^2$) / m") diff --git a/colour/examples/plotting/examples_section_plots.py b/colour/examples/plotting/examples_section_plots.py index 6eb1775d79..24bcbba85f 100644 --- a/colour/examples/plotting/examples_section_plots.py +++ b/colour/examples/plotting/examples_section_plots.py @@ -109,7 +109,7 @@ axes.get_ylim()[1], ] -section_colours = colour.notation.HEX_to_RGB( +section_colours = colour.notation.HEX_to_RGB( # pyright: ignore colour.plotting.CONSTANTS_COLOUR_STYLE.colour.cycle[:4] ) diff --git a/colour/geometry/__init__.py b/colour/geometry/__init__.py index 79294a7f29..0edc667cf9 100644 --- a/colour/geometry/__init__.py +++ b/colour/geometry/__init__.py @@ -91,7 +91,7 @@ def __getattr__(self, attribute) -> Any: """Defines the *colour.geometry* sub-package API changes.""" if not is_documentation_building(): - sys.modules["colour.geometry"] = geometry( # type:ignore[assignment] + sys.modules["colour.geometry"] = geometry( # pyright: ignore sys.modules["colour.geometry"], build_API_changes(API_CHANGES) ) diff --git a/colour/geometry/ellipse.py b/colour/geometry/ellipse.py index e67de5e9d8..d38d81ab56 100644 --- a/colour/geometry/ellipse.py +++ b/colour/geometry/ellipse.py @@ -26,11 +26,12 @@ from colour.hints import ( ArrayLike, Literal, - NDArray, + NDArrayFloat, Union, ) from colour.utilities import ( CanonicalMapping, + as_float_array, ones, tsplit, tstack, @@ -54,7 +55,7 @@ ] -def ellipse_coefficients_general_form(coefficients: ArrayLike) -> NDArray: +def ellipse_coefficients_general_form(coefficients: ArrayLike) -> NDArrayFloat: """ Return the general form ellipse coefficients from given canonical form ellipse coefficients. @@ -105,7 +106,9 @@ def ellipse_coefficients_general_form(coefficients: ArrayLike) -> NDArray: return np.array([a, b, c, d, e, f]) -def ellipse_coefficients_canonical_form(coefficients: ArrayLike) -> NDArray: +def ellipse_coefficients_canonical_form( + coefficients: ArrayLike, +) -> NDArrayFloat: """ Return the canonical form ellipse coefficients from given general form ellipse coefficients. @@ -170,7 +173,7 @@ def ellipse_coefficients_canonical_form(coefficients: ArrayLike) -> NDArray: def point_at_angle_on_ellipse( phi: ArrayLike, coefficients: ArrayLike -) -> NDArray: +) -> NDArrayFloat: """ Return the coordinates of the point at angle :math:`\\phi` in degrees on the ellipse with given canonical form coefficients. @@ -213,7 +216,7 @@ def point_at_angle_on_ellipse( return tstack([x, y]) -def ellipse_fitting_Halir1998(a: ArrayLike) -> NDArray: +def ellipse_fitting_Halir1998(a: ArrayLike) -> NDArrayFloat: """ Return the coefficients of the implicit second-order polynomial/quadratic curve that fits given point array :math:`a` using @@ -282,7 +285,7 @@ def ellipse_fitting_Halir1998(a: ArrayLike) -> NDArray: A = np.ravel([A1, A2]) - return A + return as_float_array(A) ELLIPSE_FITTING_METHODS: CanonicalMapping = CanonicalMapping( @@ -299,7 +302,7 @@ def ellipse_fitting_Halir1998(a: ArrayLike) -> NDArray: def ellipse_fitting( a: ArrayLike, method: Union[Literal["Halir 1998"], str] = "Halir 1998" -) -> NDArray: +) -> NDArrayFloat: """ Return the coefficients of the implicit second-order polynomial/quadratic curve that fits given point array :math:`a` using diff --git a/colour/geometry/intersection.py b/colour/geometry/intersection.py index c50fc9c59a..e5af146f7d 100644 --- a/colour/geometry/intersection.py +++ b/colour/geometry/intersection.py @@ -25,16 +25,8 @@ from dataclasses import dataclass from colour.algebra import euclidean_distance, sdiv, sdiv_mode -from colour.hints import ( - ArrayLike, - Floating, - NDArray, - cast, -) -from colour.utilities import ( - tsplit, - tstack, -) +from colour.hints import ArrayLike, NDArrayFloat +from colour.utilities import as_float_array, tsplit, tstack __author__ = "Colour Developers" __copyright__ = "Copyright 2013 Colour Developers" @@ -51,8 +43,8 @@ def extend_line_segment( - a: ArrayLike, b: ArrayLike, distance: Floating = 1 -) -> NDArray: + a: ArrayLike, b: ArrayLike, distance: float = 1 +) -> NDArrayFloat: """ Extend the line segment defined by point arrays :math:`a` and :math:`b` by given distance and return the new end point. @@ -125,10 +117,10 @@ class LineSegmentsIntersections_Specification: :math:`l_2` are coincident. """ - xy: NDArray - intersect: NDArray - parallel: NDArray - coincident: NDArray + xy: NDArrayFloat + intersect: NDArrayFloat + parallel: NDArrayFloat + coincident: NDArrayFloat def intersect_line_segments( @@ -199,6 +191,9 @@ def intersect_line_segments( [False, False, False]], dtype=bool) """ + l_1 = as_float_array(l_1) + l_2 = as_float_array(l_2) + l_1 = np.reshape(l_1, (-1, 4)) l_2 = np.reshape(l_2, (-1, 4)) @@ -225,8 +220,8 @@ def intersect_line_segments( denominator = y_4_y_3 * x_2_x_1 - x_4_x_3 * y_2_y_1 with sdiv_mode("Ignore"): - u_a = cast(NDArray, sdiv(numerator_a, denominator)) - u_b = cast(NDArray, sdiv(numerator_b, denominator)) + u_a = sdiv(numerator_a, denominator) + u_b = sdiv(numerator_b, denominator) intersect = np.logical_and.reduce((u_a >= 0, u_a <= 1, u_b >= 0, u_b <= 1)) xy = tstack([x_1 + x_2_x_1 * u_a, y_1 + y_2_y_1 * u_a]) diff --git a/colour/geometry/primitives.py b/colour/geometry/primitives.py index cfe52674e0..5a371d8c0a 100644 --- a/colour/geometry/primitives.py +++ b/colour/geometry/primitives.py @@ -24,17 +24,13 @@ from colour.constants import DEFAULT_INT_DTYPE, DEFAULT_FLOAT_DTYPE from colour.hints import ( Any, - DTypeFloating, - DTypeInteger, - Floating, - Integer, + DTypeFloat, + DTypeInt, Literal, NDArray, Optional, - Tuple, Type, Union, - cast, ) from colour.utilities import ( CanonicalMapping, @@ -75,16 +71,16 @@ def primitive_grid( - width: Floating = 1, - height: Floating = 1, - width_segments: Integer = 1, - height_segments: Integer = 1, + width: float = 1, + height: float = 1, + width_segments: int = 1, + height_segments: int = 1, axis: Literal[ "-x", "+x", "-y", "+y", "-z", "+z", "xy", "xz", "yz", "yx", "zx", "zy" ] = "+z", - dtype_vertices: Optional[Type[DTypeFloating]] = None, - dtype_indexes: Optional[Type[DTypeInteger]] = None, -) -> Tuple[NDArray, NDArray, NDArray]: + dtype_vertices: Optional[Type[DTypeFloat]] = None, + dtype_indexes: Optional[Type[DTypeInt]] = None, +) -> tuple[NDArray, NDArray, NDArray]: """ Generate vertices and indexes for a filled and outlined grid primitive. @@ -113,7 +109,7 @@ def primitive_grid( Returns ------- :class:`tuple` - Tuple of grid vertices, face indexes to produce a filled grid and + tuple of grid vertices, face indexes to produce a filled grid and outline indexes to produce an outline of the faces of the grid. References @@ -138,14 +134,10 @@ def primitive_grid( [1 0]] """ - axis = MAPPING_PLANE_TO_AXIS.get(axis, axis).lower() + axis = MAPPING_PLANE_TO_AXIS.get(axis, axis).lower() # pyright: ignore - dtype_vertices = cast( - Type[DTypeFloating], optional(dtype_vertices, DEFAULT_FLOAT_DTYPE) - ) - dtype_indexes = cast( - Type[DTypeInteger], optional(dtype_indexes, DEFAULT_INT_DTYPE) - ) + dtype_vertices = optional(dtype_vertices, DEFAULT_FLOAT_DTYPE) + dtype_indexes = optional(dtype_indexes, DEFAULT_INT_DTYPE) x_grid = width_segments y_grid = height_segments @@ -223,7 +215,7 @@ def primitive_grid( ("uv", dtype_vertices, 2), ("normal", dtype_vertices, 3), ("colour", dtype_vertices, 4), - ], # type: ignore[arg-type] + ], # pyright: ignore ) vertices["position"] = positions @@ -235,12 +227,12 @@ def primitive_grid( def primitive_cube( - width: Floating = 1, - height: Floating = 1, - depth: Floating = 1, - width_segments: Integer = 1, - height_segments: Integer = 1, - depth_segments: Integer = 1, + width: float = 1, + height: float = 1, + depth: float = 1, + width_segments: int = 1, + height_segments: int = 1, + depth_segments: int = 1, planes: Optional[ Literal[ "-x", @@ -257,9 +249,9 @@ def primitive_cube( "zy", ] ] = None, - dtype_vertices: Optional[Type[DTypeFloating]] = None, - dtype_indexes: Optional[Type[DTypeInteger]] = None, -) -> Tuple[NDArray, NDArray, NDArray]: + dtype_vertices: Optional[Type[DTypeFloat]] = None, + dtype_indexes: Optional[Type[DTypeInt]] = None, +) -> tuple[NDArray, NDArray, NDArray]: """ Generate vertices and indexes for a filled and outlined cube primitive. @@ -291,7 +283,7 @@ def primitive_cube( Returns ------- :class:`tuple` - Tuple of cube vertices, face indexes to produce a filled cube and + tuple of cube vertices, face indexes to produce a filled cube and outline indexes to produce an outline of the faces of the cube. Examples @@ -370,12 +362,8 @@ def primitive_cube( ] ) - dtype_vertices = cast( - Type[DTypeFloating], optional(dtype_vertices, DEFAULT_FLOAT_DTYPE) - ) - dtype_indexes = cast( - Type[DTypeInteger], optional(dtype_indexes, DEFAULT_INT_DTYPE) - ) + dtype_vertices = optional(dtype_vertices, DEFAULT_FLOAT_DTYPE) + dtype_indexes = optional(dtype_indexes, DEFAULT_INT_DTYPE) w_s, h_s, d_s = width_segments, height_segments, depth_segments @@ -428,7 +416,7 @@ def primitive_cube( ("uv", dtype_vertices, 2), ("normal", dtype_vertices, 3), ("colour", dtype_vertices, 4), - ], # type: ignore[arg-type] + ], # pyright: ignore ) vertex_colours = np.ravel(positions) @@ -467,7 +455,7 @@ def primitive_cube( def primitive( method: Union[Literal["Cube", "Grid"], str] = "Cube", **kwargs: Any -) -> Tuple[NDArray, NDArray, NDArray]: +) -> tuple[NDArray, NDArray, NDArray]: """ Return a geometry primitive using given method. @@ -525,7 +513,7 @@ def primitive( Returns ------- :class:`tuple` - Tuple of primitive vertices, face indexes to produce a filled primitive + tuple of primitive vertices, face indexes to produce a filled primitive and outline indexes to produce an outline of the faces of the primitive. diff --git a/colour/geometry/section.py b/colour/geometry/section.py index 9bafcb4259..06f98b751d 100644 --- a/colour/geometry/section.py +++ b/colour/geometry/section.py @@ -14,13 +14,12 @@ from colour.algebra import linear_conversion from colour.constants import DEFAULT_FLOAT_DTYPE from colour.hints import ( + Any, ArrayLike, - Boolean, - Floating, - Integer, Literal, - NDArray, + NDArrayFloat, Union, + cast, ) from colour.utilities import ( as_float_array, @@ -44,7 +43,7 @@ ] -def edges_to_chord(edges: ArrayLike, index: Integer = 0) -> NDArray: +def edges_to_chord(edges: ArrayLike, index: int = 0) -> NDArrayFloat: """ Convert given edges to a chord, starting at given index. @@ -114,7 +113,7 @@ def edges_to_chord(edges: ArrayLike, index: Integer = 0) -> NDArray: return as_float_array(edges_ordered).reshape([-1, segment.shape[-1]]) -def close_chord(vertices: ArrayLike) -> NDArray: +def close_chord(vertices: ArrayLike) -> NDArrayFloat: """ Close the chord. @@ -143,8 +142,8 @@ def close_chord(vertices: ArrayLike) -> NDArray: def unique_vertices( vertices: ArrayLike, - decimals: Integer = np.finfo(DEFAULT_FLOAT_DTYPE).precision - 1, -) -> NDArray: + decimals: int = np.finfo(cast(Any, DEFAULT_FLOAT_DTYPE)).precision - 1, +) -> NDArrayFloat: """ Return the unique vertices from given vertices. @@ -184,11 +183,11 @@ def unique_vertices( @required("trimesh") def hull_section( - hull: trimesh.Trimesh, # type: ignore[name-defined] # noqa + hull: trimesh.Trimesh, # pyright: ignore # noqa axis: Union[Literal["+z", "+x", "+y"], str] = "+z", - origin: Floating = 0.5, - normalise: Boolean = False, -) -> NDArray: + origin: float = 0.5, + normalise: bool = False, +) -> NDArrayFloat: """ Compute the hull section for given axis at given origin. diff --git a/colour/geometry/vertices.py b/colour/geometry/vertices.py index 13ea8478df..0a49df154c 100644 --- a/colour/geometry/vertices.py +++ b/colour/geometry/vertices.py @@ -21,12 +21,8 @@ from colour.hints import ( Any, ArrayLike, - Boolean, - Floating, - Integer, - List, Literal, - NDArray, + NDArrayFloat, Optional, Union, ) @@ -60,12 +56,12 @@ def primitive_vertices_quad_mpl( - width: Floating = 1, - height: Floating = 1, - depth: Floating = 0, + width: float = 1, + height: float = 1, + depth: float = 0, origin: ArrayLike = np.array([0, 0]), axis: Union[Literal["+z", "+x", "+y", "yz", "xz", "xy"], str] = "+z", -) -> NDArray: +) -> NDArrayFloat: """ Return the vertices of a quad primitive for use with *Matplotlib* :class:`mpl_toolkits.mplot3d.art3d.Poly3DCollection` class. @@ -131,14 +127,14 @@ def primitive_vertices_quad_mpl( def primitive_vertices_grid_mpl( - width: Floating = 1, - height: Floating = 1, - depth: Floating = 0, - width_segments: Integer = 1, - height_segments: Integer = 1, + width: float = 1, + height: float = 1, + depth: float = 0, + width_segments: int = 1, + height_segments: int = 1, origin: ArrayLike = np.array([0, 0]), axis: Union[Literal["+z", "+x", "+y", "yz", "xz", "xy"], str] = "+z", -) -> NDArray: +) -> NDArrayFloat: """ Return the vertices of a grid primitive made of quad primitives for use with *Matplotlib* :class:`mpl_toolkits.mplot3d.art3d.Poly3DCollection` @@ -208,12 +204,12 @@ def primitive_vertices_grid_mpl( def primitive_vertices_cube_mpl( - width: Floating = 1, - height: Floating = 1, - depth: Floating = 1, - width_segments: Integer = 1, - height_segments: Integer = 1, - depth_segments: Integer = 1, + width: float = 1, + height: float = 1, + depth: float = 1, + width_segments: int = 1, + height_segments: int = 1, + depth_segments: int = 1, origin: ArrayLike = np.array([0, 0, 0]), planes: Optional[ Literal[ @@ -231,7 +227,7 @@ def primitive_vertices_cube_mpl( "zy", ] ] = None, -) -> NDArray: +) -> NDArrayFloat: """ Return the vertices of a cube primitive made of grid primitives for use with *Matplotlib* :class:`mpl_toolkits.mplot3d.art3d.Poly3DCollection` @@ -307,7 +303,7 @@ def primitive_vertices_cube_mpl( w_s, h_s, d_s = width_segments, height_segments, depth_segments - grids: List = [] + grids: list = [] if "-z" in axis: grids.extend( primitive_vertices_grid_mpl( @@ -351,12 +347,12 @@ def primitive_vertices_cube_mpl( def primitive_vertices_sphere( - radius: Floating = 0.5, - segments: Integer = 8, - intermediate: Boolean = False, + radius: float = 0.5, + segments: int = 8, + intermediate: bool = False, origin: ArrayLike = np.array([0, 0, 0]), axis: Union[Literal["+z", "+x", "+y", "yz", "xz", "xy"], str] = "+z", -) -> NDArray: +) -> NDArrayFloat: """ Return the vertices of a latitude-longitude sphere primitive. @@ -415,6 +411,8 @@ def primitive_vertices_sphere( [ 3.7493994...e-33, 6.1232340...e-17, -5.0000000...e-01]]]) """ + origin = as_float_array(origin) + axis = MAPPING_PLANE_TO_AXIS.get(axis, axis).lower() axis = validate_method( axis, ["+x", "+y", "+z"], '"{0}" axis invalid, it must be one of {1}!' @@ -489,7 +487,7 @@ def primitive_vertices( Literal["Cube MPL", "Quad MPL", "Grid MPL", "Sphere"], str ] = "Cube MPL", **kwargs: Any, -) -> NDArray: +) -> NDArrayFloat: """ Return the vertices of a geometry primitive using given method. diff --git a/colour/graph/conversion.py b/colour/graph/conversion.py index 123a75042a..8eb529f7a5 100644 --- a/colour/graph/conversion.py +++ b/colour/graph/conversion.py @@ -42,13 +42,8 @@ Any, ArrayLike, Callable, - Dict, - FloatingOrArrayLike, - FloatingOrNDArray, - Integer, - List, Literal, - NDArray, + NDArrayFloat, Optional, Union, cast, @@ -255,7 +250,7 @@ def __new__(cls, source: str, target: str, conversion_function: Callable): def CIECAM02_to_JMh_CIECAM02( specification: CAM_Specification_CIECAM02, -) -> NDArray: +) -> NDArrayFloat: """ Convert from *CIECAM02* specification to *CIECAM02* :math:`JMh` correlates. @@ -281,9 +276,9 @@ def CIECAM02_to_JMh_CIECAM02( return tstack( [ - cast(FloatingOrNDArray, specification.J), - cast(FloatingOrNDArray, specification.M), - cast(FloatingOrNDArray, specification.h), + cast(NDArrayFloat, specification.J), + cast(NDArrayFloat, specification.M), + cast(NDArrayFloat, specification.h), ] ) @@ -317,7 +312,7 @@ def JMh_CIECAM02_to_CIECAM02(JMh: ArrayLike) -> CAM_Specification_CIECAM02: return CAM_Specification_CIECAM02(J=J, M=M, h=h) -def CAM16_to_JMh_CAM16(specification) -> NDArray: +def CAM16_to_JMh_CAM16(specification) -> NDArrayFloat: """ Convert from *CAM16* specification to *CAM16* :math:`JMh` correlates. @@ -371,7 +366,7 @@ def JMh_CAM16_to_CAM16(JMh: ArrayLike) -> CAM_Specification_CAM16: return CAM_Specification_CAM16(J=J, M=M, h=h) -def CIECAM16_to_JMh_CIECAM16(specification) -> NDArray: +def CIECAM16_to_JMh_CIECAM16(specification) -> NDArrayFloat: """ Convert from *CIECAM16* specification to *CIECAM16* :math:`JMh` correlates. @@ -425,7 +420,7 @@ def JMh_CIECAM16_to_CIECAM16(JMh: ArrayLike) -> CAM_Specification_CIECAM16: return CAM_Specification_CIECAM16(J=J, M=M, h=h) -def Hellwig2022_to_JMh_Hellwig2022(specification) -> NDArray: +def Hellwig2022_to_JMh_Hellwig2022(specification) -> NDArrayFloat: """ Convert from *Hellwig and Fairchild (2022)* specification to *Hellwig and Fairchild (2022)* :math:`JMh` correlates. @@ -483,7 +478,7 @@ def JMh_Hellwig2022_to_Hellwig2022( return CAM_Specification_Hellwig2022(J=J, M=M, h=h) -def XYZ_to_luminance(XYZ: ArrayLike) -> FloatingOrNDArray: +def XYZ_to_luminance(XYZ: ArrayLike) -> NDArrayFloat: """ Convert from *CIE XYZ* tristimulus values to *luminance* :math:`Y`. @@ -494,7 +489,7 @@ def XYZ_to_luminance(XYZ: ArrayLike) -> FloatingOrNDArray: Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` *Luminance* :math:`Y`. Examples @@ -510,7 +505,7 @@ def XYZ_to_luminance(XYZ: ArrayLike) -> FloatingOrNDArray: return Y -def RGB_luminance_to_RGB(Y: FloatingOrArrayLike) -> NDArray: +def RGB_luminance_to_RGB(Y: ArrayLike) -> NDArrayFloat: """ Convert from *luminance* :math:`Y` to *RGB*. @@ -538,7 +533,7 @@ def RGB_luminance_to_RGB(Y: FloatingOrArrayLike) -> NDArray: _ILLUMINANT_DEFAULT: str = "D65" """Default automatic colour conversion graph illuminant name.""" -_CCS_ILLUMINANT_DEFAULT: NDArray = CCS_ILLUMINANTS[ +_CCS_ILLUMINANT_DEFAULT: NDArrayFloat = CCS_ILLUMINANTS[ "CIE 1931 2 Degree Standard Observer" ][_ILLUMINANT_DEFAULT] """ @@ -546,7 +541,7 @@ def RGB_luminance_to_RGB(Y: FloatingOrArrayLike) -> NDArray: coordinates. """ -_TVS_ILLUMINANT_DEFAULT: NDArray = xy_to_XYZ(_CCS_ILLUMINANT_DEFAULT) +_TVS_ILLUMINANT_DEFAULT: NDArrayFloat = xy_to_XYZ(_CCS_ILLUMINANT_DEFAULT) """ Default automatic colour conversion graph illuminant *CIE XYZ* tristimulus values. @@ -555,7 +550,7 @@ def RGB_luminance_to_RGB(Y: FloatingOrArrayLike) -> NDArray: _RGB_COLOURSPACE_DEFAULT: RGB_Colourspace = RGB_COLOURSPACE_sRGB """Default automatic colour conversion graph *RGB* colourspace.""" -_CAM_KWARGS_CIECAM02_sRGB: Dict = CAM_KWARGS_CIECAM02_sRGB.copy() +_CAM_KWARGS_CIECAM02_sRGB: dict = CAM_KWARGS_CIECAM02_sRGB.copy() """ Default parameter values for the *CIECAM02* colour appearance model usage in the context of *sRGB*. @@ -568,7 +563,7 @@ def RGB_luminance_to_RGB(Y: FloatingOrArrayLike) -> NDArray: _CAM_KWARGS_CIECAM02_sRGB["XYZ_w"] = _CAM_KWARGS_CIECAM02_sRGB["XYZ_w"] / 100 -CONVERSION_SPECIFICATIONS_DATA: List = [ +CONVERSION_SPECIFICATIONS_DATA: list[tuple] = [ # Colorimetry ("Spectral Distribution", "CIE XYZ", sd_to_XYZ), ("CIE XYZ", "Spectral Distribution", XYZ_to_sd), @@ -922,7 +917,7 @@ def RGB_luminance_to_RGB(Y: FloatingOrArrayLike) -> NDArray: the edge in the graph. """ -CONVERSION_SPECIFICATIONS: List = [ +CONVERSION_SPECIFICATIONS: list = [ Conversion_Specification(*specification) for specification in CONVERSION_SPECIFICATIONS_DATA ] @@ -931,7 +926,7 @@ def RGB_luminance_to_RGB(Y: FloatingOrArrayLike) -> NDArray: the edge in the graph. """ -CONVERSION_GRAPH_NODE_LABELS: Dict = { +CONVERSION_GRAPH_NODE_LABELS: dict = { specification[0].lower(): specification[0] for specification in CONVERSION_SPECIFICATIONS_DATA } @@ -946,7 +941,7 @@ def RGB_luminance_to_RGB(Y: FloatingOrArrayLike) -> NDArray: @required("NetworkX") -def _build_graph() -> networkx.DiGraph: # type: ignore[name-defined] # noqa +def _build_graph() -> networkx.DiGraph: # pyright: ignore # noqa """ Build the automatic colour conversion graph. @@ -970,14 +965,14 @@ def _build_graph() -> networkx.DiGraph: # type: ignore[name-defined] # noqa return graph -CONVERSION_GRAPH: ( # type: ignore[name-defined] - Optional[networkx.DiGraph] # noqa +CONVERSION_GRAPH: ( + Optional[networkx.DiGraph] # pyright: ignore # noqa ) = None """Automatic colour conversion graph.""" @required("NetworkX") -def _conversion_path(source: str, target: str) -> List[Callable]: +def _conversion_path(source: str, target: str) -> list[Callable]: """ Return the conversion path from the source node to the target node in the automatic colour conversion graph. @@ -1014,7 +1009,9 @@ def _conversion_path(source: str, target: str) -> List[Callable]: path = nx.shortest_path(CONVERSION_GRAPH, source, target) return [ - CONVERSION_GRAPH.get_edge_data(a, b)["conversion_function"] + CONVERSION_GRAPH.get_edge_data(a, b)[ # pyright: ignore + "conversion_function" + ] for a, b in zip(path[:-1], path[1:]) ] @@ -1043,8 +1040,8 @@ def describe_conversion_path( source: str, target: str, mode: Union[Literal["Short", "Long", "Extended"], str] = "Short", - width: Integer = 79, - padding: Integer = 3, + width: int = 79, + padding: int = 3, print_callable: Callable = print, **kwargs: Any, ): @@ -1092,7 +1089,7 @@ def describe_conversion_path( try: # pragma: no cover signature_inspection = inspect.signature except AttributeError: # pragma: no cover - signature_inspection = inspect.getfullargspec # type: ignore[assignment] + signature_inspection = inspect.getfullargspec source, target = source.lower(), target.lower() mode = validate_method( diff --git a/colour/hints/__init__.py b/colour/hints/__init__.py index 3d110746e1..d8c8ea3ead 100644 --- a/colour/hints/__init__.py +++ b/colour/hints/__init__.py @@ -10,49 +10,33 @@ from __future__ import annotations import numpy as np -import numpy.typing as npt import re +from numpy.typing import ArrayLike, NDArray from types import ModuleType from typing import ( Any, Callable, - Dict, Generator, Iterable, Iterator, - List, + Literal, Mapping, NewType, Optional, - Union, + Protocol, Sequence, - TextIO, - Tuple, + SupportsIndex, TYPE_CHECKING, + TextIO, Type, TypeVar, + TypedDict, + Union, cast, overload, + runtime_checkable, ) - -try: - from typing import ( - Literal, - Protocol, - SupportsIndex, - TypedDict, - runtime_checkable, - ) -# TODO: Drop "typing_extensions" when "Google Colab" uses Python >= 3.8. -# Remove exclusion in ".pre-commit-config.yaml" file for "pyupgrade". -except ImportError: # pragma: no cover - from typing_extensions import ( # type: ignore[assignment] - Literal, - Protocol, - SupportsIndex, - TypedDict, - runtime_checkable, - ) +from typing_extensions import Self __author__ = "Colour Developers" __copyright__ = "Copyright 2013 Colour Developers" @@ -62,83 +46,55 @@ __status__ = "Production" __all__ = [ + "ModuleType", "Any", "Callable", - "Dict", "Generator", "Iterable", "Iterator", - "List", + "Literal", "Mapping", - "ModuleType", + "NewType", "Optional", - "Union", + "Protocol", "Sequence", "SupportsIndex", + "TYPE_CHECKING", "TextIO", - "Tuple", "Type", - "TypedDict", "TypeVar", + "TypedDict", + "Union", + "cast", + "overload", + "runtime_checkable", + "Self", + "ArrayLike", + "NDArray", "RegexFlag", - "DTypeBoolean", - "DTypeInteger", - "DTypeFloating", + "DTypeInt", + "DTypeFloat", "DTypeNumber", "DTypeComplex", + "DTypeBoolean", "DType", - "Integer", - "Floating", "Number", - "Complex", - "Boolean", - "Literal", "Dataclass", - "NestedSequence", - "ArrayLike", - "IntegerOrArrayLike", - "FloatingOrArrayLike", - "NumberOrArrayLike", - "ComplexOrArrayLike", - "BooleanOrArrayLike", - "ScalarType", - "StrOrArrayLike", - "NDArray", - "IntegerOrNDArray", - "FloatingOrNDArray", - "NumberOrNDArray", - "ComplexOrNDArray", - "BooleanOrNDArray", - "StrOrNDArray", + "NDArrayInt", + "NDArrayFloat", + "NDArrayNumber", + "NDArrayComplex", + "NDArrayBoolean", + "NDArrayStr", "TypeInterpolator", "TypeExtrapolator", "TypeLUTSequenceItem", "LiteralWarning", - "cast", ] -Any = Any -Callable = Callable -Dict = Dict -Generator = Generator -Iterable = Iterable -Iterator = Iterator -List = List -Mapping = Mapping -ModuleType = ModuleType -Optional = Optional -Union = Union -Sequence = Sequence -SupportsIndex = SupportsIndex -TextIO = TextIO -Tuple = Tuple -Type = Type -TypedDict = TypedDict -TypeVar = TypeVar - RegexFlag = NewType("RegexFlag", re.RegexFlag) -DTypeInteger = Union[ +DTypeInt = Union[ np.int8, np.int16, np.int32, @@ -148,171 +104,62 @@ np.uint32, np.uint64, ] -DTypeFloating = Union[np.float16, np.float32, np.float64] -DTypeNumber = Union[DTypeInteger, DTypeFloating] +DTypeFloat = Union[np.float16, np.float32, np.float64] +DTypeNumber = Union[DTypeInt, DTypeFloat] DTypeComplex = Union[np.csingle, np.cdouble] DTypeBoolean = np.bool_ DType = Union[DTypeBoolean, DTypeNumber, DTypeComplex] -Integer = int -Floating = float -Number = Union[Integer, Floating] -Complex = complex -Boolean = bool - -# TODO: Use "typing.Literal" when minimal Python version is raised to 3.8. -Literal = Literal +Number = Union[int, float] # TODO: Revisit to use Protocol. Dataclass = Any -# TODO: Drop mocking when minimal "Numpy" version is 1.21.x. -_T_co = TypeVar("_T_co", covariant=True) - - -class NestedSequence(Protocol[_T_co]): - """A protocol for representing nested sequences. - - Warning - ------- - `NestedSequence` currently does not work in combination with typevars, - *e.g.* ``def func(a: _NestedSequnce[T]) -> T: ...``. - - See Also - -------- - collections.abc.Sequence - ABCs for read-only and mutable :term:`sequences`. - - Examples - -------- - >>> from __future__ import annotations - - >>> from typing import TYPE_CHECKING - >>> import numpy as np - - >>> def get_dtype(seq: NestedSequence[float]) -> np.dtype[np.float64]: - ... return np.asarray(seq).dtype +NDArrayInt = NDArray[DTypeInt] +NDArrayFloat = NDArray[DTypeFloat] +NDArrayNumber = NDArray[Union[DTypeInt, DTypeFloat]] +NDArrayComplex = NDArray[DTypeComplex] +NDArrayBoolean = NDArray[DTypeBoolean] +NDArrayStr = NDArray[np.str_] - >>> a = get_dtype([1.0]) - >>> b = get_dtype([[1.0]]) - >>> c = get_dtype([[[1.0]]]) - >>> d = get_dtype([[[[1.0]]]]) - >>> if TYPE_CHECKING: - ... reveal_locals() - ... # note: Revealed local types are: - ... # note: a: numpy.dtype[numpy.floating[numpy._typing._64Bit]] - ... # note: b: numpy.dtype[numpy.floating[numpy._typing._64Bit]] - ... # note: c: numpy.dtype[numpy.floating[numpy._typing._64Bit]] - ... # note: d: numpy.dtype[numpy.floating[numpy._typing._64Bit]] - ... - - """ - - def __len__(self) -> int: - """Implement ``len(self)``.""" - raise NotImplementedError - - @overload - def __getitem__( - self, index: int - ) -> _T_co | NestedSequence[_T_co]: # noqa: D105 +class TypeInterpolator(Protocol): # noqa: D101 + @property + def x(self) -> NDArray: # noqa: D102 ... - @overload - def __getitem__(self, index: slice) -> NestedSequence[_T_co]: # noqa: D105 + @x.setter + def x(self, value: ArrayLike): # noqa: D102 ... - def __getitem__(self, index): - """Implement ``self[x]``.""" - raise NotImplementedError - - def __contains__(self, x: object) -> bool: - """Implement ``x in self``.""" - raise NotImplementedError - - def __iter__(self) -> Iterator[_T_co | NestedSequence[_T_co]]: - """Implement ``iter(self)``.""" - raise NotImplementedError - - def __reversed__(self) -> Iterator[_T_co | NestedSequence[_T_co]]: - """Implement ``reversed(self)``.""" - raise NotImplementedError - - def count(self, value: Any) -> int: - """Return the number of occurrences of `value`.""" - raise NotImplementedError - - def index(self, value: Any) -> int: - """Return the first index of `value`.""" - raise NotImplementedError - - -ArrayLike = npt.ArrayLike -IntegerOrArrayLike = Union[Integer, ArrayLike] -FloatingOrArrayLike = Union[Floating, ArrayLike] -NumberOrArrayLike = Union[Number, ArrayLike] -ComplexOrArrayLike = Union[Complex, ArrayLike] - -BooleanOrArrayLike = Union[Boolean, ArrayLike] - -StrOrArrayLike = Union[str, ArrayLike] - -ScalarType = TypeVar("ScalarType", bound=np.generic, covariant=True) - -# TODO: Use "numpy.typing.NDArray" when minimal Numpy version is raised to -# 1.21. -if TYPE_CHECKING: # pragma: no cover - NDArray = np.ndarray[Any, np.dtype[ScalarType]] -else: - NDArray = np.ndarray - -# TODO: Drop when minimal Python is raised to 3.9. -if TYPE_CHECKING: # pragma: no cover - IntegerOrNDArray = Union[Integer, NDArray[DTypeInteger]] - FloatingOrNDArray = Union[Floating, NDArray[DTypeFloating]] - NumberOrNDArray = Union[ - Number, NDArray[Union[DTypeInteger, DTypeFloating]] - ] - ComplexOrNDArray = Union[Complex, NDArray[DTypeComplex]] - - BooleanOrNDArray = Union[Boolean, NDArray[DTypeBoolean]] - - StrOrNDArray = Union[str, NDArray[np.str_]] - -else: - IntegerOrNDArray = Union[Integer, NDArray] - FloatingOrNDArray = Union[Floating, NDArray] - NumberOrNDArray = Union[Number, NDArray] - ComplexOrNDArray = Union[Complex, NDArray] - - BooleanOrNDArray = Union[Boolean, NDArray] - - StrOrNDArray = Union[str, NDArray] - + @property + def y(self) -> NDArray: # noqa: D102 + ... -class TypeInterpolator(Protocol): # noqa: D101 - x: NDArray - y: NDArray + @y.setter + def y(self, value: ArrayLike): # noqa: D102 + ... def __init__(self, *args: Any, **kwargs: Any) -> None: # noqa: D102 ... # pragma: no cover - def __call__( - self, x: FloatingOrArrayLike - ) -> FloatingOrNDArray: # noqa: D102 + def __call__(self, x: ArrayLike) -> NDArray: # noqa: D102 ... # pragma: no cover class TypeExtrapolator(Protocol): # noqa: D101 - interpolator: TypeInterpolator + @property + def interpolator(self) -> TypeInterpolator: # noqa: D102 + ... + + @interpolator.setter + def interpolator(self, value: TypeInterpolator): # noqa: D102 + ... def __init__(self, *args: Any, **kwargs: Any) -> None: # noqa: D102 ... # pragma: no cover - def __call__( - self, x: FloatingOrArrayLike - ) -> FloatingOrNDArray: # noqa: D102 + def __call__(self, x: ArrayLike) -> NDArray: # noqa: D102 ... # pragma: no cover @@ -326,29 +173,23 @@ def apply(self, RGB: ArrayLike, **kwargs: Any) -> NDArray: # noqa: D102 "default", "error", "ignore", "always", "module", "once" ] -cast = cast - -def arraylike( # type: ignore[empty-body] - a: ArrayLike | NestedSequence[ArrayLike], -) -> NDArray: +def arraylike(a: ArrayLike) -> NDArray: ... -def number_or_arraylike( # type: ignore[empty-body] - a: NumberOrArrayLike | NestedSequence[ArrayLike], -) -> NDArray: +def number_or_arraylike(a: ArrayLike) -> NDArray: ... -a: DTypeFloating = np.float64(1) +a: DTypeFloat = np.float64(1) b: float = 1 -c: Floating = 1 +c: float = 1 d: ArrayLike = [c, c] -e: FloatingOrArrayLike = d -s_a: Sequence[DTypeFloating] = [a, a] +e: ArrayLike = d +s_a: Sequence[DTypeFloat] = [a, a] s_b: Sequence[float] = [b, b] -s_c: Sequence[Floating] = [c, c] +s_c: Sequence[float] = [c, c] arraylike(a) arraylike(b) diff --git a/colour/io/ctl.py b/colour/io/ctl.py index 5c79ceb5de..6de2073955 100644 --- a/colour/io/ctl.py +++ b/colour/io/ctl.py @@ -21,17 +21,15 @@ from colour.hints import ( Any, ArrayLike, - Dict, - FloatingOrNDArray, + NDArrayFloat, Optional, Sequence, - Tuple, Union, ) from colour.io import as_3_channels_image, read_image, write_image from colour.utilities import ( as_float_array, - as_float_scalar, + as_float, optional, required, ) @@ -58,7 +56,7 @@ *ctlrender* executable name. """ -ARGUMENTS_CTL_RENDER_DEFAULTS: Tuple = ("-verbose", "-force") +ARGUMENTS_CTL_RENDER_DEFAULTS: tuple = ("-verbose", "-force") """ *ctlrender* invocation default arguments. """ @@ -71,7 +69,7 @@ def ctl_render( path_input: str, path_output: str, - ctl_transforms: Union[Sequence[str], Dict[str, Sequence[str]]], + ctl_transforms: Union[Sequence[str], dict[str, Sequence[str]]], *args: Any, **kwargs: Any, ) -> subprocess.CompletedProcess: # pragma: no cover @@ -158,7 +156,7 @@ def ctl_render( command = [EXECUTABLE_CTL_RENDER] - ctl_transforms_mapping: Dict[str, Sequence] + ctl_transforms_mapping: dict[str, Sequence] if isinstance(ctl_transforms, Sequence): ctl_transforms_mapping = dict.fromkeys(ctl_transforms, []) else: @@ -197,10 +195,10 @@ def ctl_render( @required("ctlrender") def process_image_ctl( a: ArrayLike, - ctl_transforms: Union[Sequence[str], Dict[str, Sequence[str]]], + ctl_transforms: Union[Sequence[str], dict[str, Sequence[str]]], *args: Any, **kwargs: Any, -) -> FloatingOrNDArray: # pragma: no cover +) -> NDArrayFloat: # pragma: no cover """ Process given image data with *ctlrender* using given *CTL* transforms. @@ -289,7 +287,7 @@ def process_image_ctl( os.remove(temp_output_filename) if len(shape) == 0: - return as_float_scalar(np.squeeze(b)[0]) + return as_float(np.squeeze(b)[0]) elif shape[-1] == 1: return np.reshape(b[..., 0], shape) else: @@ -320,9 +318,9 @@ def template_ctl_transform_float( description Description of the *CTL* transform. parameters - List of parameters to use with the *CTL* transform. + list of parameters to use with the *CTL* transform. imports - List of imports to use with the *CTL* transform. + list of imports to use with the *CTL* transform. header Header code that can be used to define various functions and globals. @@ -470,9 +468,9 @@ def template_ctl_transform_float3( description Description of the *CTL* transform. parameters - List of parameters to use with the *CTL* transform. + list of parameters to use with the *CTL* transform. imports - List of imports to use with the *CTL* transform. + list of imports to use with the *CTL* transform. header Header code that can be used to define various functions and globals. diff --git a/colour/io/image.py b/colour/io/image.py index d2bf8fd680..8f8bc363b8 100644 --- a/colour/io/image.py +++ b/colour/io/image.py @@ -13,14 +13,13 @@ from colour.hints import ( Any, ArrayLike, - Boolean, DTypeNumber, - List, Literal, - NDArray, + NDArrayFloat, + NDArrayNumber, Optional, Sequence, - Tuple, + TYPE_CHECKING, Type, Union, cast, @@ -99,7 +98,7 @@ class ImageAttribute_Specification: name: str value: Any - type_: Optional[OpenImageIO.TypeDesc] = field( # type: ignore[name-defined] # noqa + type_: Optional[OpenImageIO.TypeDesc] = field( # pyright: ignore # noqa default_factory=lambda: None ) @@ -116,26 +115,26 @@ class ImageAttribute_Specification: "float64": BitDepth_Specification("float64", np.float64, DOUBLE), } ) - if hasattr(np, "float128"): # pragma: no cover - MAPPING_BIT_DEPTH["float128"] = BitDepth_Specification( - "float128", np.float128, DOUBLE # type: ignore[arg-type] - ) + if not TYPE_CHECKING: + if hasattr(np, "float128"): # pragma: no cover + MAPPING_BIT_DEPTH["float128"] = BitDepth_Specification( + "float128", np.float128, DOUBLE + ) else: # pragma: no cover - MAPPING_BIT_DEPTH: CanonicalMapping = ( # type: ignore[no-redef] - CanonicalMapping( - { - "uint8": BitDepth_Specification("uint8", np.uint8, None), - "uint16": BitDepth_Specification("uint16", np.uint16, None), - "float16": BitDepth_Specification("float16", np.float16, None), - "float32": BitDepth_Specification("float32", np.float32, None), - "float64": BitDepth_Specification("float64", np.float64, None), - } - ) + MAPPING_BIT_DEPTH: CanonicalMapping = CanonicalMapping( + { + "uint8": BitDepth_Specification("uint8", np.uint8, None), + "uint16": BitDepth_Specification("uint16", np.uint16, None), + "float16": BitDepth_Specification("float16", np.float16, None), + "float32": BitDepth_Specification("float32", np.float32, None), + "float64": BitDepth_Specification("float64", np.float64, None), + } ) - if hasattr(np, "float128"): # pragma: no cover - MAPPING_BIT_DEPTH["float128"] = BitDepth_Specification( - "float128", np.float128, None # type: ignore[arg-type] - ) + if not TYPE_CHECKING: + if hasattr(np, "float128"): # pragma: no cover + MAPPING_BIT_DEPTH["float128"] = BitDepth_Specification( + "float128", np.float128, None + ) def convert_bit_depth( @@ -143,7 +142,7 @@ def convert_bit_depth( bit_depth: Literal[ "uint8", "uint16", "float16", "float32", "float64", "float128" ] = "float32", -) -> NDArray: +) -> NDArrayNumber: """ Convert given array to given bit depth, the current bit depth of the array is used to determine the appropriate conversion path. @@ -211,7 +210,7 @@ def convert_bit_depth( elif bit_depth in ("float16", "float32", "float64", "float128"): a = a.astype(target_dtype) - return a # type: ignore[return-value] + return a @required("OpenImageIO") @@ -220,8 +219,10 @@ def read_image_OpenImageIO( bit_depth: Literal[ "uint8", "uint16", "float16", "float32", "float64", "float128" ] = "float32", - attributes: Boolean = False, -) -> Union[NDArray, Tuple[NDArray, List]]: # noqa: D405,D410,D407,D411 + attributes: bool = False, +) -> Union[ + NDArrayNumber, tuple[NDArrayNumber, list] +]: # noqa: D405,D410,D407,D411 """ Read the image data at given path using *OpenImageIO*. @@ -303,7 +304,7 @@ def read_image_Imageio( "uint8", "uint16", "float16", "float32", "float64", "float128" ] = "float32", **kwargs: Any, -) -> NDArray: +) -> NDArrayNumber: """ Read the image data at given path using *Imageio*. @@ -373,7 +374,7 @@ def read_image( ] = "float32", method: Union[Literal["Imageio", "OpenImageIO"], str] = "OpenImageIO", **kwargs: Any, -) -> NDArray: # noqa: D405,D407,D410,D411,D414 +) -> NDArrayNumber: # noqa: D405,D407,D410,D411,D414 """ Read the image data at given path using given method. @@ -453,7 +454,7 @@ def write_image_OpenImageIO( "uint8", "uint16", "float16", "float32", "float64", "float128" ] = "float32", attributes: Optional[Sequence] = None, -) -> Boolean: # noqa: D405,D407,D410,D411 +) -> bool: # noqa: D405,D407,D410,D411 """ Write given image data at given path using *OpenImageIO*. @@ -537,7 +538,7 @@ def write_image_OpenImageIO( image = as_float_array(image) path = str(path) - attributes = cast(List, optional(attributes, [])) + attributes = cast(list, optional(attributes, [])) bit_depth_specification = MAPPING_BIT_DEPTH[bit_depth] @@ -680,7 +681,7 @@ def write_image( ] = "float32", method: Union[Literal["Imageio", "OpenImageIO"], str] = "OpenImageIO", **kwargs: Any, -) -> Boolean: # noqa: D405,D407,D410,D411,D414 +) -> bool: # noqa: D405,D407,D410,D411,D414 """ Write given image data at given path using given method. @@ -771,7 +772,7 @@ def write_image( return function(image, path, bit_depth, **kwargs) -def as_3_channels_image(a: ArrayLike) -> NDArray: +def as_3_channels_image(a: ArrayLike) -> NDArrayFloat: """ Convert given array :math:`a` to a 3-channels image-like representation. diff --git a/colour/io/luts/__init__.py b/colour/io/luts/__init__.py index 9a35baf848..416e717702 100644 --- a/colour/io/luts/__init__.py +++ b/colour/io/luts/__init__.py @@ -15,7 +15,7 @@ import os -from colour.hints import Any, Boolean, Integer, Literal, Optional, Union, cast +from colour.hints import Any, Literal, Optional, Union from colour.utilities import ( CanonicalMapping, filter_kwargs, @@ -220,11 +220,8 @@ def read_LUT( Offset : [ 0. 0. 0. 0.] """ - method = cast( - str, - optional( - method, MAPPING_EXTENSION_TO_LUT_FORMAT[os.path.splitext(path)[-1]] - ), + method = optional( + method, MAPPING_EXTENSION_TO_LUT_FORMAT[os.path.splitext(path)[-1]] ) method = validate_method(method, LUT_READ_METHODS) @@ -265,7 +262,7 @@ def read_LUT( def write_LUT( LUT: Union[LUT1D, LUT3x1D, LUT3D, LUTSequence, LUTOperatorMatrix], path: str, - decimals: Integer = 7, + decimals: int = 7, method: Optional[ Union[ Literal[ @@ -280,7 +277,7 @@ def write_LUT( ] ] = None, **kwargs: Any, -) -> Boolean: +) -> bool: """ Write given *LUT* to given file using given method. @@ -346,11 +343,8 @@ def write_LUT( >>> write_LUT(LUT, "My_LUT.cube") # doctest: +SKIP """ - method = cast( - str, - optional( - method, MAPPING_EXTENSION_TO_LUT_FORMAT[os.path.splitext(path)[-1]] - ), + method = optional( + method, MAPPING_EXTENSION_TO_LUT_FORMAT[os.path.splitext(path)[-1]] ) method = validate_method(method, LUT_WRITE_METHODS) diff --git a/colour/io/luts/cinespace_csp.py b/colour/io/luts/cinespace_csp.py index e65b2424ea..76b96b63ab 100644 --- a/colour/io/luts/cinespace_csp.py +++ b/colour/io/luts/cinespace_csp.py @@ -21,11 +21,7 @@ from colour.hints import ( ArrayLike, - Boolean, - Integer, - List, - NDArray, - Tuple, + NDArrayFloat, Union, ) from colour.io.luts import LUT1D, LUT3x1D, LUT3D, LUTSequence @@ -112,12 +108,12 @@ def read_LUT_Cinespace(path: str) -> Union[LUT3x1D, LUT3D, LUTSequence]: unity_range = np.array([[0.0, 0.0, 0.0], [1.0, 1.0, 1.0]]) - def _parse_metadata_section(metadata: List) -> Tuple: + def _parse_metadata_section(metadata: list) -> tuple: """Parse the metadata at given lines.""" return (metadata[0], metadata[1:]) if len(metadata) > 0 else ("", []) - def _parse_domain_section(lines: List[str]) -> NDArray: + def _parse_domain_section(lines: list[str]) -> NDArrayFloat: """Parse the domain at given lines.""" pre_LUT_size = max(int(lines[i]) for i in [0, 3, 6]) @@ -253,8 +249,8 @@ def _parse_table_section(lines): def write_LUT_Cinespace( - LUT: Union[LUT3x1D, LUT3D, LUTSequence], path: str, decimals: Integer = 7 -) -> Boolean: + LUT: Union[LUT3x1D, LUT3D, LUTSequence], path: str, decimals: int = 7 +) -> bool: """ Write given *LUT* to given *Cinespace* *.csp* *LUT* file. @@ -347,7 +343,7 @@ def write_LUT_Cinespace( 2 <= LUT[1].size <= 256, "Cube size must be in domain [2, 256]!" ) - def _ragged_size(table: ArrayLike) -> List: + def _ragged_size(table: ArrayLike) -> list: """Return the ragged size of given table.""" R, G, B = tsplit(table) @@ -358,12 +354,12 @@ def _ragged_size(table: ArrayLike) -> List: return [R_len, G_len, B_len] - def _format_array(array: Union[List, Tuple]) -> str: + def _format_array(array: Union[list, tuple]) -> str: """Format given array as a *Cinespace* *.cube* data row.""" return "{1:0.{0}f} {2:0.{0}f} {3:0.{0}f}".format(decimals, *array) - def _format_tuple(array: Union[List, Tuple]) -> str: + def _format_tuple(array: Union[list, tuple]) -> str: """ Format given array as 2 space separated values to *decimals* precision. diff --git a/colour/io/luts/iridas_cube.py b/colour/io/luts/iridas_cube.py index 943000bde2..d55c1a6197 100644 --- a/colour/io/luts/iridas_cube.py +++ b/colour/io/luts/iridas_cube.py @@ -20,7 +20,7 @@ from colour.io.luts import LUT1D, LUT3x1D, LUT3D, LUTSequence from colour.io.luts.common import path_to_title -from colour.hints import Boolean, Integer, List, Tuple, Union +from colour.hints import Union from colour.utilities import ( as_float_array, as_int_scalar, @@ -120,8 +120,8 @@ def read_LUT_IridasCube(path: str) -> Union[LUT3x1D, LUT3D]: title = path_to_title(path) domain_min, domain_max = np.array([0, 0, 0]), np.array([1, 1, 1]) - dimensions: Integer = 3 - size: Integer = 2 + dimensions: int = 3 + size: int = 2 data = [] comments = [] @@ -180,8 +180,8 @@ def read_LUT_IridasCube(path: str) -> Union[LUT3x1D, LUT3D]: def write_LUT_IridasCube( - LUT: Union[LUT3x1D, LUT3D, LUTSequence], path: str, decimals: Integer = 7 -) -> Boolean: + LUT: Union[LUT3x1D, LUT3D, LUTSequence], path: str, decimals: int = 7 +) -> bool: """ Write given *LUT* to given *Iridas* *.cube* *LUT* file. @@ -261,7 +261,7 @@ def write_LUT_IridasCube( else: attest(2 <= size <= 256, '"LUT" size must be in domain [2, 256]!') - def _format_array(array: Union[List, Tuple]) -> str: + def _format_array(array: Union[list, tuple]) -> str: """Format given array as an *Iridas* *.cube* data row.""" return "{1:0.{0}f} {2:0.{0}f} {3:0.{0}f}".format(decimals, *array) diff --git a/colour/io/luts/lut.py b/colour/io/luts/lut.py index 0e37ef7dc9..980f90bbfa 100644 --- a/colour/io/luts/lut.py +++ b/colour/io/luts/lut.py @@ -38,16 +38,11 @@ from colour.hints import ( Any, ArrayLike, - Boolean, - Dict, - FloatingOrArrayLike, - Integer, - IntegerOrArrayLike, - List, Literal, - NDArray, + NDArrayFloat, Optional, Sequence, + Self, Type, Union, cast, @@ -153,34 +148,28 @@ def __init__( self, table: Optional[ArrayLike] = None, name: Optional[str] = None, - dimensions: Optional[Integer] = None, + dimensions: Optional[int] = None, domain: Optional[ArrayLike] = None, - size: Optional[IntegerOrArrayLike] = None, + size: Optional[ArrayLike] = None, comments: Optional[Sequence] = None, ) -> None: self._name: str = f"Unity {size!r}" if table is None else f"{id(self)}" self.name = optional(name, self._name) self._dimensions = optional(dimensions, 0) - self._table: NDArray = self.linear_table( + self._table: NDArrayFloat = self.linear_table( cast(ArrayLike, optional(size, 0)), cast(ArrayLike, optional(domain, np.array([]))), ) - self.table = cast( - ArrayLike, optional(table, self._table) - ) # type: ignore[assignment] + self.table = cast(ArrayLike, optional(table, self._table)) # TODO: Remove pragma when https://github.com/python/mypy/issues/3004 # is resolved. - self._domain: NDArray = np.array([]) - self.domain = cast( - ArrayLike, optional(domain, self._domain) - ) # type: ignore[assignment] - self._comments: List = [] - self.comments = cast( - ArrayLike, optional(comments, self._comments) - ) # type: ignore[assignment] + self._domain: NDArrayFloat = np.array([]) + self.domain = cast(ArrayLike, optional(domain, self._domain)) + self._comments: list = [] + self.comments = cast(list, optional(comments, self._comments)) @property - def table(self) -> NDArray: + def table(self) -> NDArrayFloat: """ Getter and setter property for the underlying *LUT* table. @@ -233,7 +222,7 @@ def name(self, value: str): self._name = value @property - def domain(self) -> NDArray: + def domain(self) -> NDArrayFloat: """ Getter and setter property for the *LUT* domain. @@ -258,33 +247,33 @@ def domain(self, value: ArrayLike): self._domain = self._validate_domain(value) @property - def dimensions(self) -> Integer: + def dimensions(self) -> int: """ Getter property for the *LUT* dimensions. Returns ------- - :class:`numpy.integer` + :class:`int` *LUT* dimensions. """ return self._dimensions @property - def size(self) -> Integer: + def size(self) -> int: """ Getter property for the *LUT* size. Returns ------- - :class:`numpy.integer` + :class:`int` *LUT* size. """ return self._table.shape[0] @property - def comments(self) -> List: + def comments(self) -> list: """ Getter and setter property for the *LUT* comments. @@ -350,7 +339,7 @@ def __str__(self) -> str: } ) - return multiline_str(self, cast(List[Dict], attributes)) + return multiline_str(self, cast(list[dict], attributes)) def __repr__(self) -> str: """ @@ -417,9 +406,7 @@ def __ne__(self, other: Any) -> bool: return not (self == other) - def __add__( - self, a: Union[FloatingOrArrayLike, AbstractLUT] - ) -> AbstractLUT: + def __add__(self, a: Union[ArrayLike, Self]) -> Self: """ Implement support for addition. @@ -436,9 +423,7 @@ def __add__( return self.arithmetical_operation(a, "+") - def __iadd__( - self, a: Union[FloatingOrArrayLike, AbstractLUT] - ) -> AbstractLUT: + def __iadd__(self, a: Union[ArrayLike, Self]) -> Self: """ Implement support for in-place addition. @@ -455,9 +440,7 @@ def __iadd__( return self.arithmetical_operation(a, "+", True) - def __sub__( - self, a: Union[FloatingOrArrayLike, AbstractLUT] - ) -> AbstractLUT: + def __sub__(self, a: Union[ArrayLike, Self]) -> Self: """ Implement support for subtraction. @@ -474,9 +457,7 @@ def __sub__( return self.arithmetical_operation(a, "-") - def __isub__( - self, a: Union[FloatingOrArrayLike, AbstractLUT] - ) -> AbstractLUT: + def __isub__(self, a: Union[ArrayLike, Self]) -> Self: """ Implement support for in-place subtraction. @@ -493,9 +474,7 @@ def __isub__( return self.arithmetical_operation(a, "-", True) - def __mul__( - self, a: Union[FloatingOrArrayLike, AbstractLUT] - ) -> AbstractLUT: + def __mul__(self, a: Union[ArrayLike, Self]) -> Self: """ Implement support for multiplication. @@ -512,9 +491,7 @@ def __mul__( return self.arithmetical_operation(a, "*") - def __imul__( - self, a: Union[FloatingOrArrayLike, AbstractLUT] - ) -> AbstractLUT: + def __imul__(self, a: Union[ArrayLike, Self]) -> Self: """ Implement support for in-place multiplication. @@ -531,9 +508,7 @@ def __imul__( return self.arithmetical_operation(a, "*", True) - def __div__( - self, a: Union[FloatingOrArrayLike, AbstractLUT] - ) -> AbstractLUT: + def __div__(self, a: Union[ArrayLike, Self]) -> Self: """ Implement support for division. @@ -550,9 +525,7 @@ def __div__( return self.arithmetical_operation(a, "/") - def __idiv__( - self, a: Union[FloatingOrArrayLike, AbstractLUT] - ) -> AbstractLUT: + def __idiv__(self, a: Union[ArrayLike, Self]) -> Self: """ Implement support for in-place division. @@ -572,9 +545,7 @@ def __idiv__( __itruediv__ = __idiv__ __truediv__ = __div__ - def __pow__( - self, a: Union[FloatingOrArrayLike, AbstractLUT] - ) -> AbstractLUT: + def __pow__(self, a: Union[ArrayLike, Self]) -> Self: """ Implement support for exponentiation. @@ -591,9 +562,7 @@ def __pow__( return self.arithmetical_operation(a, "**") - def __ipow__( - self, a: Union[FloatingOrArrayLike, AbstractLUT] - ) -> AbstractLUT: + def __ipow__(self, a: Union[ArrayLike, Self]) -> Self: """ Implement support for in-place exponentiation. @@ -612,10 +581,10 @@ def __ipow__( def arithmetical_operation( self, - a: Union[FloatingOrArrayLike, AbstractLUT], + a: Union[ArrayLike, Self], operation: Literal["+", "-", "*", "/", "**"], - in_place: Boolean = False, - ) -> AbstractLUT: + in_place: bool = False, + ) -> Self: """ Perform given arithmetical operation with :math:`a` operand, the operation can be either performed on a copy or in-place, must be @@ -659,7 +628,7 @@ def arithmetical_operation( return copy @abstractmethod - def _validate_table(self, table: ArrayLike) -> NDArray: + def _validate_table(self, table: ArrayLike) -> NDArrayFloat: """ Validate given table according to *LUT* dimensions. @@ -677,7 +646,7 @@ def _validate_table(self, table: ArrayLike) -> NDArray: pass @abstractmethod - def _validate_domain(self, domain: ArrayLike) -> NDArray: + def _validate_domain(self, domain: ArrayLike) -> NDArrayFloat: """ Validate given domain according to *LUT* dimensions. @@ -695,7 +664,7 @@ def _validate_domain(self, domain: ArrayLike) -> NDArray: pass @abstractmethod - def is_domain_explicit(self) -> Boolean: + def is_domain_explicit(self) -> bool: """ Return whether the *LUT* domain is explicit (or implicit). @@ -726,9 +695,9 @@ def is_domain_explicit(self) -> Boolean: @staticmethod @abstractmethod def linear_table( - size: Optional[IntegerOrArrayLike] = None, + size: Optional[ArrayLike] = None, domain: Optional[ArrayLike] = None, - ) -> NDArray: + ) -> NDArrayFloat: """ Return a linear table of given size according to *LUT* dimensions. @@ -751,7 +720,7 @@ def linear_table( pass - def copy(self) -> AbstractLUT: + def copy(self) -> Self: """ Return a copy of the sub-class instance. @@ -764,7 +733,7 @@ def copy(self) -> AbstractLUT: return deepcopy(self) @abstractmethod - def invert(self, **kwargs: Any) -> AbstractLUT: + def invert(self, **kwargs: Any) -> Self: """ Compute and returns an inverse copy of the *LUT*. @@ -782,7 +751,7 @@ def invert(self, **kwargs: Any) -> AbstractLUT: pass @abstractmethod - def apply(self, RGB: ArrayLike, **kwargs: Any) -> NDArray: + def apply(self, RGB: ArrayLike, **kwargs: Any) -> NDArrayFloat: """ Apply the *LUT* to given *RGB* colourspace array using given method. @@ -818,10 +787,10 @@ def apply(self, RGB: ArrayLike, **kwargs: Any) -> NDArray: @abstractmethod def convert( self, - cls: Type[AbstractLUT], - force_conversion: Boolean = False, + cls: Type[Self], + force_conversion: bool = False, **kwargs: Any, - ) -> AbstractLUT: + ) -> Self: """ Convert the *LUT* to given ``cls`` class instance. @@ -938,18 +907,18 @@ def __init__( table: Optional[ArrayLike] = None, name: Optional[str] = None, domain: Optional[ArrayLike] = None, - size: Optional[IntegerOrArrayLike] = None, + size: Optional[ArrayLike] = None, comments: Optional[Sequence] = None, ) -> None: domain = as_float_array( cast(ArrayLike, optional(domain, np.array([0, 1]))) ) - size = cast(Integer, optional(size, 10)) + size = cast(int, optional(size, 10)) super().__init__(table, name, 1, domain, size, comments) - def _validate_table(self, table: ArrayLike) -> NDArray: + def _validate_table(self, table: ArrayLike) -> NDArrayFloat: """ Validate given table is a 1D array. @@ -970,7 +939,7 @@ def _validate_table(self, table: ArrayLike) -> NDArray: return table - def _validate_domain(self, domain: ArrayLike) -> NDArray: + def _validate_domain(self, domain: ArrayLike) -> NDArrayFloat: """ Validate given domain. @@ -996,7 +965,7 @@ def _validate_domain(self, domain: ArrayLike) -> NDArray: return domain - def is_domain_explicit(self) -> Boolean: + def is_domain_explicit(self) -> bool: """ Return whether the *LUT* domain is explicit (or implicit). @@ -1026,9 +995,9 @@ def is_domain_explicit(self) -> Boolean: @staticmethod def linear_table( - size: Optional[IntegerOrArrayLike] = None, + size: Optional[ArrayLike] = None, domain: Optional[ArrayLike] = None, - ) -> NDArray: + ) -> NDArrayFloat: """ Return a linear table, the number of output samples :math:`n` is equal to ``size``. @@ -1053,7 +1022,7 @@ def linear_table( array([-0.1, 0.3, 0.7, 1.1, 1.5]) """ - size = cast(Integer, optional(size, 10)) + size = cast(int, optional(size, 10)) domain = as_float_array( cast(ArrayLike, optional(domain, np.array([0, 1]))) ) @@ -1065,7 +1034,7 @@ def linear_table( return np.linspace(domain[0], domain[1], as_int_scalar(size)) - def invert(self, **kwargs: Any) -> LUT1D: + def invert(self, **kwargs: Any) -> Self: """ Compute and returns an inverse copy of the *LUT*. @@ -1116,7 +1085,7 @@ def invert(self, **kwargs: Any) -> LUT1D: return LUT_i - def apply(self, RGB: ArrayLike, **kwargs: Any) -> NDArray: + def apply(self, RGB: ArrayLike, **kwargs: Any) -> NDArrayFloat: """ Apply the *LUT* to given *RGB* colourspace array using given method. @@ -1190,7 +1159,7 @@ def apply(self, RGB: ArrayLike, **kwargs: Any) -> NDArray: def convert( self, cls: Type[AbstractLUT], - force_conversion: Boolean = False, + force_conversion: bool = False, **kwargs: Any, ) -> AbstractLUT: """ @@ -1257,7 +1226,9 @@ def convert( Size : (33, 33, 33, 3) """ - return LUT_to_LUT(self, cls, force_conversion, **kwargs) + return LUT_to_LUT( + self, cls, force_conversion, **kwargs # pyright: ignore + ) # ------------------------------------------------------------------------# # --- API Changes and Deprecation Management ---# @@ -1265,7 +1236,7 @@ def convert( def as_LUT( self, cls: Type[AbstractLUT], - force_conversion: Boolean = False, + force_conversion: bool = False, **kwargs: Any, ) -> AbstractLUT: # pragma: no cover # noqa: D102 # Docstrings are omitted for documentation purposes. @@ -1362,17 +1333,17 @@ def __init__( table: Optional[ArrayLike] = None, name: Optional[str] = None, domain: Optional[ArrayLike] = None, - size: Optional[IntegerOrArrayLike] = None, + size: Optional[ArrayLike] = None, comments: Optional[Sequence] = None, ) -> None: domain = cast( ArrayLike, optional(domain, np.array([[0, 0, 0], [1, 1, 1]])) ) - size = cast(Integer, optional(size, 10)) + size = cast(int, optional(size, 10)) super().__init__(table, name, 2, domain, size, comments) - def _validate_table(self, table: ArrayLike) -> NDArray: + def _validate_table(self, table: ArrayLike) -> NDArrayFloat: """ Validate given table is a 3x1D array. @@ -1393,7 +1364,7 @@ def _validate_table(self, table: ArrayLike) -> NDArray: return table - def _validate_domain(self, domain: ArrayLike) -> NDArray: + def _validate_domain(self, domain: ArrayLike) -> NDArrayFloat: """ Validate given domain. @@ -1423,7 +1394,7 @@ def _validate_domain(self, domain: ArrayLike) -> NDArray: return domain - def is_domain_explicit(self) -> Boolean: + def is_domain_explicit(self) -> bool: """ Return whether the *LUT* domain is explicit (or implicit). @@ -1462,9 +1433,9 @@ def is_domain_explicit(self) -> Boolean: @staticmethod def linear_table( - size: Optional[IntegerOrArrayLike] = None, + size: Optional[ArrayLike] = None, domain: Optional[ArrayLike] = None, - ) -> NDArray: + ) -> NDArrayFloat: """ Return a linear table, the number of output samples :math:`n` is equal to ``size * 3`` or ``size[0] + size[1] + size[2]``. @@ -1523,7 +1494,7 @@ def linear_table( [ 1.5, nan, nan]]) """ - size = cast(Integer, optional(size, 10)) + size = cast(int, optional(size, 10)) domain = as_float_array( cast(ArrayLike, optional(domain, np.array([[0, 0, 0], [1, 1, 1]]))) ) @@ -1561,7 +1532,7 @@ def linear_table( return tstack(samples) - def invert(self, **kwargs: Any) -> LUT3x1D: + def invert(self, **kwargs: Any) -> Self: """ Compute and returns an inverse copy of the *LUT*. @@ -1640,7 +1611,7 @@ def invert(self, **kwargs: Any) -> LUT3x1D: return LUT_i - def apply(self, RGB: ArrayLike, **kwargs: Any) -> NDArray: + def apply(self, RGB: ArrayLike, **kwargs: Any) -> NDArrayFloat: """ Apply the *LUT* to given *RGB* colourspace array using given method. @@ -1747,7 +1718,7 @@ def apply(self, RGB: ArrayLike, **kwargs: Any) -> NDArray: def convert( self, cls: Type[AbstractLUT], - force_conversion: Boolean = False, + force_conversion: bool = False, **kwargs: Any, ) -> AbstractLUT: """ @@ -1814,7 +1785,9 @@ def convert( Size : (33, 33, 33, 3) """ - return LUT_to_LUT(self, cls, force_conversion, **kwargs) + return LUT_to_LUT( + self, cls, force_conversion, **kwargs # pyright: ignore + ) # ------------------------------------------------------------------------# # --- API Changes and Deprecation Management ---# @@ -1822,7 +1795,7 @@ def convert( def as_LUT( self, cls: Type[AbstractLUT], - force_conversion: Boolean = False, + force_conversion: bool = False, **kwargs: Any, ) -> AbstractLUT: # pragma: no cover # noqa: D102 # Docstrings are omitted for documentation purposes. @@ -1918,17 +1891,17 @@ def __init__( table: Optional[ArrayLike] = None, name: Optional[str] = None, domain: Optional[ArrayLike] = None, - size: Optional[IntegerOrArrayLike] = None, + size: Optional[ArrayLike] = None, comments: Optional[Sequence] = None, ) -> None: domain = cast( ArrayLike, optional(domain, np.array([[0, 0, 0], [1, 1, 1]])) ) - size = cast(Integer, optional(size, 33)) + size = cast(int, optional(size, 33)) super().__init__(table, name, 3, domain, size, comments) - def _validate_table(self, table: ArrayLike) -> NDArray: + def _validate_table(self, table: ArrayLike) -> NDArrayFloat: """ Validate given table is a 4D array and that its dimensions are equal. @@ -1949,7 +1922,7 @@ def _validate_table(self, table: ArrayLike) -> NDArray: return table - def _validate_domain(self, domain: ArrayLike) -> NDArray: + def _validate_domain(self, domain: ArrayLike) -> NDArrayFloat: """ Validate given domain. @@ -1983,7 +1956,7 @@ def _validate_domain(self, domain: ArrayLike) -> NDArray: return domain - def is_domain_explicit(self) -> Boolean: + def is_domain_explicit(self) -> bool: """ Return whether the *LUT* domain is explicit (or implicit). @@ -2022,9 +1995,9 @@ def is_domain_explicit(self) -> Boolean: @staticmethod def linear_table( - size: Optional[IntegerOrArrayLike] = None, + size: Optional[ArrayLike] = None, domain: Optional[ArrayLike] = None, - ) -> NDArray: + ) -> NDArrayFloat: """ Return a linear table, the number of output samples :math:`n` is equal to ``size**3 * 3`` or ``size[0] * size[1] * size[2] * 3``. @@ -2150,7 +2123,7 @@ def linear_table( [ 1.5, 3. , 6. ]]]]) """ - size = cast(Integer, optional(size, 33)) + size = cast(int, optional(size, 33)) domain = as_float_array( cast(ArrayLike, optional(domain, np.array([[0, 0, 0], [1, 1, 1]]))) ) @@ -2189,7 +2162,7 @@ def linear_table( return table - def invert(self, **kwargs: Any) -> LUT3D: + def invert(self, **kwargs: Any) -> Self: """ Compute and returns an inverse copy of the *LUT*. @@ -2296,7 +2269,7 @@ def invert(self, **kwargs: Any) -> LUT3D: return LUT_q - def apply(self, RGB: ArrayLike, **kwargs: Any) -> NDArray: + def apply(self, RGB: ArrayLike, **kwargs: Any) -> NDArrayFloat: """ Apply the *LUT* to given *RGB* colourspace array using given method. @@ -2399,7 +2372,7 @@ def apply(self, RGB: ArrayLike, **kwargs: Any) -> NDArray: def convert( self, cls: Type[AbstractLUT], - force_conversion: Boolean = False, + force_conversion: bool = False, **kwargs: Any, ) -> AbstractLUT: """ @@ -2466,7 +2439,9 @@ class instance. Size : (33, 33, 33, 3) """ - return LUT_to_LUT(self, cls, force_conversion, **kwargs) + return LUT_to_LUT( + self, cls, force_conversion, **kwargs # pyright: ignore + ) # ------------------------------------------------------------------------# # --- API Changes and Deprecation Management ---# @@ -2474,7 +2449,7 @@ class instance. def as_LUT( self, cls: Type[AbstractLUT], - force_conversion: Boolean = False, + force_conversion: bool = False, **kwargs: Any, ) -> AbstractLUT: # pragma: no cover # noqa: D102 # Docstrings are omitted for documentation purposes. @@ -2492,8 +2467,8 @@ def as_LUT( def LUT_to_LUT( LUT, - cls: Type[AbstractLUT], - force_conversion: Boolean = False, + cls: Union[LUT1D, LUT3x1D, LUT3D], + force_conversion: bool = False, **kwargs: Any, ) -> AbstractLUT: """ @@ -2561,7 +2536,7 @@ def LUT_to_LUT( """ ranks = {LUT1D: 1, LUT3x1D: 2, LUT3D: 3} - path = (ranks[LUT.__class__], ranks[cls]) + path = (ranks[LUT.__class__], ranks[cls]) # pyright: ignore path_verbose = [ f"{element}D" if element != 2 else "3x1D" for element in path ] @@ -2624,6 +2599,6 @@ def LUT_to_LUT( domain=domain, size=table.shape[0], comments=LUT.comments, - ) + ) # pyright: ignore return LUT diff --git a/colour/io/luts/operator.py b/colour/io/luts/operator.py index 15a6d395b2..536eac4a6d 100644 --- a/colour/io/luts/operator.py +++ b/colour/io/luts/operator.py @@ -17,8 +17,7 @@ from colour.hints import ( Any, ArrayLike, - List, - NDArray, + NDArrayFloat, Optional, Sequence, cast, @@ -79,8 +78,8 @@ def __init__( self.name = optional(name, self._name) # TODO: Remove pragma when https://github.com/python/mypy/issues/3004 # is resolved. - self._comments: List[str] = [] - self.comments = optional(comments, self._comments) # type: ignore[arg-type] + self._comments: list[str] = [] + self.comments = optional(comments, self._comments) @property def name(self) -> str: @@ -112,7 +111,7 @@ def name(self, value: str): self._name = value @property - def comments(self) -> List[str]: + def comments(self) -> list[str]: """ Getter and setter property for the *LUT* comments. @@ -141,7 +140,7 @@ def comments(self, value: Sequence[str]): self._comments = list(value) @abstractmethod - def apply(self, RGB: ArrayLike, *args: Any, **kwargs: Any) -> NDArray: + def apply(self, RGB: ArrayLike, *args: Any, **kwargs: Any) -> NDArrayFloat: """ Apply the *LUT* sequence operator to given *RGB* colourspace array. @@ -255,17 +254,13 @@ def __init__( # TODO: Remove pragma when https://github.com/python/mypy/issues/3004 # is resolved. - self._matrix: NDArray = np.diag(ones(4)) - self.matrix = cast( - ArrayLike, optional(matrix, self._matrix) - ) # type: ignore[assignment] - self._offset: NDArray = zeros(4) - self.offset = cast( - ArrayLike, optional(offset, self._offset) - ) # type: ignore[assignment] + self._matrix: NDArrayFloat = np.diag(ones(4)) + self.matrix = cast(ArrayLike, optional(matrix, self._matrix)) + self._offset: NDArrayFloat = zeros(4) + self.offset = cast(ArrayLike, optional(offset, self._offset)) @property - def matrix(self) -> NDArray: + def matrix(self) -> NDArrayFloat: """ Getter and setter property for the *LUT* operator matrix. @@ -303,7 +298,7 @@ def matrix(self, value: ArrayLike): self._matrix = M @property - def offset(self) -> NDArray: + def offset(self) -> NDArrayFloat: """ Getter and setter property for the *LUT* operator offset. @@ -484,7 +479,7 @@ def __ne__(self, other: Any) -> bool: return not (self == other) - def apply(self, RGB: ArrayLike, *args: Any, **kwargs: Any) -> NDArray: + def apply(self, RGB: ArrayLike, *args: Any, **kwargs: Any) -> NDArrayFloat: """ Apply the *LUT* operator to given *RGB* array. diff --git a/colour/io/luts/resolve_cube.py b/colour/io/luts/resolve_cube.py index 50303c4aed..2d5e32a8bd 100644 --- a/colour/io/luts/resolve_cube.py +++ b/colour/io/luts/resolve_cube.py @@ -19,7 +19,7 @@ import numpy as np -from colour.hints import Boolean, Integer, List, Tuple, Union +from colour.hints import Union from colour.io.luts import LUT1D, LUT3x1D, LUT3D, LUTSequence from colour.io.luts.common import path_to_title from colour.utilities import as_float_array, as_int_scalar, attest, tstack @@ -157,8 +157,8 @@ def read_LUT_ResolveCube(path: str) -> Union[LUT3x1D, LUT3D, LUTSequence]: title = path_to_title(path) domain_3x1D, domain_3D = None, None - size_3x1D: Integer = 2 - size_3D: Integer = 2 + size_3x1D: int = 2 + size_3D: int = 2 data = [] comments = [] has_3x1D, has_3D = False, False @@ -230,8 +230,8 @@ def read_LUT_ResolveCube(path: str) -> Union[LUT3x1D, LUT3D, LUTSequence]: def write_LUT_ResolveCube( LUT: Union[LUT1D, LUT3x1D, LUT3D, LUTSequence], path: str, - decimals: Integer = 7, -) -> Boolean: + decimals: int = 7, +) -> bool: """ Write given *LUT* to given *Resolve* *.cube* *LUT* file. @@ -364,12 +364,12 @@ def write_LUT_ResolveCube( 2 <= LUT[1].size <= 256, "Cube size must be in domain [2, 256]!" ) - def _format_array(array: Union[List, Tuple]) -> str: + def _format_array(array: Union[list, tuple]) -> str: """Format given array as a *Resolve* *.cube* data row.""" return "{1:0.{0}f} {2:0.{0}f} {3:0.{0}f}".format(decimals, *array) - def _format_tuple(array: Union[List, Tuple]) -> str: + def _format_tuple(array: Union[list, tuple]) -> str: """ Format given array as 2 space separated values to *decimals* precision. diff --git a/colour/io/luts/sequence.py b/colour/io/luts/sequence.py index c8ac31830c..b15095eb82 100644 --- a/colour/io/luts/sequence.py +++ b/colour/io/luts/sequence.py @@ -16,9 +16,7 @@ from colour.hints import ( Any, ArrayLike, - Integer, - List, - NDArray, + NDArrayFloat, Sequence, TypeLUTSequenceItem, Union, @@ -114,11 +112,11 @@ class LUTSequence(MutableSequence): def __init__(self, *args: TypeLUTSequenceItem) -> None: # TODO: Remove pragma when https://github.com/python/mypy/issues/3004 # is resolved. - self._sequence: List[TypeLUTSequenceItem] = [] - self.sequence = args # type: ignore[assignment] + self._sequence: list[TypeLUTSequenceItem] = [] + self.sequence = args @property - def sequence(self) -> List[TypeLUTSequenceItem]: + def sequence(self) -> list[TypeLUTSequenceItem]: """ Getter and setter property for the underlying *LUT* sequence. @@ -148,7 +146,7 @@ def sequence(self, value: Sequence[TypeLUTSequenceItem]): self._sequence = list(value) - def __getitem__(self, index: Union[Integer, slice]) -> Any: + def __getitem__(self, index: Union[int, slice]) -> Any: """ Return the *LUT* sequence item(s) at given index (or slice). @@ -165,7 +163,7 @@ def __getitem__(self, index: Union[Integer, slice]) -> Any: return self._sequence[index] - def __setitem__(self, index: Union[Integer, slice], value: Any): + def __setitem__(self, index: Union[int, slice], value: Any): """ Set the *LUT* sequence at given index (or slice) with given value. @@ -186,7 +184,7 @@ def __setitem__(self, index: Union[Integer, slice], value: Any): self._sequence[index] = value - def __delitem__(self, index: Union[Integer, slice]): + def __delitem__(self, index: Union[int, slice]): """ Delete the *LUT* sequence item(s) at given index (or slice). @@ -198,13 +196,13 @@ def __delitem__(self, index: Union[Integer, slice]): del self._sequence[index] - def __len__(self) -> Integer: + def __len__(self) -> int: """ Return the *LUT* sequence items count. Returns ------- - :class:`numpy.integer` + :class:`int` *LUT* sequence items count. """ @@ -310,7 +308,7 @@ def __ne__(self, other) -> bool: return not (self == other) - def insert(self, index: Integer, item: TypeLUTSequenceItem): + def insert(self, index: int, item: TypeLUTSequenceItem): """ Insert given *LUT* at given index into the *LUT* sequence. @@ -330,7 +328,7 @@ def insert(self, index: Integer, item: TypeLUTSequenceItem): self._sequence.insert(index, item) - def apply(self, RGB: ArrayLike, **kwargs: Any) -> NDArray: + def apply(self, RGB: ArrayLike, **kwargs: Any) -> NDArrayFloat: """ Apply the *LUT* sequence sequentially to given *RGB* colourspace array. diff --git a/colour/io/luts/sony_spi1d.py b/colour/io/luts/sony_spi1d.py index 72214716ff..d3a403ed20 100644 --- a/colour/io/luts/sony_spi1d.py +++ b/colour/io/luts/sony_spi1d.py @@ -15,7 +15,7 @@ from colour.io.luts import LUT1D, LUT3x1D, LUTSequence from colour.io.luts.common import path_to_title -from colour.hints import Boolean, Integer, List, Tuple, Union +from colour.hints import Union from colour.utilities import ( as_float_array, as_int_scalar, @@ -154,8 +154,8 @@ def read_LUT_SonySPI1D(path: str) -> Union[LUT1D, LUT3x1D]: def write_LUT_SonySPI1D( - LUT: Union[LUT1D, LUT3x1D, LUTSequence], path: str, decimals: Integer = 7 -) -> Boolean: + LUT: Union[LUT1D, LUT3x1D, LUTSequence], path: str, decimals: int = 7 +) -> bool: """ Write given *LUT* to given *Sony* *.spi1d* *LUT* file. @@ -230,7 +230,7 @@ def write_LUT_SonySPI1D( attest(len(domain) == 2, 'Non-uniform "LUT" domain is unsupported!') - def _format_array(array: Union[List, Tuple]) -> str: + def _format_array(array: Union[list, tuple]) -> str: """Format given array as a *Sony* *.spi1d* data row.""" return " {1:0.{0}f} {2:0.{0}f} {3:0.{0}f}".format(decimals, *array) diff --git a/colour/io/luts/sony_spi3d.py b/colour/io/luts/sony_spi3d.py index e36c72e34e..f140e0fac9 100644 --- a/colour/io/luts/sony_spi3d.py +++ b/colour/io/luts/sony_spi3d.py @@ -15,7 +15,7 @@ from colour.io.luts import LUT3D, LUTSequence from colour.io.luts.common import path_to_title -from colour.hints import Boolean, Integer, List, Tuple, Union +from colour.hints import Union from colour.utilities import ( as_float_array, as_int_array, @@ -92,7 +92,7 @@ def read_LUT_SonySPI3D(path: str) -> LUT3D: title = path_to_title(path) domain_min, domain_max = np.array([0, 0, 0]), np.array([1, 1, 1]) - size: Integer = 2 + size: int = 2 data_table = [] data_indexes = [] comments = [] @@ -139,8 +139,8 @@ def read_LUT_SonySPI3D(path: str) -> LUT3D: def write_LUT_SonySPI3D( - LUT: Union[LUT3D, LUTSequence], path: str, decimals: Integer = 7 -) -> Boolean: + LUT: Union[LUT3D, LUTSequence], path: str, decimals: int = 7 +) -> bool: """ Write given *LUT* to given *Sony* *.spi3d* *LUT* file. @@ -203,7 +203,7 @@ def write_LUT_SonySPI3D( '"LUT" domain must be [[0, 0, 0], [1, 1, 1]]!', ) - def _format_array(array: Union[List, Tuple]) -> str: + def _format_array(array: Union[list, tuple]) -> str: """Format given array as a *Sony* *.spi3d* data row.""" return "{1:d} {2:d} {3:d} {4:0.{0}f} {5:0.{0}f} {6:0.{0}f}".format( diff --git a/colour/io/luts/sony_spimtx.py b/colour/io/luts/sony_spimtx.py index c95093ef1b..a98bc2e56a 100644 --- a/colour/io/luts/sony_spimtx.py +++ b/colour/io/luts/sony_spimtx.py @@ -13,10 +13,8 @@ import numpy as np from colour.constants import DEFAULT_FLOAT_DTYPE -from colour.hints import Integer from colour.io.luts.common import path_to_title from colour.io.luts import LUTOperatorMatrix -from colour.hints import Boolean __author__ = "Colour Developers" __copyright__ = "Copyright 2013 Colour Developers" @@ -77,8 +75,8 @@ def read_LUT_SonySPImtx(path: str) -> LUTOperatorMatrix: def write_LUT_SonySPImtx( - LUT: LUTOperatorMatrix, path: str, decimals: Integer = 7 -) -> Boolean: + LUT: LUTOperatorMatrix, path: str, decimals: int = 7 +) -> bool: """ Write given *LUT* to given *Sony* *.spimtx* *LUT* file. diff --git a/colour/io/luts/tests/test_lut.py b/colour/io/luts/tests/test_lut.py index a4a92f45e3..bc6cc731c1 100644 --- a/colour/io/luts/tests/test_lut.py +++ b/colour/io/luts/tests/test_lut.py @@ -21,9 +21,7 @@ from colour.hints import ( Any, Callable, - Dict, - Integer, - NDArray, + NDArrayFloat, Optional, Type, TypeInterpolator, @@ -50,7 +48,7 @@ ROOT_RESOURCES: str = os.path.join(os.path.dirname(__file__), "resources") -RANDOM_TRIPLETS: NDArray = np.reshape( +RANDOM_TRIPLETS: NDArrayFloat = np.reshape( random_triplet_generator(8, random_state=np.random.RandomState(4)), (4, 2, 3), ) @@ -127,35 +125,35 @@ def __init__(self, *args: Any) -> None: self._LUT_factory: Any = None - self._size: Optional[Integer] = None - self._dimensions: Optional[Integer] = None - self._domain_1: Optional[NDArray] = None - self._domain_2: Optional[NDArray] = None - self._domain_3: Optional[NDArray] = None - self._table_1: Optional[NDArray] = None - self._table_2: Optional[NDArray] = None - self._table_3: Optional[NDArray] = None - self._table_1_kwargs: Optional[Dict] = None - self._table_2_kwargs: Optional[Dict] = None - self._table_3_kwargs: Optional[Dict] = None + self._size: Optional[int] = None + self._dimensions: Optional[int] = None + self._domain_1: Optional[NDArrayFloat] = None + self._domain_2: Optional[NDArrayFloat] = None + self._domain_3: Optional[NDArrayFloat] = None + self._table_1: Optional[NDArrayFloat] = None + self._table_2: Optional[NDArrayFloat] = None + self._table_3: Optional[NDArrayFloat] = None + self._table_1_kwargs: Optional[dict] = None + self._table_2_kwargs: Optional[dict] = None + self._table_3_kwargs: Optional[dict] = None self._interpolator_1: Optional[ Union[Callable, Type[TypeInterpolator]] ] = None - self._interpolator_kwargs_1: Dict = {} + self._interpolator_kwargs_1: dict = {} self._interpolator_2: Optional[ Union[Callable, Type[TypeInterpolator]] ] = None - self._interpolator_kwargs_2: Dict = {} - self._invert_kwargs_1: Dict = {} - self._invert_kwargs_2: Dict = {} + self._interpolator_kwargs_2: dict = {} + self._invert_kwargs_1: dict = {} + self._invert_kwargs_2: dict = {} self._str: Optional[str] = None self._repr: Optional[str] = None - self._inverted_apply_1: Optional[NDArray] = None - self._inverted_apply_2: Optional[NDArray] = None - self._applied_1: Optional[NDArray] = None - self._applied_2: Optional[NDArray] = None - self._applied_3: Optional[NDArray] = None - self._applied_4: Optional[NDArray] = None + self._inverted_apply_1: Optional[NDArrayFloat] = None + self._inverted_apply_2: Optional[NDArrayFloat] = None + self._applied_1: Optional[NDArrayFloat] = None + self._applied_2: Optional[NDArrayFloat] = None + self._applied_3: Optional[NDArrayFloat] = None + self._applied_4: Optional[NDArrayFloat] = None def test_required_methods(self): """Test the presence of required methods.""" @@ -813,7 +811,7 @@ def __init__(self, *args: Any) -> None: samples_2 = np.linspace(-0.1, 1.5, 15) samples_3 = np.linspace(-0.1, 3.0, 20) self._domain_1 = np.array([[0, 0, 0], [1, 1, 1]]) - self._domain_2 = np.array([[0, -0.1, -0.2], [1, 1.5, 3.0]]) + self._domain_2 = np.array([[0.0, -0.1, -0.2], [1.0, 1.5, 3.0]]) self._domain_3 = tstack( [ np.hstack([samples_1, np.full(10, np.nan)]), @@ -985,7 +983,7 @@ def __init__(self, *args: Any) -> None: samples_2 = np.linspace(-0.1, 1.5, 15) samples_3 = np.linspace(-0.1, 3.0, 20) self._domain_1 = np.array([[0, 0, 0], [1, 1, 1]]) - self._domain_2 = np.array([[0, -0.1, -0.2], [1, 1.5, 3.0]]) + self._domain_2 = np.array([[0.0, -0.1, -0.2], [1.0, 1.5, 3.0]]) self._domain_3 = tstack( [ np.hstack([samples_1, np.full(10, np.nan)]), diff --git a/colour/io/luts/tests/test_sequence.py b/colour/io/luts/tests/test_sequence.py index 5b82b52758..f3d3268c57 100644 --- a/colour/io/luts/tests/test_sequence.py +++ b/colour/io/luts/tests/test_sequence.py @@ -14,7 +14,7 @@ LUT3D, LUTSequence, ) -from colour.hints import Any, ArrayLike, FloatingOrNDArray, NDArray +from colour.hints import Any, ArrayLike, NDArrayFloat from colour.models import gamma_function from colour.utilities import as_float_array, tstack @@ -415,12 +415,12 @@ class GammaOperator(AbstractLUTSequenceOperator): Gamma value. """ - def __init__(self, gamma: FloatingOrNDArray = 1) -> None: - self._gamma = gamma + def __init__(self, gamma: ArrayLike = 1) -> None: + self._gamma = as_float_array(gamma) def apply( self, RGB: ArrayLike, *args: Any, **kwargs: Any - ) -> NDArray: + ) -> NDArrayFloat: """ Apply the *LUT* sequence operator to given *RGB* colourspace array. @@ -440,7 +440,9 @@ def apply( direction = kwargs.get("direction", "Forward") gamma = ( - self._gamma if direction == "Forward" else 1 / self._gamma + self._gamma + if direction == "Forward" + else 1.0 / self._gamma ) return as_float_array(gamma_function(RGB, gamma)) diff --git a/colour/io/ocio.py b/colour/io/ocio.py index 76e322d5f4..9564e34437 100644 --- a/colour/io/ocio.py +++ b/colour/io/ocio.py @@ -12,8 +12,8 @@ import numpy as np from colour.io import as_3_channels_image -from colour.hints import Any, ArrayLike, FloatingOrNDArray -from colour.utilities import as_float_array, as_float_scalar, required +from colour.hints import Any, ArrayLike, NDArrayFloat +from colour.utilities import as_float_array, as_float, required __author__ = "Colour Developers" __copyright__ = "Copyright 2013 Colour Developers" @@ -34,7 +34,7 @@ @required("OpenColorIO") def process_image_OpenColorIO( a: ArrayLike, *args: Any, **kwargs: Any -) -> FloatingOrNDArray: # pragma: no cover +) -> NDArrayFloat: # pragma: no cover """ Process given image data with *OpenColorIO*. @@ -155,7 +155,7 @@ def process_image_OpenColorIO( b = image_desc.getData().reshape([height, width, channels]).astype(dtype) if len(shape) == 0: - return as_float_scalar(np.squeeze(b)[0]) + return as_float(np.squeeze(b)[0]) elif shape[-1] == 1: return np.reshape(b[..., 0], shape) else: diff --git a/colour/io/tabular.py b/colour/io/tabular.py index 301dc3f316..548fbf7eba 100644 --- a/colour/io/tabular.py +++ b/colour/io/tabular.py @@ -18,7 +18,7 @@ from colour.colorimetry import SpectralDistribution from colour.constants import DEFAULT_FLOAT_DTYPE -from colour.hints import Any, Boolean, Dict, NDArray, cast +from colour.hints import Any, NDArrayFloat, cast from colour.utilities import filter_kwargs __author__ = "Colour Developers" @@ -37,7 +37,7 @@ def read_spectral_data_from_csv_file( path: str, **kwargs: Any -) -> Dict[str, NDArray]: +) -> dict[str, NDArrayFloat]: """ Read the spectral data from given *CSV* file in the following form:: @@ -146,12 +146,12 @@ def read_spectral_data_from_csv_file( if transpose: os.unlink(transposed_csv_file.name) - return {name: data[name] for name in data.dtype.names} + return {name: data[name] for name in data.dtype.names} # pyright: ignore def read_sds_from_csv_file( path: str, **kwargs: Any -) -> Dict[str, SpectralDistribution]: +) -> dict[str, SpectralDistribution]: """ Read the spectral data from given *CSV* file and returns its content as a *dict* of :class:`colour.SpectralDistribution` class instances. @@ -169,7 +169,7 @@ def read_sds_from_csv_file( Returns ------- :class:`dict` - *Dict* of :class:`colour.SpectralDistribution` class instances. + *dict* of :class:`colour.SpectralDistribution` class instances. Examples -------- @@ -291,8 +291,8 @@ def read_sds_from_csv_file( def write_sds_to_csv_file( - sds: Dict[str, SpectralDistribution], path: str -) -> Boolean: + sds: dict[str, SpectralDistribution], path: str +) -> bool: """ Write the given spectral distributions to given *CSV* file. diff --git a/colour/io/tests/test_tabular.py b/colour/io/tests/test_tabular.py index 934340cd68..43c00023e0 100644 --- a/colour/io/tests/test_tabular.py +++ b/colour/io/tests/test_tabular.py @@ -9,7 +9,6 @@ import tempfile from colour.colorimetry import SpectralDistribution, SpectralShape -from colour.hints import Dict from colour.io import ( read_spectral_data_from_csv_file, read_sds_from_csv_file, @@ -33,7 +32,7 @@ ROOT_RESOURCES: str = os.path.join(os.path.dirname(__file__), "resources") -COLOURCHECKER_N_OHTA_1: Dict = { +COLOURCHECKER_N_OHTA_1: dict = { 380.0: 0.048, 385.0: 0.051, 390.0: 0.055, diff --git a/colour/io/tests/test_tm2714.py b/colour/io/tests/test_tm2714.py index ef268c7325..c11303d2cd 100644 --- a/colour/io/tests/test_tm2714.py +++ b/colour/io/tests/test_tm2714.py @@ -13,7 +13,7 @@ from copy import deepcopy from colour.colorimetry import SpectralDistribution -from colour.hints import Dict, List, Optional, Tuple, Union, cast +from colour.hints import Optional, Union, cast from colour.io.tm2714 import Header_IESTM2714, SpectralDistribution_IESTM2714 from colour.utilities import optional @@ -35,7 +35,7 @@ ROOT_RESOURCES: str = os.path.join(os.path.dirname(__file__), "resources") -FLUORESCENT_FILE_HEADER: Dict = { +FLUORESCENT_FILE_HEADER: dict = { "Manufacturer": "Unknown", "CatalogNumber": "N/A", "Description": "Rare earth fluorescent lamp", @@ -48,13 +48,13 @@ "Comments": "Ambient temperature 25 degrees C.", } -FLUORESCENT_FILE_SPECTRAL_DESCRIPTION: Dict = { +FLUORESCENT_FILE_SPECTRAL_DESCRIPTION: dict = { "SpectralQuantity": "relative", "BandwidthFWHM": 2.0, "BandwidthCorrected": True, } -FLUORESCENT_FILE_SPECTRAL_DATA: Dict = { +FLUORESCENT_FILE_SPECTRAL_DATA: dict = { 400.0: 0.034, 403.1: 0.037, 405.5: 0.069, @@ -597,9 +597,9 @@ def test_read(self, sd: Optional[SpectralDistribution] = None): np.testing.assert_array_equal(sd_r.domain, sd.domain) np.testing.assert_array_almost_equal(sd_r.values, sd.values, decimal=7) - test_read: List[ - Tuple[ - Dict, Union[Header_IESTM2714, SpectralDistribution_IESTM2714] + test_read: list[ + tuple[ + dict, Union[Header_IESTM2714, SpectralDistribution_IESTM2714] ] ] = [ (FLUORESCENT_FILE_HEADER, sd.header), diff --git a/colour/io/tests/test_uprtek_sekonic.py b/colour/io/tests/test_uprtek_sekonic.py index c9f23afed0..956e4c1be1 100644 --- a/colour/io/tests/test_uprtek_sekonic.py +++ b/colour/io/tests/test_uprtek_sekonic.py @@ -8,7 +8,7 @@ import unittest from colour.colorimetry import SpectralDistribution -from colour.hints import Any, Dict, Optional +from colour.hints import Any, Optional from colour.io import ( SpectralDistribution_UPRTek, SpectralDistribution_Sekonic, @@ -51,7 +51,7 @@ def __init__(self, *args: Any) -> None: self._sd_factory: Any = None self._path: Optional[str] = None - self._spectral_data: Optional[Dict] = None + self._spectral_data: Optional[dict] = None self._prefix: Optional[str] = None def test_required_attributes(self): diff --git a/colour/io/tests/test_xrite.py b/colour/io/tests/test_xrite.py index 8a6f2df5dd..8581b72038 100644 --- a/colour/io/tests/test_xrite.py +++ b/colour/io/tests/test_xrite.py @@ -7,7 +7,6 @@ import unittest from colour.colorimetry import SpectralDistribution -from colour.hints import Dict from colour.io import read_sds_from_xrite_file __author__ = "Colour Developers" @@ -25,7 +24,7 @@ ROOT_RESOURCES: str = os.path.join(os.path.dirname(__file__), "resources") -COLOURCHECKER_XRITE_1: Dict = { +COLOURCHECKER_XRITE_1: dict = { 380.0: 0.0069, 390.0: 0.0069, 400.0: 0.0068, diff --git a/colour/io/tm2714.py b/colour/io/tm2714.py index 3866f7c725..6a783bd9ef 100644 --- a/colour/io/tm2714.py +++ b/colour/io/tm2714.py @@ -25,10 +25,7 @@ from colour.hints import ( Any, ArrayLike, - Boolean, Callable, - Floating, - Integer, Literal, Optional, cast, @@ -90,7 +87,7 @@ class Element_Specification_IESTM2714: element: str attribute: str type_: Any = field(default_factory=str) - required: Boolean = field(default_factory=lambda: False) + required: bool = field(default_factory=lambda: False) read_conversion: Callable = field( default_factory=lambda: lambda x: None if x == "None" else str(x) ) @@ -686,13 +683,13 @@ def __repr__(self) -> str: ], ) - def __hash__(self) -> Integer: + def __hash__(self) -> int: """ Return the header hash. Returns ------- - :class:`numpy.integer` + :class:`int` Object hash. """ @@ -712,7 +709,7 @@ def __hash__(self) -> Integer: ) ) - def __eq__(self, other: Any) -> Boolean: + def __eq__(self, other: Any) -> bool: """ Return whether the header is equal to given other object. @@ -753,7 +750,7 @@ def __eq__(self, other: Any) -> Boolean: ) return False - def __ne__(self, other: Any) -> Boolean: + def __ne__(self, other: Any) -> bool: """ Return whether the header is not equal to given other object. @@ -930,8 +927,8 @@ def __init__( transmission_geometry: Optional[ Literal["0:0", "di:0", "de:0", "0:di", "0:de", "d:d", "other"] ] = None, - bandwidth_FWHM: Optional[Floating] = None, - bandwidth_corrected: Optional[Boolean] = None, + bandwidth_FWHM: Optional[float] = None, + bandwidth_corrected: Optional[bool] = None, **kwargs, ) -> None: @@ -1018,9 +1015,9 @@ def __init__( Literal["0:0", "di:0", "de:0", "0:di", "0:de", "d:d", "other"] ] = None self.transmission_geometry = transmission_geometry - self._bandwidth_FWHM: Optional[Floating] = None + self._bandwidth_FWHM: Optional[float] = None self.bandwidth_FWHM = bandwidth_FWHM - self._bandwidth_corrected: Optional[Boolean] = None + self._bandwidth_corrected: Optional[bool] = None self.bandwidth_corrected = bandwidth_corrected @property @@ -1265,7 +1262,7 @@ def transmission_geometry( self._transmission_geometry = value @property - def bandwidth_FWHM(self) -> Optional[Floating]: + def bandwidth_FWHM(self) -> Optional[float]: """ Getter and setter property for the full-width half-maximum bandwidth. @@ -1276,14 +1273,14 @@ def bandwidth_FWHM(self) -> Optional[Floating]: Returns ------- - :py:data:`None` or :class:`numpy.floating` + :py:data:`None` or :class:`float` Full-width half-maximum bandwidth. """ return self._bandwidth_FWHM @bandwidth_FWHM.setter - def bandwidth_FWHM(self, value: Optional[Floating]): + def bandwidth_FWHM(self, value: Optional[float]): """Setter for the **self.bandwidth_FWHM** property.""" if value is not None: @@ -1297,7 +1294,7 @@ def bandwidth_FWHM(self, value: Optional[Floating]): self._bandwidth_FWHM = value @property - def bandwidth_corrected(self) -> Optional[Boolean]: + def bandwidth_corrected(self) -> Optional[bool]: """ Getter and setter property for whether bandwidth correction has been applied to the measured data. @@ -1316,7 +1313,7 @@ def bandwidth_corrected(self) -> Optional[Boolean]: return self._bandwidth_corrected @bandwidth_corrected.setter - def bandwidth_corrected(self, value: Optional[Boolean]): + def bandwidth_corrected(self, value: Optional[bool]): """Setter for the **self.bandwidth_corrected** property.""" if value is not None: @@ -1710,7 +1707,7 @@ def read(self) -> SpectralDistribution_IESTM2714: iterator = root.iter for header_element in (self.header, self): - mapping = header_element.mapping # type: ignore[attr-defined] + mapping = header_element.mapping for specification in mapping.elements: element = root.find( formatter.format( @@ -1757,7 +1754,7 @@ def read(self) -> SpectralDistribution_IESTM2714: 'The "IES TM-27-14" spectral distribution path is undefined!' ) - def write(self) -> Boolean: + def write(self) -> bool: """ Write the spectral distribution spectral data to *XML* file path. @@ -1791,7 +1788,7 @@ def write(self) -> Boolean: spectral_distribution = ElementTree.Element("") for header_element in (self.header, self): - mapping = header_element.mapping # type: ignore[attr-defined] + mapping = header_element.mapping element = ElementTree.SubElement(root, mapping.element) for specification in mapping.elements: element_child = ElementTree.SubElement( diff --git a/colour/io/uprtek_sekonic.py b/colour/io/uprtek_sekonic.py index adbec40d84..6032e11868 100644 --- a/colour/io/uprtek_sekonic.py +++ b/colour/io/uprtek_sekonic.py @@ -18,7 +18,7 @@ from collections import defaultdict from colour.io import SpectralDistribution_IESTM2714 -from colour.hints import Any, Dict, List, cast +from colour.hints import Any, cast from colour.utilities import as_float_array __author__ = "Colour Developers" @@ -163,10 +163,10 @@ def __init__(self, path: str, **kwargs: Any) -> None: self._spectral_section: str = "380" self._spectral_data_pattern: str = "(\\d{3})nm" - self._metadata: Dict = {} + self._metadata: dict = {} @property - def metadata(self) -> Dict: + def metadata(self) -> dict: """ Getter property for the metadata. @@ -369,7 +369,7 @@ def read(self) -> SpectralDistribution_UPRTek: path = cast(str, self.path) - def as_array(a: Any) -> List: + def as_array(a: Any) -> list: """ Input list of numbers and converts each element to float data type. @@ -403,8 +403,8 @@ def as_array(a: Any) -> List: for method in (int, float, as_array): try: self._metadata[attribute] = method( - value - ) # type: ignore[operator] + value # pyright: ignore + ) break except Exception: self._metadata[attribute] = value diff --git a/colour/io/xrite.py b/colour/io/xrite.py index 15217f2c19..b0713d6cb6 100644 --- a/colour/io/xrite.py +++ b/colour/io/xrite.py @@ -13,7 +13,6 @@ import re from colour.colorimetry import SpectralDistribution -from colour.hints import Dict __author__ = "Colour Developers" __copyright__ = "Copyright 2013 Colour Developers" @@ -30,7 +29,7 @@ XRITE_FILE_ENCODING: str = "utf-8" -def read_sds_from_xrite_file(path: str) -> Dict[str, SpectralDistribution]: +def read_sds_from_xrite_file(path: str) -> dict[str, SpectralDistribution]: """ Read the spectral data from given *X-Rite* file and returns it as a *dict* of :class:`colour.SpectralDistribution` class instances. @@ -43,7 +42,7 @@ def read_sds_from_xrite_file(path: str) -> Dict[str, SpectralDistribution]: Returns ------- :class:`dict` - *Dict* of :class:`colour.SpectralDistribution` class instances. + *dict* of :class:`colour.SpectralDistribution` class instances. Notes ----- @@ -67,6 +66,7 @@ def read_sds_from_xrite_file(path: str) -> Dict[str, SpectralDistribution]: with codecs.open(path, encoding=XRITE_FILE_ENCODING) as xrite_file: lines = xrite_file.read().strip().split("\n") + index = 0 xrite_sds = {} is_spectral_data_format, is_spectral_data = False, False for line in lines: diff --git a/colour/models/__init__.py b/colour/models/__init__.py index a7d96fdfcc..b463565ecd 100644 --- a/colour/models/__init__.py +++ b/colour/models/__init__.py @@ -883,7 +883,7 @@ def __getattr__(self, attribute) -> Any: """Defines the *colour.models* sub-package API changes.""" if not is_documentation_building(): - sys.modules["colour.models"] = models( # type: ignore[assignment] + sys.modules["colour.models"] = models( # pyright: ignore sys.modules["colour.models"], build_API_changes(API_CHANGES) ) diff --git a/colour/models/cam02_ucs.py b/colour/models/cam02_ucs.py index 32f7548098..84cabcbc6c 100644 --- a/colour/models/cam02_ucs.py +++ b/colour/models/cam02_ucs.py @@ -31,7 +31,7 @@ from collections import namedtuple from colour.algebra import cartesian_to_polar, polar_to_cartesian -from colour.hints import Any, ArrayLike, FloatingOrNDArray, NDArray, cast +from colour.hints import Any, ArrayLike, NDArrayFloat, cast from colour.utilities import ( CanonicalMapping, as_float_array, @@ -97,7 +97,7 @@ class Coefficients_UCS_Luo2006( def JMh_CIECAM02_to_UCS_Luo2006( JMh: ArrayLike, coefficients: ArrayLike -) -> NDArray: +) -> NDArrayFloat: """ Convert from *CIECAM02* :math:`JMh` correlates array to one of the *Luo et al. (2006)* *CAM02-LCD*, *CAM02-SCD*, or *CAM02-UCS* colourspaces @@ -181,7 +181,7 @@ def JMh_CIECAM02_to_UCS_Luo2006( def UCS_Luo2006_to_JMh_CIECAM02( Jpapbp: ArrayLike, coefficients: ArrayLike -) -> NDArray: +) -> NDArrayFloat: """ Convert from one of the *Luo et al. (2006)* *CAM02-LCD*, *CAM02-SCD*, or *CAM02-UCS* colourspaces :math:`J'a'b'` array to *CIECAM02* :math:`JMh` @@ -253,7 +253,7 @@ def UCS_Luo2006_to_JMh_CIECAM02( return JMh -def JMh_CIECAM02_to_CAM02LCD(JMh: ArrayLike) -> NDArray: +def JMh_CIECAM02_to_CAM02LCD(JMh: ArrayLike) -> NDArrayFloat: """ Convert from *CIECAM02* :math:`JMh` correlates array to *Luo et al. (2006)* *CAM02-LCD* colourspace :math:`J'a'b'` array. @@ -318,7 +318,7 @@ def JMh_CIECAM02_to_CAM02LCD(JMh: ArrayLike) -> NDArray: ) -def CAM02LCD_to_JMh_CIECAM02(Jpapbp: ArrayLike) -> NDArray: +def CAM02LCD_to_JMh_CIECAM02(Jpapbp: ArrayLike) -> NDArrayFloat: """ Convert from *Luo et al. (2006)* *CAM02-LCD* colourspace :math:`J'a'b'` array to *CIECAM02* :math:`JMh` correlates array. @@ -373,7 +373,7 @@ def CAM02LCD_to_JMh_CIECAM02(Jpapbp: ArrayLike) -> NDArray: ) -def JMh_CIECAM02_to_CAM02SCD(JMh: ArrayLike) -> NDArray: +def JMh_CIECAM02_to_CAM02SCD(JMh: ArrayLike) -> NDArrayFloat: """ Convert from *CIECAM02* :math:`JMh` correlates array to *Luo et al. (2006)* *CAM02-SCD* colourspace :math:`J'a'b'` array. @@ -438,7 +438,7 @@ def JMh_CIECAM02_to_CAM02SCD(JMh: ArrayLike) -> NDArray: ) -def CAM02SCD_to_JMh_CIECAM02(Jpapbp: ArrayLike) -> NDArray: +def CAM02SCD_to_JMh_CIECAM02(Jpapbp: ArrayLike) -> NDArrayFloat: """ Convert from *Luo et al. (2006)* *CAM02-SCD* colourspace :math:`J'a'b'` array to *CIECAM02* :math:`JMh` correlates array. @@ -493,7 +493,7 @@ def CAM02SCD_to_JMh_CIECAM02(Jpapbp: ArrayLike) -> NDArray: ) -def JMh_CIECAM02_to_CAM02UCS(JMh: ArrayLike) -> NDArray: +def JMh_CIECAM02_to_CAM02UCS(JMh: ArrayLike) -> NDArrayFloat: """ Convert from *CIECAM02* :math:`JMh` correlates array to *Luo et al. (2006)* *CAM02-UCS* colourspace :math:`J'a'b'` array. @@ -558,7 +558,7 @@ def JMh_CIECAM02_to_CAM02UCS(JMh: ArrayLike) -> NDArray: ) -def CAM02UCS_to_JMh_CIECAM02(Jpapbp: ArrayLike) -> NDArray: +def CAM02UCS_to_JMh_CIECAM02(Jpapbp: ArrayLike) -> NDArrayFloat: """ Convert from *Luo et al. (2006)* *CAM02-UCS* colourspace :math:`J'a'b'` array to *CIECAM02* :math:`JMh` correlates array. @@ -615,7 +615,7 @@ def CAM02UCS_to_JMh_CIECAM02(Jpapbp: ArrayLike) -> NDArray: def XYZ_to_UCS_Luo2006( XYZ: ArrayLike, coefficients: ArrayLike, **kwargs: Any -) -> NDArray: +) -> NDArrayFloat: """ Convert from *CIE XYZ* tristimulus values to one of the *Luo et al. (2006)* *CAM02-LCD*, *CAM02-SCD*, or *CAM02-UCS* colourspaces @@ -691,9 +691,9 @@ def XYZ_to_UCS_Luo2006( specification = XYZ_to_CIECAM02(XYZ, **settings) JMh = tstack( [ - cast(FloatingOrNDArray, specification.J), - cast(FloatingOrNDArray, specification.M), - cast(FloatingOrNDArray, specification.h), + cast(NDArrayFloat, specification.J), + cast(NDArrayFloat, specification.M), + cast(NDArrayFloat, specification.h), ] ) @@ -702,7 +702,7 @@ def XYZ_to_UCS_Luo2006( def UCS_Luo2006_to_XYZ( Jpapbp: ArrayLike, coefficients: ArrayLike, **kwargs: Any -) -> NDArray: +) -> NDArrayFloat: """ Convert from one of the *Luo et al. (2006)* *CAM02-LCD*, *CAM02-SCD*, or *CAM02-UCS* colourspaces :math:`J'a'b'` array to *CIE XYZ* tristimulus @@ -789,7 +789,7 @@ def UCS_Luo2006_to_XYZ( return XYZ -def XYZ_to_CAM02LCD(XYZ: ArrayLike, **kwargs: Any) -> NDArray: +def XYZ_to_CAM02LCD(XYZ: ArrayLike, **kwargs: Any) -> NDArrayFloat: """ Convert from *CIE XYZ* tristimulus values to *Luo et al. (2006)* *CAM02-LCD* colourspace :math:`J'a'b'` array. @@ -854,7 +854,7 @@ def XYZ_to_CAM02LCD(XYZ: ArrayLike, **kwargs: Any) -> NDArray: ) -def CAM02LCD_to_XYZ(Jpapbp: ArrayLike, **kwargs: Any) -> NDArray: +def CAM02LCD_to_XYZ(Jpapbp: ArrayLike, **kwargs: Any) -> NDArrayFloat: """ Convert from *Luo et al. (2006)* *CAM02-LCD* colourspace :math:`J'a'b'` array to *CIE XYZ* tristimulus values. @@ -919,7 +919,7 @@ def CAM02LCD_to_XYZ(Jpapbp: ArrayLike, **kwargs: Any) -> NDArray: ) -def XYZ_to_CAM02SCD(XYZ: ArrayLike, **kwargs: Any) -> NDArray: +def XYZ_to_CAM02SCD(XYZ: ArrayLike, **kwargs: Any) -> NDArrayFloat: """ Convert from *CIE XYZ* tristimulus values to *Luo et al. (2006)* *CAM02-SCD* colourspace :math:`J'a'b'` array. @@ -984,7 +984,7 @@ def XYZ_to_CAM02SCD(XYZ: ArrayLike, **kwargs: Any) -> NDArray: ) -def CAM02SCD_to_XYZ(Jpapbp: ArrayLike, **kwargs: Any) -> NDArray: +def CAM02SCD_to_XYZ(Jpapbp: ArrayLike, **kwargs: Any) -> NDArrayFloat: """ Convert from *Luo et al. (2006)* *CAM02-SCD* colourspace :math:`J'a'b'` array to *CIE XYZ* tristimulus values. @@ -1049,7 +1049,7 @@ def CAM02SCD_to_XYZ(Jpapbp: ArrayLike, **kwargs: Any) -> NDArray: ) -def XYZ_to_CAM02UCS(XYZ: ArrayLike, **kwargs: Any) -> NDArray: +def XYZ_to_CAM02UCS(XYZ: ArrayLike, **kwargs: Any) -> NDArrayFloat: """ Convert from *CIE XYZ* tristimulus values to *Luo et al. (2006)* *CAM02-UCS* colourspace :math:`J'a'b'` array. @@ -1114,7 +1114,7 @@ def XYZ_to_CAM02UCS(XYZ: ArrayLike, **kwargs: Any) -> NDArray: ) -def CAM02UCS_to_XYZ(Jpapbp: ArrayLike, **kwargs: Any) -> NDArray: +def CAM02UCS_to_XYZ(Jpapbp: ArrayLike, **kwargs: Any) -> NDArrayFloat: """ Convert from *Luo et al. (2006)* *CAM02-UCS* colourspace :math:`J'a'b'` array to *CIE XYZ* tristimulus values. diff --git a/colour/models/cam16_ucs.py b/colour/models/cam16_ucs.py index bc31840526..114a33d60b 100644 --- a/colour/models/cam16_ucs.py +++ b/colour/models/cam16_ucs.py @@ -35,8 +35,7 @@ Callable, Any, ArrayLike, - FloatingOrNDArray, - NDArray, + NDArrayFloat, cast, ) from colour.models.cam02_ucs import ( @@ -183,7 +182,7 @@ def _UCS_Luo2006_callable_to_UCS_Li2017_docstring(callable_: Callable) -> str: def XYZ_to_UCS_Li2017( XYZ: ArrayLike, coefficients: ArrayLike, **kwargs: Any -) -> NDArray: +) -> NDArrayFloat: """ Convert from *CIE XYZ* tristimulus values to one of the *Li et al. (2017)* *CAM16-LCD*, *CAM16-SCD*, or *CAM16-UCS* colourspaces :math:`J'a'b'` array. @@ -267,9 +266,9 @@ def XYZ_to_UCS_Li2017( specification = XYZ_to_CAM16(XYZ, **settings) JMh = tstack( [ - cast(FloatingOrNDArray, specification.J), - cast(FloatingOrNDArray, specification.M), - cast(FloatingOrNDArray, specification.h), + cast(NDArrayFloat, specification.J), + cast(NDArrayFloat, specification.M), + cast(NDArrayFloat, specification.h), ] ) @@ -278,7 +277,7 @@ def XYZ_to_UCS_Li2017( def UCS_Li2017_to_XYZ( Jpapbp: ArrayLike, coefficients: ArrayLike, **kwargs: Any -) -> NDArray: +) -> NDArrayFloat: """ Convert from one of the *Li et al. (2017)* *CAM16-LCD*, *CAM16-SCD*, or *CAM16-UCS* colourspaces :math:`J'a'b'` array to *CIE XYZ* tristimulus diff --git a/colour/models/cie_lab.py b/colour/models/cie_lab.py index 13ceaac1e1..f537ac2d6b 100644 --- a/colour/models/cie_lab.py +++ b/colour/models/cie_lab.py @@ -23,7 +23,7 @@ intermediate_lightness_function_CIE1976, intermediate_luminance_function_CIE1976, ) -from colour.hints import ArrayLike, NDArray +from colour.hints import ArrayLike, NDArrayFloat from colour.models import xy_to_xyY, xyY_to_XYZ, Jab_to_JCh, JCh_to_Jab from colour.utilities import ( from_range_1, @@ -54,7 +54,7 @@ def XYZ_to_Lab( illuminant: ArrayLike = CCS_ILLUMINANTS[ "CIE 1931 2 Degree Standard Observer" ]["D65"], -) -> NDArray: +) -> NDArrayFloat: """ Convert from *CIE XYZ* tristimulus values to *CIE L\\*a\\*b\\** colourspace. @@ -125,7 +125,7 @@ def Lab_to_XYZ( illuminant: ArrayLike = CCS_ILLUMINANTS[ "CIE 1931 2 Degree Standard Observer" ]["D65"], -) -> NDArray: +) -> NDArrayFloat: """ Convert from *CIE L\\*a\\*b\\** colourspace to *CIE XYZ* tristimulus values. @@ -192,7 +192,7 @@ def Lab_to_XYZ( return from_range_1(XYZ) -def Lab_to_LCHab(Lab: ArrayLike) -> NDArray: +def Lab_to_LCHab(Lab: ArrayLike) -> NDArrayFloat: """ Convert from *CIE L\\*a\\*b\\** colourspace to *CIE L\\*C\\*Hab* colourspace. @@ -244,7 +244,7 @@ def Lab_to_LCHab(Lab: ArrayLike) -> NDArray: return Jab_to_JCh(Lab) -def LCHab_to_Lab(LCHab: ArrayLike) -> NDArray: +def LCHab_to_Lab(LCHab: ArrayLike) -> NDArrayFloat: """ Convert from *CIE L\\*C\\*Hab* colourspace to *CIE L\\*a\\*b\\** colourspace. diff --git a/colour/models/cie_luv.py b/colour/models/cie_luv.py index 2e0f19d0eb..e39f406833 100644 --- a/colour/models/cie_luv.py +++ b/colour/models/cie_luv.py @@ -36,7 +36,7 @@ lightness_CIE1976, luminance_CIE1976, ) -from colour.hints import ArrayLike, Floating, NDArray +from colour.hints import ArrayLike, NDArrayFloat from colour.models import xy_to_xyY, xyY_to_XYZ, Jab_to_JCh, JCh_to_Jab from colour.utilities import ( domain_range_scale, @@ -74,7 +74,7 @@ def XYZ_to_Luv( illuminant: ArrayLike = CCS_ILLUMINANTS[ "CIE 1931 2 Degree Standard Observer" ]["D65"], -) -> NDArray: +) -> NDArrayFloat: """ Convert from *CIE XYZ* tristimulus values to *CIE L\\*u\\*v\\** colourspace. @@ -148,7 +148,7 @@ def Luv_to_XYZ( illuminant: ArrayLike = CCS_ILLUMINANTS[ "CIE 1931 2 Degree Standard Observer" ]["D65"], -) -> NDArray: +) -> NDArrayFloat: """ Convert from *CIE L\\*u\\*v\\** colourspace to *CIE XYZ* tristimulus values. @@ -230,7 +230,7 @@ def Luv_to_uv( illuminant: ArrayLike = CCS_ILLUMINANTS[ "CIE 1931 2 Degree Standard Observer" ]["D65"], -) -> NDArray: +) -> NDArrayFloat: """ Return the :math:`uv^p` chromaticity coordinates from given *CIE L\\*u\\*v\\** colourspace array. @@ -291,8 +291,8 @@ def uv_to_Luv( illuminant: ArrayLike = CCS_ILLUMINANTS[ "CIE 1931 2 Degree Standard Observer" ]["D65"], - Y: Floating = 1, -) -> NDArray: + Y: float = 1, +) -> NDArrayFloat: """ Return the *CIE L\\*u\\*v\\** colourspace array from given :math:`uv^p` chromaticity coordinates by extending the array last dimension with given @@ -353,7 +353,7 @@ def uv_to_Luv( return XYZ_to_Luv(from_range_1(XYZ), illuminant) -def Luv_uv_to_xy(uv: ArrayLike) -> NDArray: +def Luv_uv_to_xy(uv: ArrayLike) -> NDArrayFloat: """ Return the *CIE xy* chromaticity coordinates from given *CIE L\\*u\\*v\\** colourspace :math:`uv^p` chromaticity coordinates. @@ -388,7 +388,7 @@ def Luv_uv_to_xy(uv: ArrayLike) -> NDArray: return xy -def xy_to_Luv_uv(xy: ArrayLike) -> NDArray: +def xy_to_Luv_uv(xy: ArrayLike) -> NDArrayFloat: """ Return the *CIE L\\*u\\*v\\** colourspace :math:`uv^p` chromaticity coordinates from given *CIE xy* chromaticity coordinates. @@ -423,7 +423,7 @@ def xy_to_Luv_uv(xy: ArrayLike) -> NDArray: return uv -def Luv_to_LCHuv(Luv: ArrayLike) -> NDArray: +def Luv_to_LCHuv(Luv: ArrayLike) -> NDArrayFloat: """ Convert from *CIE L\\*u\\*v\\** colourspace to *CIE L\\*C\\*Huv* colourspace. @@ -475,7 +475,7 @@ def Luv_to_LCHuv(Luv: ArrayLike) -> NDArray: return Jab_to_JCh(Luv) -def LCHuv_to_Luv(LCHuv: ArrayLike) -> NDArray: +def LCHuv_to_Luv(LCHuv: ArrayLike) -> NDArrayFloat: """ Convert from *CIE L\\*C\\*Huv* colourspace to *CIE L\\*u\\*v\\** colourspace. diff --git a/colour/models/cie_ucs.py b/colour/models/cie_ucs.py index 1b8b3de26b..ae9cf0f0ea 100644 --- a/colour/models/cie_ucs.py +++ b/colour/models/cie_ucs.py @@ -23,7 +23,7 @@ from __future__ import annotations from colour.algebra import sdiv, sdiv_mode -from colour.hints import ArrayLike, Floating, NDArray +from colour.hints import ArrayLike, NDArrayFloat from colour.utilities import ( as_float_scalar, from_range_1, @@ -50,7 +50,7 @@ ] -def XYZ_to_UCS(XYZ: ArrayLike) -> NDArray: +def XYZ_to_UCS(XYZ: ArrayLike) -> NDArrayFloat: """ Convert from *CIE XYZ* tristimulus values to *CIE 1960 UCS* colourspace. @@ -97,7 +97,7 @@ def XYZ_to_UCS(XYZ: ArrayLike) -> NDArray: return from_range_1(UVW) -def UCS_to_XYZ(UVW: ArrayLike) -> NDArray: +def UCS_to_XYZ(UVW: ArrayLike) -> NDArrayFloat: """ Convert from *CIE 1960 UCS* colourspace to *CIE XYZ* tristimulus values. @@ -144,7 +144,7 @@ def UCS_to_XYZ(UVW: ArrayLike) -> NDArray: return from_range_1(XYZ) -def UCS_to_uv(UVW: ArrayLike) -> NDArray: +def UCS_to_uv(UVW: ArrayLike) -> NDArrayFloat: """ Return the *uv* chromaticity coordinates from given *CIE 1960 UCS* colourspace array. @@ -189,7 +189,7 @@ def UCS_to_uv(UVW: ArrayLike) -> NDArray: return uv -def uv_to_UCS(uv: ArrayLike, V: Floating = 1) -> NDArray: +def uv_to_UCS(uv: ArrayLike, V: float = 1) -> NDArrayFloat: """ Return the *CIE 1960 UCS* colourspace array from given *uv* chromaticity coordinates. @@ -231,7 +231,7 @@ def uv_to_UCS(uv: ArrayLike, V: Floating = 1) -> NDArray: return from_range_1(UVW) -def UCS_uv_to_xy(uv: ArrayLike) -> NDArray: +def UCS_uv_to_xy(uv: ArrayLike) -> NDArrayFloat: """ Return the *CIE xy* chromaticity coordinates from given *CIE 1960 UCS* colourspace *uv* chromaticity coordinates. @@ -266,7 +266,7 @@ def UCS_uv_to_xy(uv: ArrayLike) -> NDArray: return xy -def xy_to_UCS_uv(xy: ArrayLike) -> NDArray: +def xy_to_UCS_uv(xy: ArrayLike) -> NDArrayFloat: """ Return the *CIE 1960 UCS* colourspace *uv* chromaticity coordinates from given *CIE xy* chromaticity coordinates. diff --git a/colour/models/cie_uvw.py b/colour/models/cie_uvw.py index b05cf4e05c..fa8df6bcb7 100644 --- a/colour/models/cie_uvw.py +++ b/colour/models/cie_uvw.py @@ -18,7 +18,7 @@ from colour.algebra import sdiv, sdiv_mode, spow from colour.colorimetry import CCS_ILLUMINANTS -from colour.hints import ArrayLike, NDArray, cast +from colour.hints import ArrayLike, NDArrayFloat from colour.models import ( UCS_uv_to_xy, XYZ_to_xy, @@ -46,7 +46,7 @@ def XYZ_to_UVW( illuminant: ArrayLike = CCS_ILLUMINANTS[ "CIE 1931 2 Degree Standard Observer" ]["D65"], -) -> NDArray: +) -> NDArrayFloat: """ Convert from *CIE XYZ* tristimulus values to *CIE 1964 U\\*V\\*W\\** colourspace. @@ -105,7 +105,7 @@ def XYZ_to_UVW( uv = xy_to_UCS_uv(xy) uv_0 = xy_to_UCS_uv(xy_n) - W = 25 * cast(NDArray, spow(Y, 1 / 3)) - 17 + W = 25 * spow(Y, 1 / 3) - 17 U, V = tsplit(13 * W[..., None] * (uv - uv_0)) UVW = tstack([U, V, W]) @@ -118,7 +118,7 @@ def UVW_to_XYZ( illuminant: ArrayLike = CCS_ILLUMINANTS[ "CIE 1931 2 Degree Standard Observer" ]["D65"], -) -> NDArray: +) -> NDArrayFloat: """ Convert *CIE 1964 U\\*V\\*W\\** colourspace to *CIE XYZ* tristimulus values. diff --git a/colour/models/cie_xyy.py b/colour/models/cie_xyy.py index f3bff01131..5b7b1b54b6 100644 --- a/colour/models/cie_xyy.py +++ b/colour/models/cie_xyy.py @@ -26,7 +26,7 @@ import numpy as np from colour.colorimetry import CCS_ILLUMINANTS -from colour.hints import ArrayLike, Floating, NDArray +from colour.hints import ArrayLike, NDArrayFloat from colour.utilities import ( as_float_array, as_float_scalar, @@ -60,7 +60,7 @@ def XYZ_to_xyY( illuminant: ArrayLike = CCS_ILLUMINANTS[ "CIE 1931 2 Degree Standard Observer" ]["D65"], -) -> NDArray: +) -> NDArrayFloat: """ Convert from *CIE XYZ* tristimulus values to *CIE xyY* colourspace and reference *illuminant*. @@ -126,7 +126,7 @@ def XYZ_to_xyY( return xyY -def xyY_to_XYZ(xyY: ArrayLike) -> NDArray: +def xyY_to_XYZ(xyY: ArrayLike) -> NDArrayFloat: """ Convert from *CIE xyY* colourspace to *CIE XYZ* tristimulus values. @@ -182,7 +182,7 @@ def xyY_to_XYZ(xyY: ArrayLike) -> NDArray: return from_range_1(XYZ) -def xyY_to_xy(xyY: ArrayLike) -> NDArray: +def xyY_to_xy(xyY: ArrayLike) -> NDArrayFloat: """ Convert from *CIE xyY* colourspace to *CIE xy* chromaticity coordinates. @@ -234,7 +234,7 @@ def xyY_to_xy(xyY: ArrayLike) -> NDArray: return xy -def xy_to_xyY(xy: ArrayLike, Y: Floating = 1) -> NDArray: +def xy_to_xyY(xy: ArrayLike, Y: float = 1) -> NDArrayFloat: """ Convert from *CIE xy* chromaticity coordinates to *CIE xyY* colourspace by extending the array last dimension with given :math:`Y` *luminance*. @@ -312,7 +312,7 @@ def XYZ_to_xy( illuminant: ArrayLike = CCS_ILLUMINANTS[ "CIE 1931 2 Degree Standard Observer" ]["D65"], -) -> NDArray: +) -> NDArrayFloat: """ Return the *CIE xy* chromaticity coordinates from given *CIE XYZ* tristimulus values. @@ -351,7 +351,7 @@ def XYZ_to_xy( return xyY_to_xy(XYZ_to_xyY(XYZ, illuminant)) -def xy_to_XYZ(xy: ArrayLike) -> NDArray: +def xy_to_XYZ(xy: ArrayLike) -> NDArrayFloat: """ Return the *CIE XYZ* tristimulus values from given *CIE xy* chromaticity coordinates. diff --git a/colour/models/common.py b/colour/models/common.py index d657657a3a..35e18401c5 100644 --- a/colour/models/common.py +++ b/colour/models/common.py @@ -22,7 +22,7 @@ import numpy as np from colour.algebra import cartesian_to_polar, polar_to_cartesian, vector_dot -from colour.hints import ArrayLike, Callable, NDArray, Tuple +from colour.hints import ArrayLike, Callable, NDArrayFloat from colour.utilities import ( CanonicalMapping, attest, @@ -56,7 +56,7 @@ ] -COLOURSPACE_MODELS: Tuple = ( +COLOURSPACE_MODELS: tuple = ( "CAM02LCD", "CAM02SCD", "CAM02UCS", @@ -157,7 +157,7 @@ """Colourspace models domain-range scale **'1'** to **'Reference'** mapping.""" -def Jab_to_JCh(Jab: ArrayLike) -> NDArray: +def Jab_to_JCh(Jab: ArrayLike) -> NDArrayFloat: """ Convert from *Jab* colour representation to *JCh* colour representation. @@ -220,7 +220,7 @@ def Jab_to_JCh(Jab: ArrayLike) -> NDArray: return JCh -def JCh_to_Jab(JCh: ArrayLike) -> NDArray: +def JCh_to_Jab(JCh: ArrayLike) -> NDArrayFloat: """ Convert from *JCh* colour representation to *Jab* colour representation. @@ -289,7 +289,7 @@ def XYZ_to_Iab( LMS_to_LMS_p_callable: Callable, matrix_XYZ_to_LMS: ArrayLike, matrix_LMS_p_to_Iab: ArrayLike, -) -> NDArray: +) -> NDArrayFloat: """ Convert from *CIE XYZ* tristimulus values to *IPT*-like :math:`Iab` colour representation. @@ -376,7 +376,7 @@ def Iab_to_XYZ( LMS_p_to_LMS_callable: Callable, matrix_Iab_to_LMS_p: ArrayLike, matrix_LMS_to_XYZ: ArrayLike, -) -> NDArray: +) -> NDArrayFloat: """ Convert from *IPT*-like :math:`Iab` colour representation to *CIE XYZ* tristimulus values. diff --git a/colour/models/datasets/macadam_ellipses.py b/colour/models/datasets/macadam_ellipses.py index 65ca303aab..1e347a4ddd 100644 --- a/colour/models/datasets/macadam_ellipses.py +++ b/colour/models/datasets/macadam_ellipses.py @@ -20,7 +20,7 @@ import numpy as np -from colour.hints import NDArray +from colour.hints import NDArrayFloat __author__ = "Colour Developers" __copyright__ = "Copyright 2013 Colour Developers" @@ -33,7 +33,7 @@ "DATA_MACADAM_1942_ELLIPSES", ] -DATA_MACADAM_1942_ELLIPSES: NDArray = np.array( +DATA_MACADAM_1942_ELLIPSES: NDArrayFloat = np.array( [ [0.160, 0.057, 0.85, 0.35, 62.5, 0.94, 0.30, 62.3], [0.187, 0.118, 2.20, 0.55, 77.0, 2.31, 0.44, 74.8], diff --git a/colour/models/datasets/pointer_gamut.py b/colour/models/datasets/pointer_gamut.py index ac17ff37dc..7a04716b33 100644 --- a/colour/models/datasets/pointer_gamut.py +++ b/colour/models/datasets/pointer_gamut.py @@ -15,7 +15,7 @@ import numpy as np from colour.colorimetry import CCS_LIGHT_SOURCES -from colour.hints import NDArray +from colour.hints import NDArrayFloat __author__ = "Colour Developers" __copyright__ = "Copyright 2013 Colour Developers" @@ -30,7 +30,7 @@ "CCS_POINTER_GAMUT_BOUNDARY", ] -CCS_ILLUMINANT_POINTER_GAMUT: NDArray = CCS_LIGHT_SOURCES[ +CCS_ILLUMINANT_POINTER_GAMUT: NDArrayFloat = CCS_LIGHT_SOURCES[ "CIE 1931 2 Degree Standard Observer" ]["SC"] """ @@ -41,7 +41,7 @@ :cite:`Pointer1980a` """ -DATA_POINTER_GAMUT_VOLUME: NDArray = np.array( +DATA_POINTER_GAMUT_VOLUME: NDArrayFloat = np.array( [ [15, 10, 0], [15, 15, 10], @@ -629,7 +629,7 @@ :cite:`Pointer1980a` """ -CCS_POINTER_GAMUT_BOUNDARY: NDArray = np.array( +CCS_POINTER_GAMUT_BOUNDARY: NDArrayFloat = np.array( [ [0.659, 0.316], [0.634, 0.351], diff --git a/colour/models/din99.py b/colour/models/din99.py index d2b0855e07..93a71817a1 100644 --- a/colour/models/din99.py +++ b/colour/models/din99.py @@ -27,7 +27,7 @@ from colour.algebra import spow from colour.colorimetry import CCS_ILLUMINANTS -from colour.hints import ArrayLike, Floating, Literal, NDArray, Union +from colour.hints import ArrayLike, Literal, NDArrayFloat, Union from colour.models import Lab_to_XYZ, XYZ_to_Lab from colour.utilities import ( CanonicalMapping, @@ -78,12 +78,12 @@ def Lab_to_DIN99( Lab: ArrayLike, - k_E: Floating = 1, - k_CH: Floating = 1, + k_E: float = 1, + k_CH: float = 1, method: Union[ Literal["ASTMD2244-07", "DIN99", "DIN99b", "DIN99c", "DIN99d"], str ] = "DIN99", -) -> NDArray: +) -> NDArrayFloat: """ Convert from *CIE L\\*a\\*b\\** colourspace to *DIN99* colourspace or one of the *DIN99b*, *DIN99c*, *DIN99d* refined formulas according @@ -170,12 +170,12 @@ def Lab_to_DIN99( def DIN99_to_Lab( Lab_99: ArrayLike, - k_E: Floating = 1, - k_CH: Floating = 1, + k_E: float = 1, + k_CH: float = 1, method: Union[ Literal["ASTMD2244-07", "DIN99", "DIN99b", "DIN99c", "DIN99d"], str ] = "DIN99", -) -> NDArray: +) -> NDArrayFloat: """ Convert from *DIN99* colourspace or one of the *DIN99b*, *DIN99c*, *DIN99d* refined formulas according to *Cui et al. (2002)* to @@ -265,12 +265,12 @@ def XYZ_to_DIN99( illuminant: ArrayLike = CCS_ILLUMINANTS[ "CIE 1931 2 Degree Standard Observer" ]["D65"], - k_E: Floating = 1, - k_CH: Floating = 1, + k_E: float = 1, + k_CH: float = 1, method: Union[ Literal["ASTMD2244-07", "DIN99", "DIN99b", "DIN99c", "DIN99d"], str ] = "DIN99", -) -> NDArray: +) -> NDArrayFloat: """ Convert from *CIE XYZ* tristimulus values to *DIN99* colourspace or one of the *DIN99b*, *DIN99c*, *DIN99d* refined formulas according @@ -340,12 +340,12 @@ def DIN99_to_XYZ( illuminant: ArrayLike = CCS_ILLUMINANTS[ "CIE 1931 2 Degree Standard Observer" ]["D65"], - k_E: Floating = 1, - k_CH: Floating = 1, + k_E: float = 1, + k_CH: float = 1, method: Union[ Literal["ASTMD2244-07", "DIN99", "DIN99b", "DIN99c", "DIN99d"], str ] = "DIN99", -) -> NDArray: +) -> NDArrayFloat: """ Convert from *DIN99* colourspace or one of the *DIN99b*, *DIN99c*, *DIN99d* refined formulas according to *Cui et al. (2002)* to *CIE XYZ* diff --git a/colour/models/hdr_cie_lab.py b/colour/models/hdr_cie_lab.py index 26dd65b2d2..b761eba19b 100644 --- a/colour/models/hdr_cie_lab.py +++ b/colour/models/hdr_cie_lab.py @@ -34,11 +34,8 @@ ) from colour.hints import ( ArrayLike, - FloatingOrArrayLike, - FloatingOrNDArray, Literal, - NDArray, - Tuple, + NDArrayFloat, Union, ) from colour.models import xy_to_xyY, xyY_to_XYZ @@ -72,7 +69,7 @@ "hdr_CIELab_to_XYZ", ] -HDR_CIELAB_METHODS: Tuple = ("Fairchild 2010", "Fairchild 2011") +HDR_CIELAB_METHODS: tuple = ("Fairchild 2010", "Fairchild 2011") if is_documentation_building(): # pragma: no cover HDR_CIELAB_METHODS = DocstringTuple(HDR_CIELAB_METHODS) HDR_CIELAB_METHODS.__doc__ = """ @@ -85,12 +82,12 @@ def exponent_hdr_CIELab( - Y_s: FloatingOrArrayLike, - Y_abs: FloatingOrArrayLike, + Y_s: ArrayLike, + Y_abs: ArrayLike, method: Union[ Literal["Fairchild 2011", "Fairchild 2010"], str ] = "Fairchild 2011", -) -> FloatingOrNDArray: +) -> NDArrayFloat: """ Compute *hdr-CIELAB* colourspace *Lightness* :math:`\\epsilon` exponent using *Fairchild and Wyble (2010)* or *Fairchild and Chen (2011)* method. @@ -107,7 +104,7 @@ def exponent_hdr_CIELab( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` *hdr-CIELAB* colourspace *Lightness* :math:`\\epsilon` exponent. Notes @@ -151,12 +148,12 @@ def XYZ_to_hdr_CIELab( illuminant: ArrayLike = CCS_ILLUMINANTS[ "CIE 1931 2 Degree Standard Observer" ]["D65"], - Y_s: FloatingOrArrayLike = 0.2, - Y_abs: FloatingOrArrayLike = 100, + Y_s: ArrayLike = 0.2, + Y_abs: ArrayLike = 100, method: Union[ Literal["Fairchild 2011", "Fairchild 2010"], str ] = "Fairchild 2011", -) -> NDArray: +) -> NDArrayFloat: """ Convert from *CIE XYZ* tristimulus values to *hdr-CIELAB* colourspace. @@ -251,12 +248,12 @@ def hdr_CIELab_to_XYZ( illuminant: ArrayLike = CCS_ILLUMINANTS[ "CIE 1931 2 Degree Standard Observer" ]["D65"], - Y_s: FloatingOrArrayLike = 0.2, - Y_abs: FloatingOrArrayLike = 100, + Y_s: ArrayLike = 0.2, + Y_abs: ArrayLike = 100, method: Union[ Literal["Fairchild 2011", "Fairchild 2010"], str ] = "Fairchild 2011", -) -> NDArray: +) -> NDArrayFloat: """ Convert from *hdr-CIELAB* colourspace to *CIE XYZ* tristimulus values. diff --git a/colour/models/hdr_ipt.py b/colour/models/hdr_ipt.py index 73f9bd8188..8b1e308d3b 100644 --- a/colour/models/hdr_ipt.py +++ b/colour/models/hdr_ipt.py @@ -34,11 +34,8 @@ ) from colour.hints import ( ArrayLike, - FloatingOrArrayLike, - FloatingOrNDArray, Literal, - NDArray, - Tuple, + NDArrayFloat, Union, ) from colour.models.ipt import ( @@ -75,7 +72,7 @@ "hdr_IPT_to_XYZ", ] -HDR_IPT_METHODS: Tuple = ("Fairchild 2010", "Fairchild 2011") +HDR_IPT_METHODS: tuple = ("Fairchild 2010", "Fairchild 2011") if is_documentation_building(): # pragma: no cover HDR_IPT_METHODS = DocstringTuple(HDR_IPT_METHODS) HDR_IPT_METHODS.__doc__ = """ @@ -88,12 +85,12 @@ def exponent_hdr_IPT( - Y_s: FloatingOrArrayLike, - Y_abs: FloatingOrArrayLike, + Y_s: ArrayLike, + Y_abs: ArrayLike, method: Union[ Literal["Fairchild 2011", "Fairchild 2010"], str ] = "Fairchild 2011", -) -> FloatingOrNDArray: +) -> NDArrayFloat: """ Compute *hdr-IPT* colourspace *Lightness* :math:`\\epsilon` exponent using *Fairchild and Wyble (2010)* or *Fairchild and Chen (2011)* method. @@ -110,7 +107,7 @@ def exponent_hdr_IPT( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` *hdr-IPT* colourspace *Lightness* :math:`\\epsilon` exponent. Notes @@ -151,12 +148,12 @@ def exponent_hdr_IPT( def XYZ_to_hdr_IPT( XYZ: ArrayLike, - Y_s: FloatingOrArrayLike = 0.2, - Y_abs: FloatingOrArrayLike = 100, + Y_s: ArrayLike = 0.2, + Y_abs: ArrayLike = 100, method: Union[ Literal["Fairchild 2011", "Fairchild 2010"], str ] = "Fairchild 2011", -) -> NDArray: +) -> NDArrayFloat: """ Convert from *CIE XYZ* tristimulus values to *hdr-IPT* colourspace. @@ -236,12 +233,12 @@ def XYZ_to_hdr_IPT( def hdr_IPT_to_XYZ( IPT_hdr: ArrayLike, - Y_s: FloatingOrArrayLike = 0.2, - Y_abs: FloatingOrArrayLike = 100, + Y_s: ArrayLike = 0.2, + Y_abs: ArrayLike = 100, method: Union[ Literal["Fairchild 2011", "Fairchild 2010"], str ] = "Fairchild 2011", -) -> NDArray: +) -> NDArrayFloat: """ Convert from *hdr-IPT* colourspace to *CIE XYZ* tristimulus values. diff --git a/colour/models/hunter_lab.py b/colour/models/hunter_lab.py index 619b0283f1..03628b8e1b 100644 --- a/colour/models/hunter_lab.py +++ b/colour/models/hunter_lab.py @@ -23,7 +23,7 @@ import numpy as np from colour.colorimetry import TVS_ILLUMINANTS_HUNTERLAB -from colour.hints import ArrayLike, NDArray +from colour.hints import ArrayLike, NDArrayFloat from colour.utilities import from_range_100, to_domain_100, tsplit, tstack __author__ = "Colour Developers" @@ -40,7 +40,7 @@ ] -def XYZ_to_K_ab_HunterLab1966(XYZ: ArrayLike) -> NDArray: +def XYZ_to_K_ab_HunterLab1966(XYZ: ArrayLike) -> NDArrayFloat: """ Convert from *whitepoint* *CIE XYZ* tristimulus values to *Hunter L,a,b* :math:`K_{a}` and :math:`K_{b}` chromaticity @@ -86,7 +86,7 @@ def XYZ_to_Hunter_Lab( K_ab: ArrayLike = TVS_ILLUMINANTS_HUNTERLAB[ "CIE 1931 2 Degree Standard Observer" ]["D65"].K_ab, -) -> NDArray: +) -> NDArrayFloat: """ Convert from *CIE XYZ* tristimulus values to *Hunter L,a,b* colour scale. @@ -168,7 +168,7 @@ def Hunter_Lab_to_XYZ( K_ab: ArrayLike = TVS_ILLUMINANTS_HUNTERLAB[ "CIE 1931 2 Degree Standard Observer" ]["D65"].K_ab, -) -> NDArray: +) -> NDArrayFloat: """ Convert from *Hunter L,a,b* colour scale to *CIE XYZ* tristimulus values. diff --git a/colour/models/hunter_rdab.py b/colour/models/hunter_rdab.py index 7e01f3369b..dd84d076df 100644 --- a/colour/models/hunter_rdab.py +++ b/colour/models/hunter_rdab.py @@ -18,7 +18,7 @@ from __future__ import annotations from colour.colorimetry import TVS_ILLUMINANTS_HUNTERLAB -from colour.hints import ArrayLike, NDArray +from colour.hints import ArrayLike, NDArrayFloat from colour.models import XYZ_to_K_ab_HunterLab1966 from colour.utilities import from_range_100, to_domain_100, tsplit, tstack @@ -43,7 +43,7 @@ def XYZ_to_Hunter_Rdab( K_ab: ArrayLike = TVS_ILLUMINANTS_HUNTERLAB[ "CIE 1931 2 Degree Standard Observer" ]["D65"].K_ab, -) -> NDArray: +) -> NDArrayFloat: """ Convert from *CIE XYZ* tristimulus values to *Hunter Rd,a,b* colour scale. @@ -127,7 +127,7 @@ def Hunter_Rdab_to_XYZ( K_ab: ArrayLike = TVS_ILLUMINANTS_HUNTERLAB[ "CIE 1931 2 Degree Standard Observer" ]["D65"].K_ab, -) -> NDArray: +) -> NDArrayFloat: """ Convert from *Hunter Rd,a,b* colour scale to *CIE XYZ* tristimulus values. diff --git a/colour/models/icacb.py b/colour/models/icacb.py index 9f2e4b7b8f..363416106c 100644 --- a/colour/models/icacb.py +++ b/colour/models/icacb.py @@ -17,7 +17,7 @@ import numpy as np -from colour.hints import ArrayLike, NDArray, cast +from colour.hints import ArrayLike, NDArrayFloat from colour.models import Iab_to_XYZ, XYZ_to_Iab from colour.models.rgb.transfer_functions import ( eotf_ST2084, @@ -41,7 +41,7 @@ "ICaCb_to_XYZ", ] -MATRIX_ICACB_XYZ_TO_LMS: NDArray = np.array( +MATRIX_ICACB_XYZ_TO_LMS: NDArrayFloat = np.array( [ [0.37613, 0.70431, -0.05675], [-0.21649, 1.14744, 0.05356], @@ -50,10 +50,10 @@ ) """*CIE XYZ* tristimulus values to normalised cone responses matrix.""" -MATRIX_ICACB_LMS_TO_XYZ: NDArray = np.linalg.inv(MATRIX_ICACB_XYZ_TO_LMS) +MATRIX_ICACB_LMS_TO_XYZ: NDArrayFloat = np.linalg.inv(MATRIX_ICACB_XYZ_TO_LMS) """Normalised cone responses to *CIE XYZ* tristimulus values matrix.""" -MATRIX_ICACB_XYZ_TO_LMS_2: NDArray = np.array( +MATRIX_ICACB_XYZ_TO_LMS_2: NDArrayFloat = np.array( [ [0.4949, 0.5037, 0.0015], [4.2854, -4.5462, 0.2609], @@ -62,11 +62,13 @@ ) """Normalised non-linear cone responses to :math:`IC_AC_B` colourspace matrix.""" -MATRIX_ICACB_LMS_TO_XYZ_2: NDArray = np.linalg.inv(MATRIX_ICACB_XYZ_TO_LMS_2) +MATRIX_ICACB_LMS_TO_XYZ_2: NDArrayFloat = np.linalg.inv( + MATRIX_ICACB_XYZ_TO_LMS_2 +) """:math:`IC_AC_B` to normalised non-linear cone responses colourspace matrix.""" -def XYZ_to_ICaCb(XYZ: ArrayLike) -> NDArray: +def XYZ_to_ICaCb(XYZ: ArrayLike) -> NDArrayFloat: """ Convert from *CIE XYZ* tristimulus values to :math:`IC_AC_B` colourspace. @@ -112,14 +114,14 @@ def XYZ_to_ICaCb(XYZ: ArrayLike) -> NDArray: array([ 0.06875297, 0.05753352, 0.02081548]) """ - def LMS_to_LMS_p_callable(LMS: ArrayLike) -> NDArray: + def LMS_to_LMS_p_callable(LMS: ArrayLike) -> NDArrayFloat: """ Callable applying the forward non-linearity to the :math:`LMS` colourspace array. """ with domain_range_scale("ignore"): - return cast(NDArray, eotf_inverse_ST2084(LMS)) + return eotf_inverse_ST2084(LMS) return XYZ_to_Iab( XYZ, @@ -129,7 +131,7 @@ def LMS_to_LMS_p_callable(LMS: ArrayLike) -> NDArray: ) -def ICaCb_to_XYZ(ICaCb: ArrayLike) -> NDArray: +def ICaCb_to_XYZ(ICaCb: ArrayLike) -> NDArrayFloat: """ Convert from :math:`IC_AC_B` tristimulus values to *CIE XYZ* colourspace. @@ -172,14 +174,14 @@ def ICaCb_to_XYZ(ICaCb: ArrayLike) -> NDArray: array([ 0.20654008, 0.12197225, 0.05136951]) """ - def LMS_p_to_LMS_callable(LMS_p: ArrayLike) -> NDArray: + def LMS_p_to_LMS_callable(LMS_p: ArrayLike) -> NDArrayFloat: """ Callable applying the reverse non-linearity to the :math:`LMS_p` colourspace array. """ with domain_range_scale("ignore"): - return cast(NDArray, eotf_ST2084(LMS_p)) + return eotf_ST2084(LMS_p) return Iab_to_XYZ( ICaCb, diff --git a/colour/models/igpgtg.py b/colour/models/igpgtg.py index 489d3efb74..a910082a95 100644 --- a/colour/models/igpgtg.py +++ b/colour/models/igpgtg.py @@ -19,7 +19,7 @@ import numpy as np from colour.algebra import spow from colour.models import Iab_to_XYZ, XYZ_to_Iab -from colour.hints import ArrayLike, NDArray, cast +from colour.hints import ArrayLike, NDArrayFloat, cast __author__ = "Colour Developers" __copyright__ = "Copyright 2013 Colour Developers" @@ -37,7 +37,7 @@ "IgPgTg_to_XYZ", ] -MATRIX_IGPGTG_XYZ_TO_LMS: NDArray = np.array( +MATRIX_IGPGTG_XYZ_TO_LMS: NDArrayFloat = np.array( [ [2.968, 2.741, -0.649], [1.237, 5.969, -0.173], @@ -46,10 +46,12 @@ ) """*CIE XYZ* tristimulus values to normalised cone responses matrix.""" -MATRIX_IGPGTG_LMS_TO_XYZ: NDArray = np.linalg.inv(MATRIX_IGPGTG_XYZ_TO_LMS) +MATRIX_IGPGTG_LMS_TO_XYZ: NDArrayFloat = np.linalg.inv( + MATRIX_IGPGTG_XYZ_TO_LMS +) """Normalised cone responses to *CIE XYZ* tristimulus values matrix.""" -MATRIX_IGPGTG_LMS_P_TO_IGPGTG: NDArray = np.array( +MATRIX_IGPGTG_LMS_P_TO_IGPGTG: NDArrayFloat = np.array( [ [0.117, 1.464, 0.130], [8.285, -8.361, 21.400], @@ -58,13 +60,13 @@ ) """Normalised non-linear cone responses to :math:`I_GP_GT_G` colourspace matrix.""" -MATRIX_IGPGTG_IGPGTG_TO_LMS_P: NDArray = np.linalg.inv( +MATRIX_IGPGTG_IGPGTG_TO_LMS_P: NDArrayFloat = np.linalg.inv( MATRIX_IGPGTG_LMS_P_TO_IGPGTG ) """:math:`I_GP_GT_G` colourspace to normalised non-linear cone responses matrix.""" -def XYZ_to_IgPgTg(XYZ: ArrayLike) -> NDArray: +def XYZ_to_IgPgTg(XYZ: ArrayLike) -> NDArrayFloat: """ Convert from *CIE XYZ* tristimulus values to :math:`I_GP_GT_G` colourspace. @@ -111,15 +113,13 @@ def XYZ_to_IgPgTg(XYZ: ArrayLike) -> NDArray: array([ 0.4242125..., 0.1863249..., 0.1068922...]) """ - def LMS_to_LMS_p_callable(LMS: ArrayLike) -> NDArray: + def LMS_to_LMS_p_callable(LMS: ArrayLike) -> NDArrayFloat: """ Callable applying the forward non-linearity to the :math:`LMS` colourspace array. """ - return cast( - NDArray, spow(LMS / np.array([18.36, 21.46, 19435]), 0.427) - ) + return spow(LMS / np.array([18.36, 21.46, 19435]), 0.427) return XYZ_to_Iab( XYZ, @@ -129,7 +129,7 @@ def LMS_to_LMS_p_callable(LMS: ArrayLike) -> NDArray: ) -def IgPgTg_to_XYZ(IgPgTg: ArrayLike) -> NDArray: +def IgPgTg_to_XYZ(IgPgTg: ArrayLike) -> NDArrayFloat: """ Convert from :math:`I_GP_GT_G` colourspace to *CIE XYZ* tristimulus values. @@ -173,14 +173,15 @@ def IgPgTg_to_XYZ(IgPgTg: ArrayLike) -> NDArray: array([ 0.2065400..., 0.1219722..., 0.0513695...]) """ - def LMS_p_to_LMS_callable(LMS_p: ArrayLike) -> NDArray: + def LMS_p_to_LMS_callable(LMS_p: ArrayLike) -> NDArrayFloat: """ Callable applying the reverse non-linearity to the :math:`LMS_p` colourspace array. """ return cast( - NDArray, spow(LMS_p, 1 / 0.427) * np.array([18.36, 21.46, 19435]) + NDArrayFloat, + spow(LMS_p, 1 / 0.427) * np.array([18.36, 21.46, 19435]), ) return Iab_to_XYZ( diff --git a/colour/models/ipt.py b/colour/models/ipt.py index c89e0a9743..93c4031967 100644 --- a/colour/models/ipt.py +++ b/colour/models/ipt.py @@ -24,7 +24,7 @@ from colour.algebra import spow from colour.models import Iab_to_XYZ, XYZ_to_Iab -from colour.hints import ArrayLike, FloatingOrNDArray, NDArray +from colour.hints import ArrayLike, NDArrayFloat from colour.utilities import as_float, from_range_degrees, to_domain_1, tsplit __author__ = "Colour Developers" @@ -44,7 +44,7 @@ "IPT_hue_angle", ] -MATRIX_IPT_XYZ_TO_LMS: NDArray = np.array( +MATRIX_IPT_XYZ_TO_LMS: NDArrayFloat = np.array( [ [0.4002, 0.7075, -0.0807], [-0.2280, 1.1500, 0.0612], @@ -53,10 +53,10 @@ ) """*CIE XYZ* tristimulus values to normalised cone responses matrix.""" -MATRIX_IPT_LMS_TO_XYZ: NDArray = np.linalg.inv(MATRIX_IPT_XYZ_TO_LMS) +MATRIX_IPT_LMS_TO_XYZ: NDArrayFloat = np.linalg.inv(MATRIX_IPT_XYZ_TO_LMS) """Normalised cone responses to *CIE XYZ* tristimulus values matrix.""" -MATRIX_IPT_LMS_P_TO_IPT: NDArray = np.array( +MATRIX_IPT_LMS_P_TO_IPT: NDArrayFloat = np.array( [ [0.4000, 0.4000, 0.2000], [4.4550, -4.8510, 0.3960], @@ -65,11 +65,11 @@ ) """Normalised non-linear cone responses to *IPT* colourspace matrix.""" -MATRIX_IPT_IPT_TO_LMS_P: NDArray = np.linalg.inv(MATRIX_IPT_LMS_P_TO_IPT) +MATRIX_IPT_IPT_TO_LMS_P: NDArrayFloat = np.linalg.inv(MATRIX_IPT_LMS_P_TO_IPT) """*IPT* colourspace to normalised non-linear cone responses matrix.""" -def XYZ_to_IPT(XYZ: ArrayLike) -> NDArray: +def XYZ_to_IPT(XYZ: ArrayLike) -> NDArrayFloat: """ Convert from *CIE XYZ* tristimulus values to *IPT* colourspace. @@ -123,7 +123,7 @@ def XYZ_to_IPT(XYZ: ArrayLike) -> NDArray: ) -def IPT_to_XYZ(IPT: ArrayLike) -> NDArray: +def IPT_to_XYZ(IPT: ArrayLike) -> NDArrayFloat: """ Convert from *IPT* colourspace to *CIE XYZ* tristimulus values. @@ -174,7 +174,7 @@ def IPT_to_XYZ(IPT: ArrayLike) -> NDArray: ) -def IPT_hue_angle(IPT: ArrayLike) -> FloatingOrNDArray: +def IPT_hue_angle(IPT: ArrayLike) -> NDArrayFloat: """ Compute the hue angle in degrees from *IPT* colourspace. @@ -185,7 +185,7 @@ def IPT_hue_angle(IPT: ArrayLike) -> FloatingOrNDArray: Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Hue angle in degrees. Notes diff --git a/colour/models/jzazbz.py b/colour/models/jzazbz.py index 8a4a3069c8..bf78e11606 100644 --- a/colour/models/jzazbz.py +++ b/colour/models/jzazbz.py @@ -29,9 +29,8 @@ from colour.hints import ( ArrayLike, Literal, - NDArray, + NDArrayFloat, Optional, - Tuple, Union, ) from colour.models.rgb.transfer_functions import ( @@ -97,7 +96,7 @@ CONSTANTS_JZAZBZ_SAFDAR2021.d_0 = 3.7035226210190005 * 10**-11 """:math:`J_za_zb_z` colourspace constants for the *ZCAM* colour appearance model.""" -MATRIX_JZAZBZ_XYZ_TO_LMS: NDArray = np.array( +MATRIX_JZAZBZ_XYZ_TO_LMS: NDArrayFloat = np.array( [ [0.41478972, 0.579999, 0.0146480], [-0.2015100, 1.120649, 0.0531008], @@ -109,13 +108,15 @@ matrix. """ -MATRIX_JZAZBZ_LMS_TO_XYZ: NDArray = np.linalg.inv(MATRIX_JZAZBZ_XYZ_TO_LMS) +MATRIX_JZAZBZ_LMS_TO_XYZ: NDArrayFloat = np.linalg.inv( + MATRIX_JZAZBZ_XYZ_TO_LMS +) """ :math:`J_za_zb_z` normalised cone responses to *CIE XYZ* tristimulus values matrix. """ -MATRIX_JZAZBZ_LMS_P_TO_IZAZBZ_SAFDAR2017: NDArray = np.array( +MATRIX_JZAZBZ_LMS_P_TO_IZAZBZ_SAFDAR2017: NDArrayFloat = np.array( [ [0.500000, 0.500000, 0.000000], [3.524000, -4.066708, 0.542708], @@ -127,7 +128,7 @@ :math:`I_za_zb_z` intermediate colourspace matrix. """ -MATRIX_JZAZBZ_IZAZBZ_TO_LMS_P_SAFDAR2017: NDArray = np.linalg.inv( +MATRIX_JZAZBZ_IZAZBZ_TO_LMS_P_SAFDAR2017: NDArrayFloat = np.linalg.inv( MATRIX_JZAZBZ_LMS_P_TO_IZAZBZ_SAFDAR2017 ) """ @@ -135,7 +136,7 @@ *SMPTE ST 2084:2014* encoded normalised cone responses matrix. """ -MATRIX_JZAZBZ_LMS_P_TO_IZAZBZ_SAFDAR2021: NDArray = np.array( +MATRIX_JZAZBZ_LMS_P_TO_IZAZBZ_SAFDAR2021: NDArrayFloat = np.array( [ [0.000000, 1.000000, 0.000000], [3.524000, -4.066708, 0.542708], @@ -151,7 +152,7 @@ :cite:`Safdar2021` """ -MATRIX_JZAZBZ_IZAZBZ_TO_LMS_P_SAFDAR2021: NDArray = np.linalg.inv( +MATRIX_JZAZBZ_IZAZBZ_TO_LMS_P_SAFDAR2021: NDArrayFloat = np.linalg.inv( MATRIX_JZAZBZ_LMS_P_TO_IZAZBZ_SAFDAR2021 ) """ @@ -163,7 +164,7 @@ :cite:`Safdar2021` """ -IZAZBZ_METHODS: Tuple = ("Safdar 2017", "Safdar 2021", "ZCAM") +IZAZBZ_METHODS: tuple = ("Safdar 2017", "Safdar 2021", "ZCAM") if is_documentation_building(): # pragma: no cover IZAZBZ_METHODS = DocstringTuple(IZAZBZ_METHODS) IZAZBZ_METHODS.__doc__ = """ @@ -181,7 +182,7 @@ def XYZ_to_Izazbz( method: Union[ Literal["Safdar 2017", "Safdar 2021", "ZCAM"], str ] = "Safdar 2017", -) -> NDArray: +) -> NDArrayFloat: """ Convert from *CIE XYZ* tristimulus values to :math:`I_za_zb_z` colourspace. @@ -280,7 +281,7 @@ def Izazbz_to_XYZ( method: Union[ Literal["Safdar 2017", "Safdar 2021", "ZCAM"], str ] = "Safdar 2017", -) -> NDArray: +) -> NDArrayFloat: """ Convert from :math:`I_za_zb_z` colourspace to *CIE XYZ* tristimulus values. @@ -375,7 +376,7 @@ def Izazbz_to_XYZ( def XYZ_to_Jzazbz( XYZ_D65: ArrayLike, constants: Structure = CONSTANTS_JZAZBZ_SAFDAR2017 -) -> NDArray: +) -> NDArrayFloat: """ Convert from *CIE XYZ* tristimulus values to :math:`J_za_zb_z` colourspace. @@ -452,7 +453,7 @@ def XYZ_to_Jzazbz( def Jzazbz_to_XYZ( Jzazbz: ArrayLike, constants: Structure = CONSTANTS_JZAZBZ_SAFDAR2017 -) -> NDArray: +) -> NDArrayFloat: """ Convert from :math:`J_za_zb_z` colourspace to *CIE XYZ* tristimulus values. diff --git a/colour/models/munish2021.py b/colour/models/munish2021.py index 383355369d..cab4761564 100644 --- a/colour/models/munish2021.py +++ b/colour/models/munish2021.py @@ -23,7 +23,7 @@ from colour.algebra import spow from colour.models import Iab_to_XYZ, XYZ_to_Iab -from colour.hints import ArrayLike, NDArray +from colour.hints import ArrayLike, NDArrayFloat __author__ = "Colour Developers" __copyright__ = "Copyright 2013 Colour Developers" @@ -41,7 +41,7 @@ "IPT_Munish2021_to_XYZ", ] -MATRIX_IPT_XYZ_TO_LMS: NDArray = np.array( +MATRIX_IPT_XYZ_TO_LMS: NDArrayFloat = np.array( [ [0.4321, 0.6906, -0.0930], [-0.1793, 1.1458, 0.0226], @@ -50,10 +50,10 @@ ) """*CIE XYZ* tristimulus values to normalised cone responses matrix.""" -MATRIX_IPT_LMS_TO_XYZ: NDArray = np.linalg.inv(MATRIX_IPT_XYZ_TO_LMS) +MATRIX_IPT_LMS_TO_XYZ: NDArrayFloat = np.linalg.inv(MATRIX_IPT_XYZ_TO_LMS) """Normalised cone responses to *CIE XYZ* tristimulus values matrix.""" -MATRIX_IPT_LMS_P_TO_IPT: NDArray = np.array( +MATRIX_IPT_LMS_P_TO_IPT: NDArrayFloat = np.array( [ [0.3037, 0.6688, 0.0276], [3.9247, -4.7339, 0.8093], @@ -65,14 +65,14 @@ *Optimised IPT* colourspace matrix. """ -MATRIX_IPT_IPT_TO_LMS_P: NDArray = np.linalg.inv(MATRIX_IPT_LMS_P_TO_IPT) +MATRIX_IPT_IPT_TO_LMS_P: NDArrayFloat = np.linalg.inv(MATRIX_IPT_LMS_P_TO_IPT) """ *Munish Ragoo and Farup (2021)* *Optimised IPT* colourspace to normalised non-linear cone responses matrix. """ -def XYZ_to_IPT_Munish2021(XYZ: ArrayLike) -> NDArray: +def XYZ_to_IPT_Munish2021(XYZ: ArrayLike) -> NDArrayFloat: """ Convert from *CIE XYZ* tristimulus values to *Munish Ragoo and Farup (2021)* *Optimised IPT* colourspace. @@ -127,7 +127,7 @@ def XYZ_to_IPT_Munish2021(XYZ: ArrayLike) -> NDArray: ) -def IPT_Munish2021_to_XYZ(IPT: ArrayLike) -> NDArray: +def IPT_Munish2021_to_XYZ(IPT: ArrayLike) -> NDArrayFloat: """ Convert from *Munish Ragoo and Farup (2021)* *Optimised IPT* colourspace to *CIE XYZ* tristimulus values. diff --git a/colour/models/oklab.py b/colour/models/oklab.py index 416a464a8d..9e3b35ebb3 100644 --- a/colour/models/oklab.py +++ b/colour/models/oklab.py @@ -21,7 +21,7 @@ from colour.algebra import spow from colour.models import Iab_to_XYZ, XYZ_to_Iab -from colour.hints import ArrayLike, NDArray +from colour.hints import ArrayLike, NDArrayFloat __author__ = "Colour Developers" __copyright__ = "Copyright 2013 Colour Developers" @@ -39,7 +39,7 @@ "Oklab_to_XYZ", ] -MATRIX_1_XYZ_TO_LMS: NDArray = np.array( +MATRIX_1_XYZ_TO_LMS: NDArrayFloat = np.array( [ [0.8189330101, 0.3618667424, -0.1288597137], [0.0329845436, 0.9293118715, 0.0361456387], @@ -48,10 +48,10 @@ ) """*CIE XYZ* tristimulus values to normalised cone responses matrix.""" -MATRIX_1_LMS_TO_XYZ: NDArray = np.linalg.inv(MATRIX_1_XYZ_TO_LMS) +MATRIX_1_LMS_TO_XYZ: NDArrayFloat = np.linalg.inv(MATRIX_1_XYZ_TO_LMS) """Normalised cone responses to *CIE XYZ* tristimulus values matrix.""" -MATRIX_2_LMS_TO_LAB: NDArray = np.array( +MATRIX_2_LMS_TO_LAB: NDArrayFloat = np.array( [ [0.2104542553, 0.7936177850, -0.0040720468], [1.9779984951, -2.4285922050, 0.4505937099], @@ -60,11 +60,11 @@ ) """Normalised cone responses to *Oklab* colourspace matrix.""" -MATRIX_2_LAB_TO_LMS: NDArray = np.linalg.inv(MATRIX_2_LMS_TO_LAB) +MATRIX_2_LAB_TO_LMS: NDArrayFloat = np.linalg.inv(MATRIX_2_LMS_TO_LAB) """*Oklab* colourspace to normalised cone responses matrix.""" -def XYZ_to_Oklab(XYZ: ArrayLike) -> NDArray: +def XYZ_to_Oklab(XYZ: ArrayLike) -> NDArrayFloat: """ Convert from *CIE XYZ* tristimulus values to *Oklab* colourspace. @@ -118,7 +118,7 @@ def XYZ_to_Oklab(XYZ: ArrayLike) -> NDArray: ) -def Oklab_to_XYZ(Lab: ArrayLike) -> NDArray: +def Oklab_to_XYZ(Lab: ArrayLike) -> NDArrayFloat: """ Convert from *Oklab* colourspace to *CIE XYZ* tristimulus values. diff --git a/colour/models/osa_ucs.py b/colour/models/osa_ucs.py index bafbf81841..b0e0888106 100644 --- a/colour/models/osa_ucs.py +++ b/colour/models/osa_ucs.py @@ -24,7 +24,7 @@ from scipy.optimize import fmin from colour.algebra import sdiv, sdiv_mode, spow, vector_dot -from colour.hints import ArrayLike, Dict, FloatingOrNDArray, NDArray, Optional +from colour.hints import ArrayLike, NDArrayFloat, Optional from colour.models import XYZ_to_xyY from colour.utilities import ( as_float, @@ -48,7 +48,7 @@ "OSA_UCS_to_XYZ", ] -MATRIX_XYZ_TO_RGB_OSA_UCS: NDArray = np.array( +MATRIX_XYZ_TO_RGB_OSA_UCS: NDArrayFloat = np.array( [ [0.799, 0.4194, -0.1648], [-0.4493, 1.3265, 0.0927], @@ -61,7 +61,7 @@ """ -def XYZ_to_OSA_UCS(XYZ: ArrayLike) -> NDArray: +def XYZ_to_OSA_UCS(XYZ: ArrayLike) -> NDArrayFloat: """ Convert from *CIE XYZ* tristimulus values under the *CIE 1964 10 Degree Standard Observer* to *OSA UCS* colourspace. @@ -147,8 +147,8 @@ def XYZ_to_OSA_UCS(XYZ: ArrayLike) -> NDArray: def OSA_UCS_to_XYZ( - Ljg: ArrayLike, optimisation_kwargs: Optional[Dict] = None -) -> NDArray: + Ljg: ArrayLike, optimisation_kwargs: Optional[dict] = None +) -> NDArrayFloat: """ Convert from *OSA UCS* colourspace to *CIE XYZ* tristimulus values under the *CIE 1964 10 Degree Standard Observer*. @@ -214,7 +214,7 @@ def OSA_UCS_to_XYZ( if optimisation_kwargs is not None: optimisation_settings.update(optimisation_kwargs) - def error_function(XYZ: ArrayLike, Ljg: ArrayLike) -> FloatingOrNDArray: + def error_function(XYZ: ArrayLike, Ljg: ArrayLike) -> NDArrayFloat: """Error function.""" # Error must be computed in "reference" domain and range. diff --git a/colour/models/prolab.py b/colour/models/prolab.py index 6e7d72a461..0203b198d9 100644 --- a/colour/models/prolab.py +++ b/colour/models/prolab.py @@ -19,7 +19,7 @@ import numpy as np from colour.colorimetry import CCS_ILLUMINANTS -from colour.hints import ArrayLike, NDArray +from colour.hints import ArrayLike, NDArrayFloat from colour.models import xy_to_xyY, xyY_to_XYZ from colour.utilities import as_float_array, from_range_1, ones, to_domain_1 @@ -37,21 +37,21 @@ "XYZ_to_ProLab", ] -MATRIX_Q: NDArray = np.array( +MATRIX_Q: NDArrayFloat = np.array( [ - [75.54, 486.66, 167.39, 0], - [617.72, -595.45, -22.27, 0], - [48.34, 194.94, -243.28, 0], - [0.7554, 3.8666, 1.6739, 1], + [75.54, 486.66, 167.39, 0.0], + [617.72, -595.45, -22.27, 0.0], + [48.34, 194.94, -243.28, 0.0], + [0.7554, 3.8666, 1.6739, 1.0], ] ) """Normalised cone responses to *CIE XYZ* tristimulus values matrix.""" -MATRIX_INVERSE_Q: NDArray = np.linalg.inv(MATRIX_Q) +MATRIX_INVERSE_Q: NDArrayFloat = np.linalg.inv(MATRIX_Q) """Normalised cone responses to *ProLab* colourspace matrix.""" -def projective_transformation(a: ArrayLike, Q: ArrayLike) -> NDArray: +def projective_transformation(a: ArrayLike, Q: ArrayLike) -> NDArrayFloat: """ Transform given array :math:`a` with the projective transformation matrix :math:`Q`. @@ -89,7 +89,7 @@ def XYZ_to_ProLab( illuminant: ArrayLike = CCS_ILLUMINANTS[ "CIE 1931 2 Degree Standard Observer" ]["D65"], -) -> NDArray: +) -> NDArrayFloat: """ Convert from *CIE XYZ* tristimulus values to *ProLab* colourspace. @@ -148,7 +148,7 @@ def ProLab_to_XYZ( illuminant: ArrayLike = CCS_ILLUMINANTS[ "CIE 1931 2 Degree Standard Observer" ]["D65"], -) -> NDArray: +) -> NDArrayFloat: """ Convert from *ProLab* colourspace to *CIE XYZ* tristimulus values. diff --git a/colour/models/rgb/cmyk.py b/colour/models/rgb/cmyk.py index e3d50ccd07..9b419deddf 100644 --- a/colour/models/rgb/cmyk.py +++ b/colour/models/rgb/cmyk.py @@ -25,7 +25,7 @@ import numpy as np -from colour.hints import ArrayLike, NDArray +from colour.hints import ArrayLike, NDArrayFloat from colour.utilities import ( as_float_array, from_range_1, @@ -49,7 +49,7 @@ ] -def RGB_to_CMY(RGB: ArrayLike) -> NDArray: +def RGB_to_CMY(RGB: ArrayLike) -> NDArrayFloat: """ Convert from *RGB* colourspace to *CMY* colourspace. @@ -93,7 +93,7 @@ def RGB_to_CMY(RGB: ArrayLike) -> NDArray: return from_range_1(CMY) -def CMY_to_RGB(CMY: ArrayLike) -> NDArray: +def CMY_to_RGB(CMY: ArrayLike) -> NDArrayFloat: """ Convert from *CMY* colourspace to *CMY* colourspace. @@ -137,7 +137,7 @@ def CMY_to_RGB(CMY: ArrayLike) -> NDArray: return from_range_1(RGB) -def CMY_to_CMYK(CMY: ArrayLike) -> NDArray: +def CMY_to_CMYK(CMY: ArrayLike) -> NDArrayFloat: """ Convert from *CMY* colourspace to *CMYK* colourspace. @@ -195,7 +195,7 @@ def CMY_to_CMYK(CMY: ArrayLike) -> NDArray: return from_range_1(CMYK) -def CMYK_to_CMY(CMYK: ArrayLike) -> NDArray: +def CMYK_to_CMY(CMYK: ArrayLike) -> NDArrayFloat: """ Convert from *CMYK* colourspace to *CMY* colourspace. diff --git a/colour/models/rgb/common.py b/colour/models/rgb/common.py index e6c741ecb1..32e1182af1 100644 --- a/colour/models/rgb/common.py +++ b/colour/models/rgb/common.py @@ -8,7 +8,7 @@ from __future__ import annotations from colour.colorimetry import CCS_ILLUMINANTS -from colour.hints import ArrayLike, Boolean, Literal, NDArray, Optional, Union +from colour.hints import ArrayLike, Literal, NDArrayFloat, Optional, Union from colour.models.rgb import RGB_COLOURSPACES, RGB_to_XYZ, XYZ_to_RGB __author__ = "Colour Developers" @@ -48,8 +48,8 @@ def XYZ_to_sRGB( str, ] ] = "CAT02", - apply_cctf_encoding: Boolean = True, -) -> NDArray: + apply_cctf_encoding: bool = True, +) -> NDArrayFloat: """ Convert from *CIE XYZ* tristimulus values to *sRGB* colourspace. @@ -128,8 +128,8 @@ def sRGB_to_XYZ( str, ] ] = "CAT02", - apply_cctf_decoding: Boolean = True, -) -> NDArray: + apply_cctf_decoding: bool = True, +) -> NDArrayFloat: """ Convert from *sRGB* colourspace to *CIE XYZ* tristimulus values. diff --git a/colour/models/rgb/cylindrical.py b/colour/models/rgb/cylindrical.py index 59b3f1a604..1e939585c8 100644 --- a/colour/models/rgb/cylindrical.py +++ b/colour/models/rgb/cylindrical.py @@ -44,7 +44,7 @@ import numpy as np from colour.algebra import sdiv, sdiv_mode -from colour.hints import ArrayLike, Floating, NDArray +from colour.hints import ArrayLike, NDArrayFloat, cast from colour.utilities import ( as_float_array, from_range_1, @@ -70,7 +70,7 @@ ] -def RGB_to_HSV(RGB: ArrayLike) -> NDArray: +def RGB_to_HSV(RGB: ArrayLike) -> NDArrayFloat: """ Convert from *RGB* colourspace to *HSV* colourspace. @@ -137,7 +137,7 @@ def RGB_to_HSV(RGB: ArrayLike) -> NDArray: return from_range_1(HSV) -def HSV_to_RGB(HSV: ArrayLike) -> NDArray: +def HSV_to_RGB(HSV: ArrayLike) -> NDArrayFloat: """ Convert from *HSV* colourspace to *RGB* colourspace. @@ -204,7 +204,7 @@ def HSV_to_RGB(HSV: ArrayLike) -> NDArray: return from_range_1(RGB) -def RGB_to_HSL(RGB: ArrayLike) -> NDArray: +def RGB_to_HSL(RGB: ArrayLike) -> NDArrayFloat: """ Convert from *RGB* colourspace to *HSL* colourspace. @@ -276,7 +276,7 @@ def RGB_to_HSL(RGB: ArrayLike) -> NDArray: return from_range_1(HSL) -def HSL_to_RGB(HSL: ArrayLike) -> NDArray: +def HSL_to_RGB(HSL: ArrayLike) -> NDArrayFloat: """ Convert from *HSL* colourspace to *RGB* colourspace. @@ -317,7 +317,9 @@ def HSL_to_RGB(HSL: ArrayLike) -> NDArray: H, S, L = tsplit(to_domain_1(HSL)) - def H_to_RGB(vi: NDArray, vj: NDArray, vH: NDArray) -> NDArray: + def H_to_RGB( + vi: NDArrayFloat, vj: NDArrayFloat, vH: NDArrayFloat + ) -> NDArrayFloat: """Convert *hue* value to *RGB* colourspace.""" vH = as_float_array(vH) @@ -357,8 +359,8 @@ def H_to_RGB(vi: NDArray, vj: NDArray, vH: NDArray) -> NDArray: def RGB_to_HCL( - RGB: ArrayLike, gamma: Floating = 3, Y_0: Floating = 100 -) -> NDArray: + RGB: ArrayLike, gamma: float = 3, Y_0: float = 100 +) -> NDArrayFloat: """ Convert from *RGB* colourspace to *HCL* colourspace according to *Sarifuddin and Missaoui (2005)* method. @@ -447,8 +449,8 @@ def RGB_to_HCL( def HCL_to_RGB( - HCL: ArrayLike, gamma: Floating = 3, Y_0: Floating = 100 -) -> NDArray: + HCL: ArrayLike, gamma: float = 3, Y_0: float = 100 +) -> NDArrayFloat: """ Convert from *HCL* colourspace to *RGB* colourspace according to *Sarifuddin and Missaoui (2005)* method. @@ -500,10 +502,10 @@ def HCL_to_RGB( Min = sdiv(4 * L - 3 * C, 4 * Q - 2) Max = Min + sdiv(3 * C, 2 * Q) - def _1_2_3(a: ArrayLike) -> NDArray: + def _1_2_3(a: ArrayLike) -> NDArrayFloat: """Tail-stack given :math:`a` array as a *bool* dtype.""" - return tstack([a, a, a], dtype=np.bool_) + return tstack(cast(ArrayLike, [a, a, a]), dtype=np.bool_) tan_3_2_H = np.tan(3 / 2 * H) tan_3_4_H_MP = np.tan(3 / 4 * (H - np.pi)) diff --git a/colour/models/rgb/datasets/aces.py b/colour/models/rgb/datasets/aces.py index bb3eae8abb..479308379c 100644 --- a/colour/models/rgb/datasets/aces.py +++ b/colour/models/rgb/datasets/aces.py @@ -26,7 +26,7 @@ - :cite:`TheAcademyofMotionPictureArtsandSciences2014s` : The Academy of Motion Picture Arts and Sciences, Science and Technology Council, & Academy Color Encoding System (ACES) Project Subcommittee. (2013). Specification - S-2013-001 - ACESproxy, an Integer Log Encoding of ACES Image Data. + S-2013-001 - ACESproxy, an int Log Encoding of ACES Image Data. Retrieved December 19, 2014, from http://j.mp/S-2013-001 - :cite:`TheAcademyofMotionPictureArtsandSciences2014t` : The Academy of Motion Picture Arts and Sciences, Science and Technology Council, & Academy @@ -56,7 +56,7 @@ import numpy as np from colour.colorimetry import CCS_ILLUMINANTS -from colour.hints import NDArray +from colour.hints import NDArrayFloat from colour.models.rgb import ( RGB_Colourspace, linear_function, @@ -92,7 +92,7 @@ "RGB_COLOURSPACE_ACESPROXY", ] -AP0: NDArray = np.array( +AP0: NDArrayFloat = np.array( [ [0.73470, 0.26530], [0.00000, 1.00000], @@ -101,7 +101,7 @@ ) """*ACES Primaries 0* or *AP0* primaries.""" -AP1: NDArray = np.array( +AP1: NDArrayFloat = np.array( [ [0.71300, 0.29300], [0.16500, 0.83000], @@ -116,12 +116,12 @@ WHITEPOINT_NAME_ACES: str = "ACES" """*ACES2065-1* colourspace whitepoint name.""" -CCS_WHITEPOINT_ACES: NDArray = CCS_ILLUMINANTS[ +CCS_WHITEPOINT_ACES: NDArrayFloat = CCS_ILLUMINANTS[ "CIE 1931 2 Degree Standard Observer" ][WHITEPOINT_NAME_ACES] """*ACES2065-1* colourspace whitepoint chromaticity coordinates.""" -MATRIX_AP0_TO_XYZ: NDArray = np.array( +MATRIX_AP0_TO_XYZ: NDArrayFloat = np.array( [ [0.9525523959, 0.0000000000, 0.0000936786], [0.3439664498, 0.7281660966, -0.0721325464], @@ -130,7 +130,7 @@ ) """*ACES Primaries 0* to *CIE XYZ* tristimulus values matrix defined as per [2].""" -MATRIX_XYZ_TO_AP0: NDArray = np.array( +MATRIX_XYZ_TO_AP0: NDArrayFloat = np.array( [ [1.0498110175, 0.0000000000, -0.0000974845], [-0.4959030231, 1.3733130458, 0.0982400361], @@ -139,12 +139,12 @@ ) """*CIE XYZ* tristimulus values to *ACES Primaries 0* matrix.""" -MATRIX_AP1_TO_XYZ: NDArray = normalised_primary_matrix( +MATRIX_AP1_TO_XYZ: NDArrayFloat = normalised_primary_matrix( AP1, CCS_WHITEPOINT_ACES ) """*ACES Primaries 1* to *CIE XYZ* tristimulus values matrix.""" -MATRIX_XYZ_TO_AP1: NDArray = np.linalg.inv(MATRIX_AP1_TO_XYZ) +MATRIX_XYZ_TO_AP1: NDArrayFloat = np.linalg.inv(MATRIX_AP1_TO_XYZ) """*CIE XYZ* tristimulus values to *ACES Primaries 1* matrix.""" RGB_COLOURSPACE_ACES2065_1: RGB_Colourspace = RGB_Colourspace( diff --git a/colour/models/rgb/datasets/adobe_rgb_1998.py b/colour/models/rgb/datasets/adobe_rgb_1998.py index 6a8e71f166..4f7dff5f25 100644 --- a/colour/models/rgb/datasets/adobe_rgb_1998.py +++ b/colour/models/rgb/datasets/adobe_rgb_1998.py @@ -18,7 +18,7 @@ from functools import partial from colour.colorimetry import CCS_ILLUMINANTS -from colour.hints import NDArray +from colour.hints import NDArrayFloat from colour.models.rgb import RGB_Colourspace, gamma_function __author__ = "Colour Developers" @@ -37,7 +37,7 @@ "RGB_COLOURSPACE_ADOBE_RGB1998", ] -PRIMARIES_ADOBE_RGB1998: NDArray = np.array( +PRIMARIES_ADOBE_RGB1998: NDArrayFloat = np.array( [ [0.6400, 0.3300], [0.2100, 0.7100], @@ -49,12 +49,12 @@ WHITEPOINT_NAME_ADOBE_RGB1998: str = "D65" """*Adobe RGB (1998)* colourspace whitepoint name.""" -CCS_WHITEPOINT_ADOBE_RGB1998: NDArray = CCS_ILLUMINANTS[ +CCS_WHITEPOINT_ADOBE_RGB1998: NDArrayFloat = CCS_ILLUMINANTS[ "CIE 1931 2 Degree Standard Observer" ][WHITEPOINT_NAME_ADOBE_RGB1998] """*Adobe RGB (1998)* colourspace whitepoint chromaticity coordinates.""" -MATRIX_ADOBE_RGB1998_TO_XYZ: NDArray = np.array( +MATRIX_ADOBE_RGB1998_TO_XYZ: NDArrayFloat = np.array( [ [0.57667, 0.18556, 0.18823], [0.29734, 0.62736, 0.07529], @@ -63,7 +63,7 @@ ) """*Adobe RGB (1998)* colourspace to *CIE XYZ* tristimulus values matrix.""" -MATRIX_XYZ_TO_ADOBE_RGB1998: NDArray = np.array( +MATRIX_XYZ_TO_ADOBE_RGB1998: NDArrayFloat = np.array( [ [2.04159, -0.56501, -0.34473], [-0.96924, 1.87597, 0.04156], diff --git a/colour/models/rgb/datasets/adobe_wide_gamut_rgb.py b/colour/models/rgb/datasets/adobe_wide_gamut_rgb.py index 8dc9942a6e..e34ddd74f3 100644 --- a/colour/models/rgb/datasets/adobe_wide_gamut_rgb.py +++ b/colour/models/rgb/datasets/adobe_wide_gamut_rgb.py @@ -19,7 +19,7 @@ from functools import partial from colour.colorimetry import CCS_ILLUMINANTS -from colour.hints import NDArray +from colour.hints import NDArrayFloat from colour.models.rgb import ( RGB_Colourspace, gamma_function, @@ -42,7 +42,7 @@ "RGB_COLOURSPACE_ADOBE_WIDE_GAMUT_RGB", ] -PRIMARIES_ADOBE_WIDE_GAMUT_RGB: NDArray = np.array( +PRIMARIES_ADOBE_WIDE_GAMUT_RGB: NDArrayFloat = np.array( [ [0.7347, 0.2653], [0.1152, 0.8264], @@ -54,17 +54,17 @@ WHITEPOINT_NAME_ADOBE_WIDE_GAMUT_RGB: str = "D50" """*Adobe Wide Gamut RGB* colourspace whitepoint name.""" -CCS_WHITEPOINT_ADOBE_WIDE_GAMUT_RGB: NDArray = CCS_ILLUMINANTS[ +CCS_WHITEPOINT_ADOBE_WIDE_GAMUT_RGB: NDArrayFloat = CCS_ILLUMINANTS[ "CIE 1931 2 Degree Standard Observer" ][WHITEPOINT_NAME_ADOBE_WIDE_GAMUT_RGB] """*Adobe Wide Gamut RGB* colourspace whitepoint chromaticity coordinates.""" -MATRIX_ADOBE_WIDE_GAMUT_RGB_TO_XYZ: NDArray = normalised_primary_matrix( +MATRIX_ADOBE_WIDE_GAMUT_RGB_TO_XYZ: NDArrayFloat = normalised_primary_matrix( PRIMARIES_ADOBE_WIDE_GAMUT_RGB, CCS_WHITEPOINT_ADOBE_WIDE_GAMUT_RGB ) """*Adobe Wide Gamut RGB* colourspace to *CIE XYZ* tristimulus values matrix.""" -MATRIX_XYZ_TO_ADOBE_WIDE_GAMUT_RGB: NDArray = np.linalg.inv( +MATRIX_XYZ_TO_ADOBE_WIDE_GAMUT_RGB: NDArrayFloat = np.linalg.inv( MATRIX_ADOBE_WIDE_GAMUT_RGB_TO_XYZ ) """*CIE XYZ* tristimulus values to *Adobe Wide Gamut RGB* colourspace matrix.""" diff --git a/colour/models/rgb/datasets/apple_rgb.py b/colour/models/rgb/datasets/apple_rgb.py index cc251ef6ba..87d801555d 100644 --- a/colour/models/rgb/datasets/apple_rgb.py +++ b/colour/models/rgb/datasets/apple_rgb.py @@ -18,7 +18,7 @@ from functools import partial from colour.colorimetry import CCS_ILLUMINANTS -from colour.hints import NDArray +from colour.hints import NDArrayFloat from colour.models.rgb import ( RGB_Colourspace, gamma_function, @@ -41,7 +41,7 @@ "RGB_COLOURSPACE_APPLE_RGB", ] -PRIMARIES_APPLE_RGB: NDArray = np.array( +PRIMARIES_APPLE_RGB: NDArrayFloat = np.array( [ [0.6250, 0.3400], [0.2800, 0.5950], @@ -53,17 +53,17 @@ WHITEPOINT_NAME_APPLE_RGB: str = "D65" """*Apple RGB* colourspace whitepoint name.""" -CCS_WHITEPOINT_APPLE_RGB: NDArray = CCS_ILLUMINANTS[ +CCS_WHITEPOINT_APPLE_RGB: NDArrayFloat = CCS_ILLUMINANTS[ "CIE 1931 2 Degree Standard Observer" ][WHITEPOINT_NAME_APPLE_RGB] """*Apple RGB* colourspace whitepoint chromaticity coordinates.""" -MATRIX_APPLE_RGB_TO_XYZ: NDArray = normalised_primary_matrix( +MATRIX_APPLE_RGB_TO_XYZ: NDArrayFloat = normalised_primary_matrix( PRIMARIES_APPLE_RGB, CCS_WHITEPOINT_APPLE_RGB ) """*Apple RGB* colourspace to *CIE XYZ* tristimulus values matrix.""" -MATRIX_XYZ_TO_APPLE_RGB: NDArray = np.linalg.inv(MATRIX_APPLE_RGB_TO_XYZ) +MATRIX_XYZ_TO_APPLE_RGB: NDArrayFloat = np.linalg.inv(MATRIX_APPLE_RGB_TO_XYZ) """*CIE XYZ* tristimulus values to *Apple RGB* colourspace matrix.""" RGB_COLOURSPACE_APPLE_RGB: RGB_Colourspace = RGB_Colourspace( diff --git a/colour/models/rgb/datasets/arri.py b/colour/models/rgb/datasets/arri.py index 452307c5c1..c868c705d2 100644 --- a/colour/models/rgb/datasets/arri.py +++ b/colour/models/rgb/datasets/arri.py @@ -22,7 +22,7 @@ import numpy as np from colour.colorimetry import CCS_ILLUMINANTS -from colour.hints import NDArray +from colour.hints import NDArrayFloat from colour.models.rgb import ( RGB_Colourspace, log_encoding_ARRILogC3, @@ -53,7 +53,7 @@ "RGB_COLOURSPACE_ARRI_WIDE_GAMUT_4", ] -PRIMARIES_ARRI_WIDE_GAMUT_3: NDArray = np.array( +PRIMARIES_ARRI_WIDE_GAMUT_3: NDArrayFloat = np.array( [ [0.6840, 0.3130], [0.2210, 0.8480], @@ -65,12 +65,12 @@ WHITEPOINT_NAME_ARRI_WIDE_GAMUT_3: str = "D65" """*ARRI Wide Gamut 3* colourspace whitepoint name.""" -CCS_WHITEPOINT_ARRI_WIDE_GAMUT_3: NDArray = CCS_ILLUMINANTS[ +CCS_WHITEPOINT_ARRI_WIDE_GAMUT_3: NDArrayFloat = CCS_ILLUMINANTS[ "CIE 1931 2 Degree Standard Observer" ][WHITEPOINT_NAME_ARRI_WIDE_GAMUT_3] """*ARRI Wide Gamut 3* colourspace whitepoint chromaticity coordinates.""" -MATRIX_ARRI_WIDE_GAMUT_3_TO_XYZ: NDArray = np.array( +MATRIX_ARRI_WIDE_GAMUT_3_TO_XYZ: NDArrayFloat = np.array( [ [0.638008, 0.214704, 0.097744], [0.291954, 0.823841, -0.115795], @@ -79,7 +79,7 @@ ) """*ARRI Wide Gamut 3* colourspace to *CIE XYZ* tristimulus values matrix.""" -MATRIX_XYZ_TO_ARRI_WIDE_GAMUT_3: NDArray = np.array( +MATRIX_XYZ_TO_ARRI_WIDE_GAMUT_3: NDArrayFloat = np.array( [ [1.789066, -0.482534, -0.200076], [-0.639849, 1.396400, 0.194432], @@ -106,7 +106,7 @@ :cite:`ARRI2012a` """ -PRIMARIES_ARRI_WIDE_GAMUT_4: NDArray = np.array( +PRIMARIES_ARRI_WIDE_GAMUT_4: NDArrayFloat = np.array( [ [0.7347, 0.2653], [0.1424, 0.8576], @@ -118,12 +118,12 @@ WHITEPOINT_NAME_ARRI_WIDE_GAMUT_4: str = "D65" """*ARRI Wide Gamut 4* colourspace whitepoint name.""" -CCS_WHITEPOINT_ARRI_WIDE_GAMUT_4: NDArray = CCS_ILLUMINANTS[ +CCS_WHITEPOINT_ARRI_WIDE_GAMUT_4: NDArrayFloat = CCS_ILLUMINANTS[ "CIE 1931 2 Degree Standard Observer" ][WHITEPOINT_NAME_ARRI_WIDE_GAMUT_4] """*ARRI Wide Gamut 4* colourspace whitepoint chromaticity coordinates.""" -MATRIX_ARRI_WIDE_GAMUT_4_TO_XYZ: NDArray = np.array( +MATRIX_ARRI_WIDE_GAMUT_4_TO_XYZ: NDArrayFloat = np.array( [ [0.7048583204, 0.1297602952, 0.1158373115], [0.2545241764, 0.7814777327, -0.0360019091], @@ -132,7 +132,7 @@ ) """*ARRI Wide Gamut 4* colourspace to *CIE XYZ* tristimulus values matrix.""" -MATRIX_XYZ_TO_ARRI_WIDE_GAMUT_4: NDArray = np.linalg.inv( +MATRIX_XYZ_TO_ARRI_WIDE_GAMUT_4: NDArrayFloat = np.linalg.inv( MATRIX_ARRI_WIDE_GAMUT_4_TO_XYZ ) """*CIE XYZ* tristimulus values to *ARRI Wide Gamut 4* colourspace matrix.""" diff --git a/colour/models/rgb/datasets/best_rgb.py b/colour/models/rgb/datasets/best_rgb.py index f55c5529e1..722cab8810 100644 --- a/colour/models/rgb/datasets/best_rgb.py +++ b/colour/models/rgb/datasets/best_rgb.py @@ -18,7 +18,7 @@ from functools import partial from colour.colorimetry import CCS_ILLUMINANTS -from colour.hints import NDArray +from colour.hints import NDArrayFloat from colour.models.rgb import ( RGB_Colourspace, gamma_function, @@ -41,7 +41,7 @@ "RGB_COLOURSPACE_BEST_RGB", ] -PRIMARIES_BEST_RGB: NDArray = np.array( +PRIMARIES_BEST_RGB: NDArrayFloat = np.array( [ [0.735191637630662, 0.264808362369338], [0.215336134453781, 0.774159663865546], @@ -53,17 +53,17 @@ WHITEPOINT_NAME_BEST_RGB: str = "D50" """*Best RGB* colourspace whitepoint name.""" -CCS_WHITEPOINT_BEST_RGB: NDArray = CCS_ILLUMINANTS[ +CCS_WHITEPOINT_BEST_RGB: NDArrayFloat = CCS_ILLUMINANTS[ "CIE 1931 2 Degree Standard Observer" ][WHITEPOINT_NAME_BEST_RGB] """*Best RGB* colourspace whitepoint chromaticity coordinates.""" -MATRIX_BEST_RGB_TO_XYZ: NDArray = normalised_primary_matrix( +MATRIX_BEST_RGB_TO_XYZ: NDArrayFloat = normalised_primary_matrix( PRIMARIES_BEST_RGB, CCS_WHITEPOINT_BEST_RGB ) """*Best RGB* colourspace to *CIE XYZ* tristimulus values matrix.""" -MATRIX_XYZ_TO_BEST_RGB: NDArray = np.linalg.inv(MATRIX_BEST_RGB_TO_XYZ) +MATRIX_XYZ_TO_BEST_RGB: NDArrayFloat = np.linalg.inv(MATRIX_BEST_RGB_TO_XYZ) """*CIE XYZ* tristimulus values to *Best RGB* colourspace matrix.""" RGB_COLOURSPACE_BEST_RGB: RGB_Colourspace = RGB_Colourspace( diff --git a/colour/models/rgb/datasets/beta_rgb.py b/colour/models/rgb/datasets/beta_rgb.py index 05c17b4005..d0f226579b 100644 --- a/colour/models/rgb/datasets/beta_rgb.py +++ b/colour/models/rgb/datasets/beta_rgb.py @@ -19,7 +19,7 @@ from functools import partial from colour.colorimetry import CCS_ILLUMINANTS -from colour.hints import NDArray +from colour.hints import NDArrayFloat from colour.models.rgb import ( RGB_Colourspace, gamma_function, @@ -42,7 +42,7 @@ "RGB_COLOURSPACE_BETA_RGB", ] -PRIMARIES_BETA_RGB: NDArray = np.array( +PRIMARIES_BETA_RGB: NDArrayFloat = np.array( [ [0.6888, 0.3112], [0.1986, 0.7551], @@ -54,17 +54,17 @@ WHITEPOINT_NAME_BETA_RGB: str = "D50" """*Beta RGB* colourspace whitepoint name.""" -CCS_WHITEPOINT_BETA_RGB: NDArray = CCS_ILLUMINANTS[ +CCS_WHITEPOINT_BETA_RGB: NDArrayFloat = CCS_ILLUMINANTS[ "CIE 1931 2 Degree Standard Observer" ][WHITEPOINT_NAME_BETA_RGB] """*Beta RGB* colourspace whitepoint chromaticity coordinates.""" -MATRIX_BETA_RGB_TO_XYZ: NDArray = normalised_primary_matrix( +MATRIX_BETA_RGB_TO_XYZ: NDArrayFloat = normalised_primary_matrix( PRIMARIES_BETA_RGB, CCS_WHITEPOINT_BETA_RGB ) """*Beta RGB* colourspace to *CIE XYZ* tristimulus values matrix.""" -MATRIX_XYZ_TO_BETA_RGB: NDArray = np.linalg.inv(MATRIX_BETA_RGB_TO_XYZ) +MATRIX_XYZ_TO_BETA_RGB: NDArrayFloat = np.linalg.inv(MATRIX_BETA_RGB_TO_XYZ) """*CIE XYZ* tristimulus values to *Beta RGB* colourspace matrix.""" RGB_COLOURSPACE_BETA_RGB: RGB_Colourspace = RGB_Colourspace( diff --git a/colour/models/rgb/datasets/blackmagic_design.py b/colour/models/rgb/datasets/blackmagic_design.py index 81753bef3e..23fbfdb2f0 100644 --- a/colour/models/rgb/datasets/blackmagic_design.py +++ b/colour/models/rgb/datasets/blackmagic_design.py @@ -18,7 +18,7 @@ import numpy as np from colour.colorimetry import CCS_ILLUMINANTS -from colour.hints import NDArray +from colour.hints import NDArrayFloat from colour.models.rgb import ( RGB_Colourspace, oetf_BlackmagicFilmGeneration5, @@ -41,7 +41,7 @@ "RGB_COLOURSPACE_BLACKMAGIC_WIDE_GAMUT", ] -PRIMARIES_BLACKMAGIC_WIDE_GAMUT: NDArray = np.array( +PRIMARIES_BLACKMAGIC_WIDE_GAMUT: NDArrayFloat = np.array( [ [0.7177215, 0.3171181], [0.2280410, 0.8615690], @@ -60,12 +60,12 @@ *D65* variant at 7 decimals: [0.3127170, 0.3290312] """ -CCS_WHITEPOINT_BLACKMAGIC_WIDE_GAMUT: NDArray = CCS_ILLUMINANTS[ +CCS_WHITEPOINT_BLACKMAGIC_WIDE_GAMUT: NDArrayFloat = CCS_ILLUMINANTS[ "CIE 1931 2 Degree Standard Observer" ][WHITEPOINT_NAME_BLACKMAGIC_WIDE_GAMUT] """*Blackmagic Wide Gamut* colourspace whitepoint chromaticity coordinates.""" -MATRIX_BLACKMAGIC_WIDE_GAMUT_TO_XYZ: NDArray = np.array( +MATRIX_BLACKMAGIC_WIDE_GAMUT_TO_XYZ: NDArrayFloat = np.array( [ [0.606530, 0.220408, 0.123479], [0.267989, 0.832731, -0.100720], @@ -74,7 +74,7 @@ ) """*Blackmagic Wide Gamut* colourspace to *CIE XYZ* tristimulus values matrix.""" -MATRIX_XYZ_TO_BLACKMAGIC_WIDE_GAMUT: NDArray = np.array( +MATRIX_XYZ_TO_BLACKMAGIC_WIDE_GAMUT: NDArrayFloat = np.array( [ [1.866382, -0.518397, -0.234610], [-0.600342, 1.378149, 0.176732], diff --git a/colour/models/rgb/datasets/canon_cinema_gamut.py b/colour/models/rgb/datasets/canon_cinema_gamut.py index 4829b0eadd..df70aa01de 100644 --- a/colour/models/rgb/datasets/canon_cinema_gamut.py +++ b/colour/models/rgb/datasets/canon_cinema_gamut.py @@ -19,7 +19,7 @@ import numpy as np from colour.colorimetry import CCS_ILLUMINANTS -from colour.hints import NDArray +from colour.hints import NDArrayFloat from colour.models.rgb import ( RGB_Colourspace, linear_function, @@ -42,7 +42,7 @@ "RGB_COLOURSPACE_CINEMA_GAMUT", ] -PRIMARIES_CINEMA_GAMUT: NDArray = np.array( +PRIMARIES_CINEMA_GAMUT: NDArrayFloat = np.array( [ [0.7400, 0.2700], [0.1700, 1.1400], @@ -54,17 +54,19 @@ WHITEPOINT_NAME_CINEMA_GAMUT: str = "D65" """*Canon Cinema Gamut* colourspace whitepoint name.""" -CCS_WHITEPOINT_CINEMA_GAMUT: NDArray = CCS_ILLUMINANTS[ +CCS_WHITEPOINT_CINEMA_GAMUT: NDArrayFloat = CCS_ILLUMINANTS[ "CIE 1931 2 Degree Standard Observer" ][WHITEPOINT_NAME_CINEMA_GAMUT] """*Canon Cinema Gamut* colourspace whitepoint chromaticity coordinates.""" -MATRIX_CINEMA_GAMUT_TO_XYZ: NDArray = normalised_primary_matrix( +MATRIX_CINEMA_GAMUT_TO_XYZ: NDArrayFloat = normalised_primary_matrix( PRIMARIES_CINEMA_GAMUT, CCS_WHITEPOINT_CINEMA_GAMUT ) """*Canon Cinema Gamut* colourspace to *CIE XYZ* tristimulus values matrix.""" -MATRIX_XYZ_TO_CINEMA_GAMUT: NDArray = np.linalg.inv(MATRIX_CINEMA_GAMUT_TO_XYZ) +MATRIX_XYZ_TO_CINEMA_GAMUT: NDArrayFloat = np.linalg.inv( + MATRIX_CINEMA_GAMUT_TO_XYZ +) """*CIE XYZ* tristimulus values to *Canon Cinema Gamut* colourspace matrix.""" RGB_COLOURSPACE_CINEMA_GAMUT: RGB_Colourspace = RGB_Colourspace( diff --git a/colour/models/rgb/datasets/cie_rgb.py b/colour/models/rgb/datasets/cie_rgb.py index 47157a5f1c..289ebe5fc2 100644 --- a/colour/models/rgb/datasets/cie_rgb.py +++ b/colour/models/rgb/datasets/cie_rgb.py @@ -20,7 +20,7 @@ from functools import partial from colour.colorimetry import CCS_ILLUMINANTS -from colour.hints import NDArray +from colour.hints import NDArrayFloat from colour.models.rgb import RGB_Colourspace, gamma_function __author__ = "Colour Developers" @@ -39,7 +39,7 @@ "RGB_COLOURSPACE_CIE_RGB", ] -PRIMARIES_CIE_RGB: NDArray = np.array( +PRIMARIES_CIE_RGB: NDArrayFloat = np.array( [ [0.734742840005998, 0.265257159994002], [0.273779033824958, 0.717477700256116], @@ -59,12 +59,12 @@ WHITEPOINT_NAME_CIE_RGB: str = "E" """*CIE RGB* colourspace whitepoint name.""" -CCS_WHITEPOINT_CIE_RGB: NDArray = CCS_ILLUMINANTS[ +CCS_WHITEPOINT_CIE_RGB: NDArrayFloat = CCS_ILLUMINANTS[ "CIE 1931 2 Degree Standard Observer" ][WHITEPOINT_NAME_CIE_RGB] """*CIE RGB* colourspace whitepoint chromaticity coordinates.""" -MATRIX_CIE_RGB_TO_XYZ: NDArray = np.array( +MATRIX_CIE_RGB_TO_XYZ: NDArrayFloat = np.array( [ [0.4900, 0.3100, 0.2000], [0.1769, 0.8124, 0.0107], @@ -73,7 +73,7 @@ ) """*CIE RGB* colourspace to *CIE XYZ* tristimulus values matrix.""" -MATRIX_XYZ_TO_CIE_RGB: NDArray = np.linalg.inv(MATRIX_CIE_RGB_TO_XYZ) +MATRIX_XYZ_TO_CIE_RGB: NDArrayFloat = np.linalg.inv(MATRIX_CIE_RGB_TO_XYZ) """*CIE XYZ* tristimulus values to *CIE RGB* colourspace matrix.""" RGB_COLOURSPACE_CIE_RGB: RGB_Colourspace = RGB_Colourspace( diff --git a/colour/models/rgb/datasets/color_match_rgb.py b/colour/models/rgb/datasets/color_match_rgb.py index 339a1bd7a9..4000a74a6d 100644 --- a/colour/models/rgb/datasets/color_match_rgb.py +++ b/colour/models/rgb/datasets/color_match_rgb.py @@ -19,7 +19,7 @@ from functools import partial from colour.colorimetry import CCS_ILLUMINANTS -from colour.hints import NDArray +from colour.hints import NDArrayFloat from colour.models.rgb import ( RGB_Colourspace, gamma_function, @@ -42,7 +42,7 @@ "RGB_COLOURSPACE_COLOR_MATCH_RGB", ] -PRIMARIES_COLOR_MATCH_RGB: NDArray = np.array( +PRIMARIES_COLOR_MATCH_RGB: NDArrayFloat = np.array( [ [0.6300, 0.3400], [0.2950, 0.6050], @@ -54,17 +54,17 @@ WHITEPOINT_NAME_COLOR_MATCH_RGB: str = "D50" """*ColorMatch RGB* colourspace whitepoint name.""" -CCS_WHITEPOINT_COLOR_MATCH_RGB: NDArray = CCS_ILLUMINANTS[ +CCS_WHITEPOINT_COLOR_MATCH_RGB: NDArrayFloat = CCS_ILLUMINANTS[ "CIE 1931 2 Degree Standard Observer" ][WHITEPOINT_NAME_COLOR_MATCH_RGB] """*ColorMatch RGB* colourspace whitepoint chromaticity coordinates.""" -MATRIX_COLOR_MATCH_RGB_TO_XYZ: NDArray = normalised_primary_matrix( +MATRIX_COLOR_MATCH_RGB_TO_XYZ: NDArrayFloat = normalised_primary_matrix( PRIMARIES_COLOR_MATCH_RGB, CCS_WHITEPOINT_COLOR_MATCH_RGB ) """*ColorMatch RGB* colourspace to *CIE XYZ* tristimulus values matrix.""" -MATRIX_XYZ_TO_COLOR_MATCH_RGB: NDArray = np.linalg.inv( +MATRIX_XYZ_TO_COLOR_MATCH_RGB: NDArrayFloat = np.linalg.inv( MATRIX_COLOR_MATCH_RGB_TO_XYZ ) """*CIE XYZ* tristimulus values to *ColorMatch RGB* colourspace matrix.""" diff --git a/colour/models/rgb/datasets/davinci_wide_gamut.py b/colour/models/rgb/datasets/davinci_wide_gamut.py index 534b2d92c9..88fe9f68b8 100644 --- a/colour/models/rgb/datasets/davinci_wide_gamut.py +++ b/colour/models/rgb/datasets/davinci_wide_gamut.py @@ -21,7 +21,7 @@ import numpy as np from colour.colorimetry import CCS_ILLUMINANTS -from colour.hints import NDArray +from colour.hints import NDArrayFloat from colour.models.rgb import ( RGB_Colourspace, oetf_DaVinciIntermediate, @@ -44,7 +44,7 @@ "RGB_COLOURSPACE_DAVINCI_WIDE_GAMUT", ] -PRIMARIES_DAVINCI_WIDE_GAMUT: NDArray = np.array( +PRIMARIES_DAVINCI_WIDE_GAMUT: NDArrayFloat = np.array( [ [0.8000, 0.3130], [0.1682, 0.9877], @@ -56,12 +56,12 @@ WHITEPOINT_NAME_DAVINCI_WIDE_GAMUT: str = "D65" """*DaVinci Wide Gamut* colourspace whitepoint name.""" -CCS_WHITEPOINT_DAVINCI_WIDE_GAMUT: NDArray = CCS_ILLUMINANTS[ +CCS_WHITEPOINT_DAVINCI_WIDE_GAMUT: NDArrayFloat = CCS_ILLUMINANTS[ "CIE 1931 2 Degree Standard Observer" ][WHITEPOINT_NAME_DAVINCI_WIDE_GAMUT] """*DaVinci Wide Gamut* colourspace whitepoint chromaticity coordinates.""" -MATRIX_DAVINCI_WIDE_GAMUT_TO_XYZ: NDArray = np.array( +MATRIX_DAVINCI_WIDE_GAMUT_TO_XYZ: NDArrayFloat = np.array( [ [0.70062239, 0.14877482, 0.10105872], [0.27411851, 0.87363190, -0.14775041], @@ -70,7 +70,7 @@ ) """*DaVinci Wide Gamut* colourspace to *CIE XYZ* tristimulus values matrix.""" -MATRIX_XYZ_TO_DAVINCI_WIDE_GAMUT: NDArray = np.array( +MATRIX_XYZ_TO_DAVINCI_WIDE_GAMUT: NDArrayFloat = np.array( [ [1.51667204, -0.28147805, -0.14696363], [-0.46491710, 1.25142378, 0.17488461], diff --git a/colour/models/rgb/datasets/dcdm_xyz.py b/colour/models/rgb/datasets/dcdm_xyz.py index c5df50ab14..1e5b326dd5 100644 --- a/colour/models/rgb/datasets/dcdm_xyz.py +++ b/colour/models/rgb/datasets/dcdm_xyz.py @@ -19,7 +19,7 @@ import numpy as np from colour.colorimetry import CCS_ILLUMINANTS -from colour.hints import NDArray +from colour.hints import NDArrayFloat from colour.models.rgb import ( RGB_Colourspace, eotf_DCDM, @@ -43,7 +43,7 @@ "RGB_COLOURSPACE_DCDM_XYZ", ] -PRIMARIES_DCDM_XYZ: NDArray = np.array( +PRIMARIES_DCDM_XYZ: NDArrayFloat = np.array( [ [1.0, 0.0], [0.0, 1.0], @@ -55,17 +55,17 @@ WHITEPOINT_NAME_DCDM_XYZ: str = "E" """*DCDM XYZ* colourspace whitepoint name.""" -CCS_WHITEPOINT_DCDM_XYZ: NDArray = CCS_ILLUMINANTS[ +CCS_WHITEPOINT_DCDM_XYZ: NDArrayFloat = CCS_ILLUMINANTS[ "CIE 1931 2 Degree Standard Observer" ][WHITEPOINT_NAME_DCDM_XYZ] """*DCDM XYZ* colourspace whitepoint chromaticity coordinates.""" -MATRIX_DCDM_XYZ_TO_XYZ: NDArray = normalised_primary_matrix( +MATRIX_DCDM_XYZ_TO_XYZ: NDArrayFloat = normalised_primary_matrix( PRIMARIES_DCDM_XYZ, CCS_WHITEPOINT_DCDM_XYZ ) """*DCDM XYZ* colourspace to *CIE XYZ* tristimulus values matrix.""" -MATRIX_XYZ_TO_DCDM_XYZ: NDArray = np.linalg.inv(MATRIX_DCDM_XYZ_TO_XYZ) +MATRIX_XYZ_TO_DCDM_XYZ: NDArrayFloat = np.linalg.inv(MATRIX_DCDM_XYZ_TO_XYZ) """*CIE XYZ* tristimulus values to *DCDM XYZ* colourspace matrix.""" RGB_COLOURSPACE_DCDM_XYZ: RGB_Colourspace = RGB_Colourspace( diff --git a/colour/models/rgb/datasets/dci_p3.py b/colour/models/rgb/datasets/dci_p3.py index 9b4f4ed783..4afa860bc5 100644 --- a/colour/models/rgb/datasets/dci_p3.py +++ b/colour/models/rgb/datasets/dci_p3.py @@ -30,7 +30,7 @@ from functools import partial from colour.colorimetry import CCS_ILLUMINANTS -from colour.hints import NDArray +from colour.hints import NDArrayFloat from colour.models.rgb import ( RGB_Colourspace, gamma_function, @@ -57,7 +57,7 @@ "RGB_COLOURSPACE_DCI_P3_P", ] -PRIMARIES_DCI_P3: NDArray = np.array( +PRIMARIES_DCI_P3: NDArrayFloat = np.array( [ [0.6800, 0.3200], [0.2650, 0.6900], @@ -66,7 +66,7 @@ ) """*DCI-P3* colourspace primaries.""" -PRIMARIES_DCI_P3_P: NDArray = np.array( +PRIMARIES_DCI_P3_P: NDArrayFloat = np.array( [ [0.7400, 0.2700], [0.2200, 0.7800], @@ -86,25 +86,25 @@ matching spectral distribution is Kinoton 75P projector. """ -CCS_WHITEPOINT_DCI_P3: NDArray = CCS_ILLUMINANTS[ +CCS_WHITEPOINT_DCI_P3: NDArrayFloat = CCS_ILLUMINANTS[ "CIE 1931 2 Degree Standard Observer" ][WHITEPOINT_NAME_DCI_P3] """*DCI-P3* colourspace whitepoint chromaticity coordinates.""" -MATRIX_DCI_P3_TO_XYZ: NDArray = normalised_primary_matrix( +MATRIX_DCI_P3_TO_XYZ: NDArrayFloat = normalised_primary_matrix( PRIMARIES_DCI_P3, CCS_WHITEPOINT_DCI_P3 ) """*DCI-P3* colourspace to *CIE XYZ* tristimulus values matrix.""" -MATRIX_XYZ_TO_DCI_P3: NDArray = np.linalg.inv(MATRIX_DCI_P3_TO_XYZ) +MATRIX_XYZ_TO_DCI_P3: NDArrayFloat = np.linalg.inv(MATRIX_DCI_P3_TO_XYZ) """*CIE XYZ* tristimulus values to *DCI-P3* colourspace matrix.""" -MATRIX_DCI_P3_P_TO_XYZ: NDArray = normalised_primary_matrix( +MATRIX_DCI_P3_P_TO_XYZ: NDArrayFloat = normalised_primary_matrix( PRIMARIES_DCI_P3_P, CCS_WHITEPOINT_DCI_P3 ) """*DCI-P3+* colourspace to *CIE XYZ* tristimulus values matrix.""" -MATRIX_XYZ_TO_DCI_P3_P: NDArray = np.linalg.inv(MATRIX_DCI_P3_P_TO_XYZ) +MATRIX_XYZ_TO_DCI_P3_P: NDArrayFloat = np.linalg.inv(MATRIX_DCI_P3_P_TO_XYZ) """*CIE XYZ* tristimulus values to *DCI-P3+* colourspace matrix.""" RGB_COLOURSPACE_DCI_P3: RGB_Colourspace = RGB_Colourspace( diff --git a/colour/models/rgb/datasets/display_p3.py b/colour/models/rgb/datasets/display_p3.py index 96f2be5d27..abda42e80a 100644 --- a/colour/models/rgb/datasets/display_p3.py +++ b/colour/models/rgb/datasets/display_p3.py @@ -18,7 +18,7 @@ import numpy as np from colour.colorimetry import CCS_ILLUMINANTS -from colour.hints import NDArray +from colour.hints import NDArrayFloat from colour.models.rgb import ( RGB_Colourspace, eotf_inverse_sRGB, @@ -43,23 +43,25 @@ "RGB_COLOURSPACE_DISPLAY_P3", ] -PRIMARIES_DISPLAY_P3: NDArray = RGB_COLOURSPACE_DCI_P3.primaries +PRIMARIES_DISPLAY_P3: NDArrayFloat = RGB_COLOURSPACE_DCI_P3.primaries """*Display P3* colourspace primaries.""" WHITEPOINT_NAME_DISPLAY_P3: str = "D65" """*Display P3* colourspace whitepoint name.""" -CCS_WHITEPOINT_DISPLAY_P3: NDArray = CCS_ILLUMINANTS[ +CCS_WHITEPOINT_DISPLAY_P3: NDArrayFloat = CCS_ILLUMINANTS[ "CIE 1931 2 Degree Standard Observer" ][WHITEPOINT_NAME_DISPLAY_P3] """*Display P3* colourspace whitepoint chromaticity coordinates.""" -MATRIX_DISPLAY_P3_TO_XYZ: NDArray = normalised_primary_matrix( +MATRIX_DISPLAY_P3_TO_XYZ: NDArrayFloat = normalised_primary_matrix( PRIMARIES_DISPLAY_P3, CCS_WHITEPOINT_DISPLAY_P3 ) """*Display P3* colourspace to *CIE XYZ* tristimulus values matrix.""" -MATRIX_XYZ_TO_DISPLAY_P3: NDArray = np.linalg.inv(MATRIX_DISPLAY_P3_TO_XYZ) +MATRIX_XYZ_TO_DISPLAY_P3: NDArrayFloat = np.linalg.inv( + MATRIX_DISPLAY_P3_TO_XYZ +) """*CIE XYZ* tristimulus values to *Display P3* colourspace matrix.""" RGB_COLOURSPACE_DISPLAY_P3: RGB_Colourspace = RGB_Colourspace( diff --git a/colour/models/rgb/datasets/dji_d_gamut.py b/colour/models/rgb/datasets/dji_d_gamut.py index 52e5f1cad7..88453d629e 100644 --- a/colour/models/rgb/datasets/dji_d_gamut.py +++ b/colour/models/rgb/datasets/dji_d_gamut.py @@ -19,7 +19,7 @@ import numpy as np from colour.colorimetry import CCS_ILLUMINANTS -from colour.hints import NDArray +from colour.hints import NDArrayFloat from colour.models.rgb import ( RGB_Colourspace, log_encoding_DJIDLog, @@ -42,7 +42,7 @@ "RGB_COLOURSPACE_DJI_D_GAMUT", ] -PRIMARIES_DJI_D_GAMUT: NDArray = np.array( +PRIMARIES_DJI_D_GAMUT: NDArrayFloat = np.array( [ [0.71, 0.31], [0.21, 0.88], @@ -54,12 +54,12 @@ WHITEPOINT_NAME_DJI_D_GAMUT: str = "D65" """*DJI D-Gamut* colourspace whitepoint name.""" -CCS_WHITEPOINT_DJI_D_GAMUT: NDArray = CCS_ILLUMINANTS[ +CCS_WHITEPOINT_DJI_D_GAMUT: NDArrayFloat = CCS_ILLUMINANTS[ "CIE 1931 2 Degree Standard Observer" ][WHITEPOINT_NAME_DJI_D_GAMUT] """*DJI D-Gamut* colourspace whitepoint chromaticity coordinates.""" -MATRIX_DJI_D_GAMUT_TO_XYZ: NDArray = np.array( +MATRIX_DJI_D_GAMUT_TO_XYZ: NDArrayFloat = np.array( [ [0.6482, 0.1940, 0.1082], [0.2830, 0.8132, -0.0962], @@ -68,7 +68,7 @@ ) """*DJI D-Gamut* colourspace to *CIE XYZ* tristimulus values matrix.""" -MATRIX_XYZ_TO_DJI_D_GAMUT: NDArray = np.array( +MATRIX_XYZ_TO_DJI_D_GAMUT: NDArrayFloat = np.array( [ [1.7257, -0.4314, -0.1917], [-0.6025, 1.3906, 0.1671], diff --git a/colour/models/rgb/datasets/don_rgb_4.py b/colour/models/rgb/datasets/don_rgb_4.py index 0a57a05177..5510577f04 100644 --- a/colour/models/rgb/datasets/don_rgb_4.py +++ b/colour/models/rgb/datasets/don_rgb_4.py @@ -18,7 +18,7 @@ from functools import partial from colour.colorimetry import CCS_ILLUMINANTS -from colour.hints import NDArray +from colour.hints import NDArrayFloat from colour.models.rgb import ( RGB_Colourspace, gamma_function, @@ -41,7 +41,7 @@ "RGB_COLOURSPACE_DON_RGB_4", ] -PRIMARIES_DON_RGB_4: NDArray = np.array( +PRIMARIES_DON_RGB_4: NDArrayFloat = np.array( [ [0.696120689655172, 0.299568965517241], [0.214682981090100, 0.765294771968854], @@ -53,17 +53,17 @@ WHITEPOINT_NAME_DON_RGB_4: str = "D50" """*Don RGB 4* colourspace whitepoint name.""" -CCS_WHITEPOINT_DON_RGB_4: NDArray = CCS_ILLUMINANTS[ +CCS_WHITEPOINT_DON_RGB_4: NDArrayFloat = CCS_ILLUMINANTS[ "CIE 1931 2 Degree Standard Observer" ][WHITEPOINT_NAME_DON_RGB_4] """*Don RGB 4* colourspace whitepoint chromaticity coordinates.""" -MATRIX_DON_RGB_4_TO_XYZ: NDArray = normalised_primary_matrix( +MATRIX_DON_RGB_4_TO_XYZ: NDArrayFloat = normalised_primary_matrix( PRIMARIES_DON_RGB_4, CCS_WHITEPOINT_DON_RGB_4 ) """*Don RGB 4* colourspace to *CIE XYZ* tristimulus values matrix.""" -MATRIX_XYZ_TO_DON_RGB_4: NDArray = np.linalg.inv(MATRIX_DON_RGB_4_TO_XYZ) +MATRIX_XYZ_TO_DON_RGB_4: NDArrayFloat = np.linalg.inv(MATRIX_DON_RGB_4_TO_XYZ) """*CIE XYZ* tristimulus values to *Don RGB 4* colourspace matrix.""" RGB_COLOURSPACE_DON_RGB_4: RGB_Colourspace = RGB_Colourspace( diff --git a/colour/models/rgb/datasets/ebu_3213_e.py b/colour/models/rgb/datasets/ebu_3213_e.py index f9e9882ad7..03ec5db12d 100644 --- a/colour/models/rgb/datasets/ebu_3213_e.py +++ b/colour/models/rgb/datasets/ebu_3213_e.py @@ -17,7 +17,7 @@ import numpy as np -from colour.hints import NDArray +from colour.hints import NDArrayFloat from colour.models.rgb import ( RGB_Colourspace, linear_function, @@ -40,7 +40,7 @@ "RGB_COLOURSPACE_EBU_3213_E", ] -PRIMARIES_EBU_3213_E: NDArray = np.array( +PRIMARIES_EBU_3213_E: NDArrayFloat = np.array( [ [0.64, 0.33], [0.29, 0.60], @@ -52,15 +52,15 @@ WHITEPOINT_NAME_EBU_3213_E: str = "D65" """*EBU Tech. 3213-E* colourspace whitepoint name.""" -CCS_WHITEPOINT_EBU_3213_E: NDArray = np.array([0.313, 0.329]) +CCS_WHITEPOINT_EBU_3213_E: NDArrayFloat = np.array([0.313, 0.329]) """*EBU Tech. 3213-E* colourspace whitepoint chromaticity coordinates.""" -MATRIX_EBU_3213_E_RGB_TO_XYZ: NDArray = normalised_primary_matrix( +MATRIX_EBU_3213_E_RGB_TO_XYZ: NDArrayFloat = normalised_primary_matrix( PRIMARIES_EBU_3213_E, CCS_WHITEPOINT_EBU_3213_E ) """*EBU Tech. 3213-E* colourspace to *CIE XYZ* tristimulus values matrix.""" -MATRIX_XYZ_TO_EBU_3213_E_RGB: NDArray = np.linalg.inv( +MATRIX_XYZ_TO_EBU_3213_E_RGB: NDArrayFloat = np.linalg.inv( MATRIX_EBU_3213_E_RGB_TO_XYZ ) """*CIE XYZ* tristimulus values to *EBU Tech. 3213-E* colourspace matrix.""" diff --git a/colour/models/rgb/datasets/eci_rgb_v2.py b/colour/models/rgb/datasets/eci_rgb_v2.py index 013661e333..2515269fca 100644 --- a/colour/models/rgb/datasets/eci_rgb_v2.py +++ b/colour/models/rgb/datasets/eci_rgb_v2.py @@ -24,10 +24,9 @@ luminance_CIE1976, ) from colour.hints import ( + ArrayLike, Callable, - NDArray, - FloatingOrArrayLike, - FloatingOrNDArray, + NDArrayFloat, ) from colour.models.rgb import RGB_Colourspace, normalised_primary_matrix from colour.utilities import as_float_array @@ -48,7 +47,7 @@ "RGB_COLOURSPACE_ECI_RGB_V2", ] -PRIMARIES_ECI_RGB_V2: NDArray = np.array( +PRIMARIES_ECI_RGB_V2: NDArrayFloat = np.array( [ [0.670103092783505, 0.329896907216495], [0.209905660377358, 0.709905660377358], @@ -60,23 +59,25 @@ WHITEPOINT_NAME_ECI_RGB_V: str = "D50" """*ECI RGB v2* colourspace whitepoint name.""" -CCS_WHITEPOINT_ECI_RGB_V2: NDArray = CCS_ILLUMINANTS[ +CCS_WHITEPOINT_ECI_RGB_V2: NDArrayFloat = CCS_ILLUMINANTS[ "CIE 1931 2 Degree Standard Observer" ][WHITEPOINT_NAME_ECI_RGB_V] """*ECI RGB v2* colourspace whitepoint chromaticity coordinates.""" -MATRIX_ECI_RGB_V2_TO_XYZ: NDArray = normalised_primary_matrix( +MATRIX_ECI_RGB_V2_TO_XYZ: NDArrayFloat = normalised_primary_matrix( PRIMARIES_ECI_RGB_V2, CCS_WHITEPOINT_ECI_RGB_V2 ) """*ECI RGB v2* colourspace to *CIE XYZ* tristimulus values matrix.""" -MATRIX_XYZ_TO_ECI_RGB_V2: NDArray = np.linalg.inv(MATRIX_ECI_RGB_V2_TO_XYZ) +MATRIX_XYZ_TO_ECI_RGB_V2: NDArrayFloat = np.linalg.inv( + MATRIX_ECI_RGB_V2_TO_XYZ +) """*CIE XYZ* tristimulus values to *ECI RGB v2* colourspace matrix.""" def _scale_domain_0_100_range_0_1( - a: FloatingOrArrayLike, callable_: Callable -) -> FloatingOrNDArray: + a: ArrayLike, callable_: Callable +) -> NDArrayFloat: """ Scale the input domain of given *luminance* :math:`Y` or *Lightness* :math:`L^*` array to [0, 100], call the given callable, and @@ -94,7 +95,7 @@ def _scale_domain_0_100_range_0_1( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Scaled *luminance* :math:`Y` or *Lightness* :math:`L^*` array. """ diff --git a/colour/models/rgb/datasets/ekta_space_ps5.py b/colour/models/rgb/datasets/ekta_space_ps5.py index 65bc04172f..9923921c62 100644 --- a/colour/models/rgb/datasets/ekta_space_ps5.py +++ b/colour/models/rgb/datasets/ekta_space_ps5.py @@ -18,7 +18,7 @@ from functools import partial from colour.colorimetry import CCS_ILLUMINANTS -from colour.hints import NDArray +from colour.hints import NDArrayFloat from colour.models.rgb import ( RGB_Colourspace, gamma_function, @@ -41,7 +41,7 @@ "RGB_COLOURSPACE_EKTA_SPACE_PS_5", ] -PRIMARIES_EKTA_SPACE_PS_5: NDArray = np.array( +PRIMARIES_EKTA_SPACE_PS_5: NDArrayFloat = np.array( [ [0.694736842105263, 0.305263157894737], [0.260000000000000, 0.700000000000000], @@ -53,17 +53,17 @@ WHITEPOINT_NAME_EKTA_SPACE_PS_5_V: str = "D50" """*Ekta Space PS 5* colourspace whitepoint name.""" -CCS_WHITEPOINT_EKTA_SPACE_PS_5: NDArray = CCS_ILLUMINANTS[ +CCS_WHITEPOINT_EKTA_SPACE_PS_5: NDArrayFloat = CCS_ILLUMINANTS[ "CIE 1931 2 Degree Standard Observer" ][WHITEPOINT_NAME_EKTA_SPACE_PS_5_V] """*Ekta Space PS 5* colourspace whitepoint chromaticity coordinates.""" -MATRIX_EKTA_SPACE_PS_5_TO_XYZ: NDArray = normalised_primary_matrix( +MATRIX_EKTA_SPACE_PS_5_TO_XYZ: NDArrayFloat = normalised_primary_matrix( PRIMARIES_EKTA_SPACE_PS_5, CCS_WHITEPOINT_EKTA_SPACE_PS_5 ) """*Ekta Space PS 5* colourspace to *CIE XYZ* tristimulus values matrix.""" -MATRIX_XYZ_TO_EKTA_SPACE_PS_5: NDArray = np.linalg.inv( +MATRIX_XYZ_TO_EKTA_SPACE_PS_5: NDArrayFloat = np.linalg.inv( MATRIX_EKTA_SPACE_PS_5_TO_XYZ ) """*CIE XYZ* tristimulus values to *Ekta Space PS 5* colourspace matrix.""" diff --git a/colour/models/rgb/datasets/filmlight_e_gamut.py b/colour/models/rgb/datasets/filmlight_e_gamut.py index 8008f0db82..d9ece3de4d 100755 --- a/colour/models/rgb/datasets/filmlight_e_gamut.py +++ b/colour/models/rgb/datasets/filmlight_e_gamut.py @@ -17,7 +17,7 @@ import numpy as np from colour.colorimetry import CCS_ILLUMINANTS -from colour.hints import NDArray +from colour.hints import NDArrayFloat from colour.models.rgb import ( RGB_Colourspace, log_encoding_FilmLightTLog, @@ -41,7 +41,7 @@ "RGB_COLOURSPACE_FILMLIGHT_E_GAMUT", ] -PRIMARIES_FILMLIGHT_E_GAMUT: NDArray = np.array( +PRIMARIES_FILMLIGHT_E_GAMUT: NDArrayFloat = np.array( [ [0.8000, 0.3177], [0.1800, 0.9000], @@ -53,17 +53,17 @@ WHITEPOINT_NAME_FILMLIGHT_E_GAMUT: str = "D65" """*FilmLight E-Gamut* colourspace whitepoint name.""" -CCS_WHITEPOINT_FILMLIGHT_E_GAMUT: NDArray = CCS_ILLUMINANTS[ +CCS_WHITEPOINT_FILMLIGHT_E_GAMUT: NDArrayFloat = CCS_ILLUMINANTS[ "CIE 1931 2 Degree Standard Observer" ][WHITEPOINT_NAME_FILMLIGHT_E_GAMUT] """*FilmLight E-Gamut* colourspace whitepoint chromaticity coordinates.""" -MATRIX_FILMLIGHT_E_GAMUT_TO_XYZ: NDArray = normalised_primary_matrix( +MATRIX_FILMLIGHT_E_GAMUT_TO_XYZ: NDArrayFloat = normalised_primary_matrix( PRIMARIES_FILMLIGHT_E_GAMUT, CCS_WHITEPOINT_FILMLIGHT_E_GAMUT ) """*FilmLight E-Gamut* colourspace to *CIE XYZ* tristimulus values matrix.""" -MATRIX_XYZ_TO_FILMLIGHT_E_GAMUT: NDArray = np.linalg.inv( +MATRIX_XYZ_TO_FILMLIGHT_E_GAMUT: NDArrayFloat = np.linalg.inv( MATRIX_FILMLIGHT_E_GAMUT_TO_XYZ ) """*CIE XYZ* tristimulus values to *FilmLight E-Gamut* colourspace matrix.""" diff --git a/colour/models/rgb/datasets/fujifilm_f_gamut.py b/colour/models/rgb/datasets/fujifilm_f_gamut.py index 6c1b7b385c..1523d75770 100644 --- a/colour/models/rgb/datasets/fujifilm_f_gamut.py +++ b/colour/models/rgb/datasets/fujifilm_f_gamut.py @@ -18,7 +18,7 @@ import numpy as np from colour.colorimetry import CCS_ILLUMINANTS -from colour.hints import NDArray +from colour.hints import NDArrayFloat from colour.models.rgb import ( RGB_Colourspace, log_encoding_FLog, @@ -42,7 +42,7 @@ "RGB_COLOURSPACE_F_GAMUT", ] -PRIMARIES_F_GAMUT: NDArray = np.array( +PRIMARIES_F_GAMUT: NDArrayFloat = np.array( [ [0.70800, 0.29200], [0.17000, 0.79700], @@ -54,17 +54,17 @@ WHITEPOINT_NAME_F_GAMUT: str = "D65" """*Fujifilm F-Gamut* colourspace whitepoint name.""" -CCS_WHITEPOINT_F_GAMUT: NDArray = CCS_ILLUMINANTS[ +CCS_WHITEPOINT_F_GAMUT: NDArrayFloat = CCS_ILLUMINANTS[ "CIE 1931 2 Degree Standard Observer" ][WHITEPOINT_NAME_F_GAMUT] """*Fujifilm F-Gamut* colourspace whitepoint chromaticity coordinates.""" -MATRIX_F_GAMUT_TO_XYZ: NDArray = normalised_primary_matrix( +MATRIX_F_GAMUT_TO_XYZ: NDArrayFloat = normalised_primary_matrix( PRIMARIES_F_GAMUT, CCS_WHITEPOINT_F_GAMUT ) """*Fujifilm F-Gamut* colourspace to *CIE XYZ* tristimulus values matrix.""" -MATRIX_XYZ_TO_F_GAMUT: NDArray = np.linalg.inv(MATRIX_F_GAMUT_TO_XYZ) +MATRIX_XYZ_TO_F_GAMUT: NDArrayFloat = np.linalg.inv(MATRIX_F_GAMUT_TO_XYZ) """*CIE XYZ* tristimulus values to *Fujifilm F-Gamut* colourspace matrix.""" RGB_COLOURSPACE_F_GAMUT: RGB_Colourspace = RGB_Colourspace( diff --git a/colour/models/rgb/datasets/gopro.py b/colour/models/rgb/datasets/gopro.py index 485f56dda8..c693527e85 100644 --- a/colour/models/rgb/datasets/gopro.py +++ b/colour/models/rgb/datasets/gopro.py @@ -29,7 +29,7 @@ import numpy as np from colour.colorimetry import CCS_ILLUMINANTS -from colour.hints import NDArray +from colour.hints import NDArrayFloat from colour.models.rgb import ( RGB_Colourspace, log_decoding_Protune, @@ -53,7 +53,7 @@ "RGB_COLOURSPACE_PROTUNE_NATIVE", ] -PRIMARIES_PROTUNE_NATIVE: NDArray = np.array( +PRIMARIES_PROTUNE_NATIVE: NDArrayFloat = np.array( [ [0.698480461493841, 0.193026445370121], [0.329555378387345, 1.024596624134644], @@ -65,17 +65,17 @@ WHITEPOINT_NAME_PROTUNE_NATIVE: str = "D65" """*Protune Native* colourspace whitepoint name.""" -CCS_WHITEPOINT_PROTUNE_NATIVE: NDArray = CCS_ILLUMINANTS[ +CCS_WHITEPOINT_PROTUNE_NATIVE: NDArrayFloat = CCS_ILLUMINANTS[ "CIE 1931 2 Degree Standard Observer" ][WHITEPOINT_NAME_PROTUNE_NATIVE] """*Protune Native* colourspace whitepoint chromaticity coordinates.""" -MATRIX_PROTUNE_NATIVE_TO_XYZ: NDArray = normalised_primary_matrix( +MATRIX_PROTUNE_NATIVE_TO_XYZ: NDArrayFloat = normalised_primary_matrix( PRIMARIES_PROTUNE_NATIVE, CCS_WHITEPOINT_PROTUNE_NATIVE ) """*Protune Native* colourspace to *CIE XYZ* tristimulus values matrix.""" -MATRIX_XYZ_TO_PROTUNE_NATIVE: NDArray = np.linalg.inv( +MATRIX_XYZ_TO_PROTUNE_NATIVE: NDArrayFloat = np.linalg.inv( MATRIX_PROTUNE_NATIVE_TO_XYZ ) """*CIE XYZ* tristimulus values to *Protune Native* colourspace matrix.""" diff --git a/colour/models/rgb/datasets/itur_bt_2020.py b/colour/models/rgb/datasets/itur_bt_2020.py index 1a5300434a..76967c8172 100644 --- a/colour/models/rgb/datasets/itur_bt_2020.py +++ b/colour/models/rgb/datasets/itur_bt_2020.py @@ -21,7 +21,7 @@ import numpy as np from colour.colorimetry import CCS_ILLUMINANTS -from colour.hints import NDArray +from colour.hints import NDArrayFloat from colour.models.rgb import ( RGB_Colourspace, normalised_primary_matrix, @@ -45,7 +45,7 @@ "RGB_COLOURSPACE_BT2020", ] -PRIMARIES_BT2020: NDArray = np.array( +PRIMARIES_BT2020: NDArrayFloat = np.array( [ [0.7080, 0.2920], [0.1700, 0.7970], @@ -57,14 +57,14 @@ WHITEPOINT_NAME_BT2020: str = "D65" """*RecommendationITU-R BT.2020* colourspace whitepoint name.""" -CCS_WHITEPOINT_BT2020: NDArray = CCS_ILLUMINANTS[ +CCS_WHITEPOINT_BT2020: NDArrayFloat = CCS_ILLUMINANTS[ "CIE 1931 2 Degree Standard Observer" ][WHITEPOINT_NAME_BT2020] """ *RecommendationITU-R BT.2020* colourspace whitepoint chromaticity coordinates. """ -MATRIX_BT2020_TO_XYZ: NDArray = normalised_primary_matrix( +MATRIX_BT2020_TO_XYZ: NDArrayFloat = normalised_primary_matrix( PRIMARIES_BT2020, CCS_WHITEPOINT_BT2020 ) """ @@ -72,7 +72,7 @@ matrix. """ -MATRIX_XYZ_TO_BT2020: NDArray = np.linalg.inv(MATRIX_BT2020_TO_XYZ) +MATRIX_XYZ_TO_BT2020: NDArrayFloat = np.linalg.inv(MATRIX_BT2020_TO_XYZ) """ *CIE XYZ* tristimulus values to *RecommendationITU-R BT.2020* colourspace matrix. diff --git a/colour/models/rgb/datasets/itur_bt_470.py b/colour/models/rgb/datasets/itur_bt_470.py index 03820cde8d..f387f1a98a 100644 --- a/colour/models/rgb/datasets/itur_bt_470.py +++ b/colour/models/rgb/datasets/itur_bt_470.py @@ -22,7 +22,7 @@ from functools import partial from colour.colorimetry import CCS_ILLUMINANTS -from colour.hints import NDArray +from colour.hints import NDArrayFloat from colour.models.rgb import ( RGB_Colourspace, gamma_function, @@ -51,7 +51,7 @@ "RGB_COLOURSPACE_BT470_625", ] -PRIMARIES_BT470_525: NDArray = np.array( +PRIMARIES_BT470_525: NDArrayFloat = np.array( [ [0.6700, 0.3300], [0.2100, 0.7100], @@ -63,7 +63,7 @@ WHITEPOINT_NAME_BT470_525: str = "C" """*Recommendation ITU-R BT.470 - 525* colourspace whitepoint name.""" -CCS_WHITEPOINT_BT470_525: NDArray = CCS_ILLUMINANTS[ +CCS_WHITEPOINT_BT470_525: NDArrayFloat = CCS_ILLUMINANTS[ "CIE 1931 2 Degree Standard Observer" ][WHITEPOINT_NAME_BT470_525] """ @@ -71,7 +71,7 @@ coordinates. """ -MATRIX_BT470_525_TO_XYZ: NDArray = normalised_primary_matrix( +MATRIX_BT470_525_TO_XYZ: NDArrayFloat = normalised_primary_matrix( PRIMARIES_BT470_525, CCS_WHITEPOINT_BT470_525 ) """ @@ -79,7 +79,7 @@ matrix. """ -MATRIX_XYZ_TO_BT470_525: NDArray = np.linalg.inv(MATRIX_BT470_525_TO_XYZ) +MATRIX_XYZ_TO_BT470_525: NDArrayFloat = np.linalg.inv(MATRIX_BT470_525_TO_XYZ) """ *CIE XYZ* tristimulus values to *Recommendation ITU-R BT.470 - 525* colourspace matrix. @@ -103,7 +103,7 @@ :cite:`InternationalTelecommunicationUnion1998a` """ -PRIMARIES_BT470_625: NDArray = np.array( +PRIMARIES_BT470_625: NDArrayFloat = np.array( [ [0.6400, 0.3300], [0.2900, 0.6000], @@ -115,7 +115,7 @@ WHITEPOINT_NAME_BT470_625: str = "D65" """*Recommendation ITU-R BT.470 - 625* colourspace whitepoint name.""" -CCS_WHITEPOINT_BT470_625: NDArray = CCS_ILLUMINANTS[ +CCS_WHITEPOINT_BT470_625: NDArrayFloat = CCS_ILLUMINANTS[ "CIE 1931 2 Degree Standard Observer" ][WHITEPOINT_NAME_BT470_625] """ @@ -123,7 +123,7 @@ coordinates. """ -MATRIX_BT470_625_TO_XYZ: NDArray = normalised_primary_matrix( +MATRIX_BT470_625_TO_XYZ: NDArrayFloat = normalised_primary_matrix( PRIMARIES_BT470_625, CCS_WHITEPOINT_BT470_625 ) """ @@ -131,7 +131,7 @@ matrix. """ -MATRIX_XYZ_TO_BT470_625: NDArray = np.linalg.inv(MATRIX_BT470_625_TO_XYZ) +MATRIX_XYZ_TO_BT470_625: NDArrayFloat = np.linalg.inv(MATRIX_BT470_625_TO_XYZ) """ *CIE XYZ* tristimulus values to *Recommendation ITU-R BT.470 - 625* colourspace matrix. diff --git a/colour/models/rgb/datasets/itur_bt_709.py b/colour/models/rgb/datasets/itur_bt_709.py index 7daecf5dff..b694b36dfb 100644 --- a/colour/models/rgb/datasets/itur_bt_709.py +++ b/colour/models/rgb/datasets/itur_bt_709.py @@ -21,7 +21,7 @@ import numpy as np from colour.colorimetry import CCS_ILLUMINANTS -from colour.hints import NDArray +from colour.hints import NDArrayFloat from colour.models.rgb import ( RGB_Colourspace, oetf_BT709, @@ -45,7 +45,7 @@ "RGB_COLOURSPACE_BT709", ] -PRIMARIES_BT709: NDArray = np.array( +PRIMARIES_BT709: NDArrayFloat = np.array( [ [0.6400, 0.3300], [0.3000, 0.6000], @@ -57,14 +57,14 @@ WHITEPOINT_NAME_BT709: str = "D65" """*Recommendation ITU-R BT.709* colourspace whitepoint name.""" -CCS_WHITEPOINT_BT709: NDArray = CCS_ILLUMINANTS[ +CCS_WHITEPOINT_BT709: NDArrayFloat = CCS_ILLUMINANTS[ "CIE 1931 2 Degree Standard Observer" ][WHITEPOINT_NAME_BT709] """ *Recommendation ITU-R BT.709* colourspace whitepoint chromaticity coordinates. """ -MATRIX_BT709_TO_XYZ: NDArray = normalised_primary_matrix( +MATRIX_BT709_TO_XYZ: NDArrayFloat = normalised_primary_matrix( PRIMARIES_BT709, CCS_WHITEPOINT_BT709 ) """ @@ -72,7 +72,7 @@ matrix. """ -MATRIX_XYZ_TO_BT709: NDArray = np.linalg.inv(MATRIX_BT709_TO_XYZ) +MATRIX_XYZ_TO_BT709: NDArrayFloat = np.linalg.inv(MATRIX_BT709_TO_XYZ) """ *CIE XYZ* tristimulus values to *Recommendation ITU-R BT.709* colourspace matrix. diff --git a/colour/models/rgb/datasets/itut_h_273.py b/colour/models/rgb/datasets/itut_h_273.py index 893c748709..3a7b748ac9 100644 --- a/colour/models/rgb/datasets/itut_h_273.py +++ b/colour/models/rgb/datasets/itut_h_273.py @@ -20,7 +20,7 @@ import numpy as np -from colour.hints import NDArray +from colour.hints import NDArrayFloat from colour.models.rgb import ( RGB_Colourspace, linear_function, @@ -49,7 +49,7 @@ "RGB_COLOURSPACE_H273_22_UNSPECIFIED", ] -PRIMARIES_H273_GENERIC_FILM: NDArray = np.array( +PRIMARIES_H273_GENERIC_FILM: NDArrayFloat = np.array( [ [0.681, 0.319], # Wratten 25 [0.243, 0.692], # Wratten 58 @@ -73,7 +73,7 @@ - :cite:`InternationalTelecommunicationUnion2021` """ -CCS_WHITEPOINT_H273_GENERIC_FILM: NDArray = np.array([0.310, 0.316]) +CCS_WHITEPOINT_H273_GENERIC_FILM: NDArrayFloat = np.array([0.310, 0.316]) """ Whitepoint chromaticity coordinates for *Generic Film* (colour filters using Illuminant C). @@ -89,7 +89,7 @@ - :cite:`InternationalTelecommunicationUnion2021` """ -MATRIX_H273_GENERIC_FILM_RGB_TO_XYZ: NDArray = normalised_primary_matrix( +MATRIX_H273_GENERIC_FILM_RGB_TO_XYZ: NDArrayFloat = normalised_primary_matrix( PRIMARIES_H273_GENERIC_FILM, CCS_WHITEPOINT_H273_GENERIC_FILM ) """ @@ -101,7 +101,7 @@ - :cite:`InternationalTelecommunicationUnion2021` """ -MATRIX_XYZ_TO_H273_GENERIC_FILM_RGB: NDArray = np.linalg.inv( +MATRIX_XYZ_TO_H273_GENERIC_FILM_RGB: NDArrayFloat = np.linalg.inv( MATRIX_H273_GENERIC_FILM_RGB_TO_XYZ ) """ @@ -133,7 +133,7 @@ """ -PRIMARIES_H273_22_UNSPECIFIED: NDArray = np.array( +PRIMARIES_H273_22_UNSPECIFIED: NDArrayFloat = np.array( [ [0.630, 0.340], [0.295, 0.605], @@ -159,7 +159,7 @@ - :cite:`InternationalTelecommunicationUnion2021` """ -CCS_WHITEPOINT_H273_22_UNSPECIFIED: NDArray = np.array([0.3127, 0.3290]) +CCS_WHITEPOINT_H273_22_UNSPECIFIED: NDArrayFloat = np.array([0.3127, 0.3290]) """ Whitepoint chromaticity coordinates for row *22* as given in *Table 2 - Interpretation of colour primaries (ColourPrimaries) value*. @@ -169,8 +169,10 @@ - :cite:`InternationalTelecommunicationUnion2021` """ -MATRIX_H273_22_UNSPECIFIED_RGB_TO_XYZ: NDArray = normalised_primary_matrix( - PRIMARIES_H273_22_UNSPECIFIED, CCS_WHITEPOINT_H273_22_UNSPECIFIED +MATRIX_H273_22_UNSPECIFIED_RGB_TO_XYZ: NDArrayFloat = ( + normalised_primary_matrix( + PRIMARIES_H273_22_UNSPECIFIED, CCS_WHITEPOINT_H273_22_UNSPECIFIED + ) ) """ Row *22* colourspace as given in @@ -182,7 +184,7 @@ - :cite:`InternationalTelecommunicationUnion2021` """ -MATRIX_XYZ_TO_H273_22_UNSPECIFIED_RGB: NDArray = np.linalg.inv( +MATRIX_XYZ_TO_H273_22_UNSPECIFIED_RGB: NDArrayFloat = np.linalg.inv( MATRIX_H273_22_UNSPECIFIED_RGB_TO_XYZ ) """ diff --git a/colour/models/rgb/datasets/max_rgb.py b/colour/models/rgb/datasets/max_rgb.py index 3b264abbf5..021380c81e 100644 --- a/colour/models/rgb/datasets/max_rgb.py +++ b/colour/models/rgb/datasets/max_rgb.py @@ -18,7 +18,7 @@ from functools import partial from colour.colorimetry import CCS_ILLUMINANTS -from colour.hints import NDArray +from colour.hints import NDArrayFloat from colour.models.rgb import ( RGB_Colourspace, gamma_function, @@ -41,7 +41,7 @@ "RGB_COLOURSPACE_MAX_RGB", ] -PRIMARIES_MAX_RGB: NDArray = np.array( +PRIMARIES_MAX_RGB: NDArrayFloat = np.array( [ [0.73413379, 0.26586621], [0.10039113, 0.89960887], @@ -53,17 +53,17 @@ WHITEPOINT_NAME_MAX_RGB: str = "D50" """*Max RGB* colourspace whitepoint name.""" -CCS_WHITEPOINT_MAX_RGB: NDArray = CCS_ILLUMINANTS[ +CCS_WHITEPOINT_MAX_RGB: NDArrayFloat = CCS_ILLUMINANTS[ "CIE 1931 2 Degree Standard Observer" ][WHITEPOINT_NAME_MAX_RGB] """*Max RGB* colourspace whitepoint chromaticity coordinates.""" -MATRIX_MAX_RGB_TO_XYZ: NDArray = normalised_primary_matrix( +MATRIX_MAX_RGB_TO_XYZ: NDArrayFloat = normalised_primary_matrix( PRIMARIES_MAX_RGB, CCS_WHITEPOINT_MAX_RGB ) """*Max RGB* colourspace to *CIE XYZ* tristimulus values matrix.""" -MATRIX_XYZ_TO_MAX_RGB: NDArray = np.linalg.inv(MATRIX_MAX_RGB_TO_XYZ) +MATRIX_XYZ_TO_MAX_RGB: NDArrayFloat = np.linalg.inv(MATRIX_MAX_RGB_TO_XYZ) """*CIE XYZ* tristimulus values to *Max RGB* colourspace matrix.""" RGB_COLOURSPACE_MAX_RGB: RGB_Colourspace = RGB_Colourspace( diff --git a/colour/models/rgb/datasets/nikon_n_gamut.py b/colour/models/rgb/datasets/nikon_n_gamut.py index f03487a4ca..54414788e0 100644 --- a/colour/models/rgb/datasets/nikon_n_gamut.py +++ b/colour/models/rgb/datasets/nikon_n_gamut.py @@ -16,7 +16,7 @@ from __future__ import annotations -from colour.hints import NDArray +from colour.hints import NDArrayFloat from colour.models.rgb import ( RGB_Colourspace, log_encoding_NLog, @@ -46,7 +46,7 @@ "RGB_COLOURSPACE_N_GAMUT", ] -PRIMARIES_N_GAMUT: NDArray = PRIMARIES_BT2020 +PRIMARIES_N_GAMUT: NDArrayFloat = PRIMARIES_BT2020 """ *Nikon N-Gamut* colourspace primaries. @@ -59,13 +59,13 @@ WHITEPOINT_NAME_N_GAMUT: str = WHITEPOINT_NAME_BT2020 """*Nikon N-Gamut* colourspace whitepoint name.""" -CCS_WHITEPOINT_N_GAMUT: NDArray = CCS_WHITEPOINT_BT2020 +CCS_WHITEPOINT_N_GAMUT: NDArrayFloat = CCS_WHITEPOINT_BT2020 """*Nikon N-Gamut* colourspace whitepoint.""" -MATRIX_N_GAMUT_TO_XYZ: NDArray = MATRIX_BT2020_TO_XYZ +MATRIX_N_GAMUT_TO_XYZ: NDArrayFloat = MATRIX_BT2020_TO_XYZ """*Nikon N-Gamut* colourspace to *CIE XYZ* tristimulus values matrix.""" -MATRIX_XYZ_TO_N_GAMUT: NDArray = MATRIX_XYZ_TO_BT2020 +MATRIX_XYZ_TO_N_GAMUT: NDArrayFloat = MATRIX_XYZ_TO_BT2020 """*CIE XYZ* tristimulus values to *Nikon N-Gamut* colourspace matrix.""" RGB_COLOURSPACE_N_GAMUT: RGB_Colourspace = RGB_Colourspace( diff --git a/colour/models/rgb/datasets/ntsc.py b/colour/models/rgb/datasets/ntsc.py index 1b20774c7d..f0a320a406 100644 --- a/colour/models/rgb/datasets/ntsc.py +++ b/colour/models/rgb/datasets/ntsc.py @@ -22,7 +22,7 @@ from __future__ import annotations -from colour.hints import NDArray +from colour.hints import NDArrayFloat from colour.models.rgb import RGB_Colourspace from colour.models.rgb.datasets.itur_bt_470 import ( PRIMARIES_BT470_525, @@ -63,19 +63,19 @@ "RGB_COLOURSPACE_NTSC1987", ] -PRIMARIES_NTSC1953: NDArray = PRIMARIES_BT470_525 +PRIMARIES_NTSC1953: NDArrayFloat = PRIMARIES_BT470_525 """*NTSC (1953)* colourspace primaries.""" WHITEPOINT_NAME_NTSC1953: str = WHITEPOINT_NAME_BT470_525 """*NTSC (1953)* colourspace whitepoint name.""" -CCS_WHITEPOINT_NTSC1953: NDArray = CCS_WHITEPOINT_BT470_525 +CCS_WHITEPOINT_NTSC1953: NDArrayFloat = CCS_WHITEPOINT_BT470_525 """*NTSC (1953)* colourspace whitepoint chromaticity coordinates.""" -MATRIX_NTSC1953_TO_XYZ: NDArray = MATRIX_BT470_525_TO_XYZ +MATRIX_NTSC1953_TO_XYZ: NDArrayFloat = MATRIX_BT470_525_TO_XYZ """*NTSC (1953)* colourspace to *CIE XYZ* tristimulus values matrix.""" -MATRIX_XYZ_TO_NTSC1953: NDArray = MATRIX_XYZ_TO_BT470_525 +MATRIX_XYZ_TO_NTSC1953: NDArrayFloat = MATRIX_XYZ_TO_BT470_525 """*CIE XYZ* tristimulus values to *NTSC (1953)* colourspace matrix.""" RGB_COLOURSPACE_NTSC1953: RGB_Colourspace = RGB_Colourspace( @@ -96,19 +96,19 @@ :cite:`InternationalTelecommunicationUnion1998a` """ -PRIMARIES_NTSC1987: NDArray = PRIMARIES_SMPTE_C +PRIMARIES_NTSC1987: NDArrayFloat = PRIMARIES_SMPTE_C """*NTSC (1987)* colourspace primaries.""" WHITEPOINT_NAME_NTSC1987: str = WHITEPOINT_NAME_SMPTE_C """*NTSC (1987)* colourspace whitepoint name.""" -CCS_WHITEPOINT_NTSC1987: NDArray = CCS_WHITEPOINT_SMPTE_C +CCS_WHITEPOINT_NTSC1987: NDArrayFloat = CCS_WHITEPOINT_SMPTE_C """*NTSC (1987)* colourspace whitepoint chromaticity coordinates.""" -MATRIX_NTSC1987_TO_XYZ: NDArray = MATRIX_SMPTE_C_TO_XYZ +MATRIX_NTSC1987_TO_XYZ: NDArrayFloat = MATRIX_SMPTE_C_TO_XYZ """*NTSC (1987)* colourspace to *CIE XYZ* tristimulus values matrix.""" -MATRIX_XYZ_TO_NTSC1987: NDArray = MATRIX_XYZ_TO_SMPTE_C +MATRIX_XYZ_TO_NTSC1987: NDArrayFloat = MATRIX_XYZ_TO_SMPTE_C """*CIE XYZ* tristimulus values to *NTSC (1987)* colourspace matrix.""" RGB_COLOURSPACE_NTSC1987: RGB_Colourspace = RGB_Colourspace( diff --git a/colour/models/rgb/datasets/p3_d65.py b/colour/models/rgb/datasets/p3_d65.py index 60dc97e02d..3ccde0e4d5 100644 --- a/colour/models/rgb/datasets/p3_d65.py +++ b/colour/models/rgb/datasets/p3_d65.py @@ -13,7 +13,7 @@ from functools import partial from colour.colorimetry import CCS_ILLUMINANTS -from colour.hints import NDArray +from colour.hints import NDArrayFloat from colour.models.rgb import ( RGB_Colourspace, gamma_function, @@ -36,7 +36,7 @@ "RGB_COLOURSPACE_P3_D65", ] -PRIMARIES_P3_D65: NDArray = np.array( +PRIMARIES_P3_D65: NDArrayFloat = np.array( [ [0.6800, 0.3200], [0.2650, 0.6900], @@ -48,17 +48,17 @@ WHITEPOINT_NAME_P3_D65: str = "D65" """*P3-D65* colourspace whitepoint name.""" -CCS_WHITEPOINT_P3_D65: NDArray = CCS_ILLUMINANTS[ +CCS_WHITEPOINT_P3_D65: NDArrayFloat = CCS_ILLUMINANTS[ "CIE 1931 2 Degree Standard Observer" ][WHITEPOINT_NAME_P3_D65] """*P3-D65* colourspace whitepoint chromaticity coordinates.""" -MATRIX_P3_D65_TO_XYZ: NDArray = normalised_primary_matrix( +MATRIX_P3_D65_TO_XYZ: NDArrayFloat = normalised_primary_matrix( PRIMARIES_P3_D65, CCS_WHITEPOINT_P3_D65 ) """*P3-D65* colourspace to *CIE XYZ* tristimulus values matrix.""" -MATRIX_XYZ_TO_P3_D65: NDArray = np.linalg.inv(MATRIX_P3_D65_TO_XYZ) +MATRIX_XYZ_TO_P3_D65: NDArrayFloat = np.linalg.inv(MATRIX_P3_D65_TO_XYZ) """*CIE XYZ* tristimulus values to *P3-D65* colourspace matrix.""" RGB_COLOURSPACE_P3_D65: RGB_Colourspace = RGB_Colourspace( diff --git a/colour/models/rgb/datasets/pal_secam.py b/colour/models/rgb/datasets/pal_secam.py index d0d74f91ea..1b2162ecbb 100644 --- a/colour/models/rgb/datasets/pal_secam.py +++ b/colour/models/rgb/datasets/pal_secam.py @@ -17,7 +17,7 @@ from __future__ import annotations -from colour.hints import NDArray +from colour.hints import NDArrayFloat from colour.models.rgb import RGB_Colourspace from colour.models.rgb.datasets.itur_bt_470 import ( PRIMARIES_BT470_625, @@ -44,19 +44,19 @@ "RGB_COLOURSPACE_PAL_SECAM", ] -PRIMARIES_PAL_SECAM: NDArray = PRIMARIES_BT470_625 +PRIMARIES_PAL_SECAM: NDArrayFloat = PRIMARIES_BT470_625 """*Pal/Secam* colourspace primaries.""" WHITEPOINT_NAME_PAL_SECAM: str = WHITEPOINT_NAME_BT470_625 """*Pal/Secam* colourspace whitepoint name.""" -CCS_WHITEPOINT_PAL_SECAM: NDArray = CCS_WHITEPOINT_BT470_625 +CCS_WHITEPOINT_PAL_SECAM: NDArrayFloat = CCS_WHITEPOINT_BT470_625 """*Pal/Secam* colourspace whitepoint chromaticity coordinates.""" -MATRIX_PAL_SECAM_TO_XYZ: NDArray = MATRIX_BT470_625_TO_XYZ +MATRIX_PAL_SECAM_TO_XYZ: NDArrayFloat = MATRIX_BT470_625_TO_XYZ """*Pal/Secam* colourspace to *CIE XYZ* tristimulus values matrix.""" -MATRIX_XYZ_TO_PAL_SECAM: NDArray = MATRIX_XYZ_TO_BT470_625 +MATRIX_XYZ_TO_PAL_SECAM: NDArrayFloat = MATRIX_XYZ_TO_BT470_625 """*CIE XYZ* tristimulus values to *Pal/Secam* colourspace matrix.""" RGB_COLOURSPACE_PAL_SECAM: RGB_Colourspace = RGB_Colourspace( diff --git a/colour/models/rgb/datasets/panasonic_v_gamut.py b/colour/models/rgb/datasets/panasonic_v_gamut.py index 5881b0a0da..86bd7445eb 100644 --- a/colour/models/rgb/datasets/panasonic_v_gamut.py +++ b/colour/models/rgb/datasets/panasonic_v_gamut.py @@ -18,7 +18,7 @@ import numpy as np from colour.colorimetry import CCS_ILLUMINANTS -from colour.hints import NDArray +from colour.hints import NDArrayFloat from colour.models.rgb import ( RGB_Colourspace, log_encoding_VLog, @@ -41,7 +41,7 @@ "RGB_COLOURSPACE_V_GAMUT", ] -PRIMARIES_V_GAMUT: NDArray = np.array( +PRIMARIES_V_GAMUT: NDArrayFloat = np.array( [ [0.7300, 0.2800], [0.1650, 0.8400], @@ -53,12 +53,12 @@ WHITEPOINT_NAME_V_GAMUT: str = "D65" """*Panasonic V-Gamut* colourspace whitepoint name.""" -CCS_WHITEPOINT_V_GAMUT: NDArray = CCS_ILLUMINANTS[ +CCS_WHITEPOINT_V_GAMUT: NDArrayFloat = CCS_ILLUMINANTS[ "CIE 1931 2 Degree Standard Observer" ][WHITEPOINT_NAME_V_GAMUT] """*Panasonic V-Gamut* colourspace whitepoint chromaticity coordinates.""" -MATRIX_V_GAMUT_TO_XYZ: NDArray = np.array( +MATRIX_V_GAMUT_TO_XYZ: NDArrayFloat = np.array( [ [0.679644, 0.152211, 0.118600], [0.260686, 0.774894, -0.035580], @@ -67,7 +67,7 @@ ) """*Panasonic V-Gamut* colourspace to *CIE XYZ* tristimulus values matrix.""" -MATRIX_XYZ_TO_V_GAMUT: NDArray = np.array( +MATRIX_XYZ_TO_V_GAMUT: NDArrayFloat = np.array( [ [1.589012, -0.313204, -0.180965], [-0.534053, 1.396011, 0.102458], diff --git a/colour/models/rgb/datasets/red.py b/colour/models/rgb/datasets/red.py index 3396759331..963b6c1776 100644 --- a/colour/models/rgb/datasets/red.py +++ b/colour/models/rgb/datasets/red.py @@ -30,7 +30,7 @@ import numpy as np from colour.colorimetry import CCS_ILLUMINANTS -from colour.hints import NDArray +from colour.hints import NDArrayFloat from colour.models.rgb import ( RGB_Colourspace, normalised_primary_matrix, @@ -92,7 +92,7 @@ "RGB_COLOURSPACE_RED_WIDE_GAMUT_RGB", ] -PRIMARIES_RED_COLOR: NDArray = np.array( +PRIMARIES_RED_COLOR: NDArrayFloat = np.array( [ [0.701058563171395, 0.330180975940326], [0.298811317306316, 0.625169245953133], @@ -104,17 +104,17 @@ WHITEPOINT_NAME_RED_COLOR: str = "D65" """*REDcolor* colourspace whitepoint name.""" -CCS_WHITEPOINT_RED_COLOR: NDArray = CCS_ILLUMINANTS[ +CCS_WHITEPOINT_RED_COLOR: NDArrayFloat = CCS_ILLUMINANTS[ "CIE 1931 2 Degree Standard Observer" ][WHITEPOINT_NAME_RED_COLOR] """*REDcolor* colourspace whitepoint chromaticity coordinates.""" -MATRIX_RED_COLOR_TO_XYZ: NDArray = normalised_primary_matrix( +MATRIX_RED_COLOR_TO_XYZ: NDArrayFloat = normalised_primary_matrix( PRIMARIES_RED_COLOR, CCS_WHITEPOINT_RED_COLOR ) """*REDcolor* colourspace to *CIE XYZ* tristimulus values matrix.""" -MATRIX_XYZ_TO_RED_COLOR: NDArray = np.linalg.inv(MATRIX_RED_COLOR_TO_XYZ) +MATRIX_XYZ_TO_RED_COLOR: NDArrayFloat = np.linalg.inv(MATRIX_RED_COLOR_TO_XYZ) """*CIE XYZ* tristimulus values to *REDcolor* colourspace matrix.""" RGB_COLOURSPACE_RED_COLOR: RGB_Colourspace = RGB_Colourspace( @@ -135,7 +135,7 @@ :cite:`Mansencal2015d`, :cite:`SonyImageworks2012a` """ -PRIMARIES_RED_COLOR_2: NDArray = np.array( +PRIMARIES_RED_COLOR_2: NDArrayFloat = np.array( [ [0.897407221929776, 0.330776225980398], [0.296022094516625, 0.684635550900945], @@ -147,15 +147,17 @@ WHITEPOINT_NAME_RED_COLOR_2: str = WHITEPOINT_NAME_RED_COLOR """*REDcolor2* colourspace whitepoint name.""" -CCS_WHITEPOINT_RED_COLOR_2: NDArray = CCS_WHITEPOINT_RED_COLOR +CCS_WHITEPOINT_RED_COLOR_2: NDArrayFloat = CCS_WHITEPOINT_RED_COLOR """*REDcolor2* colourspace whitepoint chromaticity coordinates.""" -MATRIX_RED_COLOR_2_TO_XYZ: NDArray = normalised_primary_matrix( +MATRIX_RED_COLOR_2_TO_XYZ: NDArrayFloat = normalised_primary_matrix( PRIMARIES_RED_COLOR_2, CCS_WHITEPOINT_RED_COLOR_2 ) """*REDcolor2* colourspace to *CIE XYZ* tristimulus values matrix.""" -MATRIX_XYZ_TO_RED_COLOR_2: NDArray = np.linalg.inv(MATRIX_RED_COLOR_2_TO_XYZ) +MATRIX_XYZ_TO_RED_COLOR_2: NDArrayFloat = np.linalg.inv( + MATRIX_RED_COLOR_2_TO_XYZ +) """*CIE XYZ* tristimulus values to *REDcolor2* colourspace matrix.""" RGB_COLOURSPACE_RED_COLOR_2: RGB_Colourspace = RGB_Colourspace( @@ -176,7 +178,7 @@ :cite:`Mansencal2015d`, :cite:`SonyImageworks2012a` """ -PRIMARIES_RED_COLOR_3: NDArray = np.array( +PRIMARIES_RED_COLOR_3: NDArrayFloat = np.array( [ [0.702598658589917, 0.330185588938484], [0.295782235737268, 0.689748258397534], @@ -188,15 +190,17 @@ WHITEPOINT_NAME_RED_COLOR_3: str = WHITEPOINT_NAME_RED_COLOR """*REDcolor3* colourspace whitepoint name.""" -CCS_WHITEPOINT_RED_COLOR_3: NDArray = CCS_WHITEPOINT_RED_COLOR +CCS_WHITEPOINT_RED_COLOR_3: NDArrayFloat = CCS_WHITEPOINT_RED_COLOR """*REDcolor3* colourspace whitepoint chromaticity coordinates.""" -MATRIX_RED_COLOR_3_TO_XYZ: NDArray = normalised_primary_matrix( +MATRIX_RED_COLOR_3_TO_XYZ: NDArrayFloat = normalised_primary_matrix( PRIMARIES_RED_COLOR_3, CCS_WHITEPOINT_RED_COLOR_3 ) """*REDcolor3* colourspace to *CIE XYZ* tristimulus values matrix.""" -MATRIX_XYZ_TO_RED_COLOR_3: NDArray = np.linalg.inv(MATRIX_RED_COLOR_3_TO_XYZ) +MATRIX_XYZ_TO_RED_COLOR_3: NDArrayFloat = np.linalg.inv( + MATRIX_RED_COLOR_3_TO_XYZ +) """*CIE XYZ* tristimulus values to *REDcolor3* colourspace matrix.""" RGB_COLOURSPACE_RED_COLOR_3: RGB_Colourspace = RGB_Colourspace( @@ -217,7 +221,7 @@ :cite:`Mansencal2015d`, :cite:`SonyImageworks2012a` """ -PRIMARIES_RED_COLOR_4: NDArray = np.array( +PRIMARIES_RED_COLOR_4: NDArrayFloat = np.array( [ [0.702598154635438, 0.330185096210515], [0.295782328047083, 0.689748253964859], @@ -229,15 +233,17 @@ WHITEPOINT_NAME_RED_COLOR_4: str = WHITEPOINT_NAME_RED_COLOR """*REDcolor4* colourspace whitepoint name.""" -CCS_WHITEPOINT_RED_COLOR_4: NDArray = CCS_WHITEPOINT_RED_COLOR +CCS_WHITEPOINT_RED_COLOR_4: NDArrayFloat = CCS_WHITEPOINT_RED_COLOR """*REDcolor4* colourspace whitepoint chromaticity coordinates.""" -MATRIX_RED_COLOR_4_TO_XYZ: NDArray = normalised_primary_matrix( +MATRIX_RED_COLOR_4_TO_XYZ: NDArrayFloat = normalised_primary_matrix( PRIMARIES_RED_COLOR_4, CCS_WHITEPOINT_RED_COLOR_4 ) """*REDcolor4* colourspace to *CIE XYZ* tristimulus values matrix.""" -MATRIX_XYZ_TO_RED_COLOR_4: NDArray = np.linalg.inv(MATRIX_RED_COLOR_4_TO_XYZ) +MATRIX_XYZ_TO_RED_COLOR_4: NDArrayFloat = np.linalg.inv( + MATRIX_RED_COLOR_4_TO_XYZ +) """*CIE XYZ* tristimulus values to *REDcolor4* colourspace matrix.""" RGB_COLOURSPACE_RED_COLOR_4: RGB_Colourspace = RGB_Colourspace( @@ -258,7 +264,7 @@ :cite:`Mansencal2015d`, :cite:`SonyImageworks2012a` """ -PRIMARIES_DRAGON_COLOR: NDArray = np.array( +PRIMARIES_DRAGON_COLOR: NDArrayFloat = np.array( [ [0.758655892599321, 0.330355348611293], [0.294923619810175, 0.708053242065117], @@ -270,15 +276,17 @@ WHITEPOINT_NAME_DRAGON_COLOR: str = WHITEPOINT_NAME_RED_COLOR """*DRAGONcolor* colourspace whitepoint name.""" -CCS_WHITEPOINT_DRAGON_COLOR: NDArray = CCS_WHITEPOINT_RED_COLOR +CCS_WHITEPOINT_DRAGON_COLOR: NDArrayFloat = CCS_WHITEPOINT_RED_COLOR """*DRAGONcolor* colourspace whitepoint chromaticity coordinates.""" -MATRIX_DRAGON_COLOR_TO_XYZ: NDArray = normalised_primary_matrix( +MATRIX_DRAGON_COLOR_TO_XYZ: NDArrayFloat = normalised_primary_matrix( PRIMARIES_DRAGON_COLOR, CCS_WHITEPOINT_DRAGON_COLOR ) """*DRAGONcolor* colourspace to *CIE XYZ* tristimulus values matrix.""" -MATRIX_XYZ_TO_DRAGON_COLOR: NDArray = np.linalg.inv(MATRIX_DRAGON_COLOR_TO_XYZ) +MATRIX_XYZ_TO_DRAGON_COLOR: NDArrayFloat = np.linalg.inv( + MATRIX_DRAGON_COLOR_TO_XYZ +) """*CIE XYZ* tristimulus values to *DRAGONcolor* colourspace matrix.""" RGB_COLOURSPACE_DRAGON_COLOR: RGB_Colourspace = RGB_Colourspace( @@ -299,7 +307,7 @@ :cite:`Mansencal2015d`, :cite:`SonyImageworks2012a` """ -PRIMARIES_DRAGON_COLOR_2: NDArray = np.array( +PRIMARIES_DRAGON_COLOR_2: NDArrayFloat = np.array( [ [0.758656214177604, 0.330355835762678], [0.294923887732982, 0.708053363192126], @@ -311,15 +319,15 @@ WHITEPOINT_NAME_DRAGON_COLOR_2: str = WHITEPOINT_NAME_RED_COLOR """*DRAGONcolor2* colourspace whitepoint name.""" -CCS_WHITEPOINT_DRAGON_COLOR_2: NDArray = CCS_WHITEPOINT_RED_COLOR +CCS_WHITEPOINT_DRAGON_COLOR_2: NDArrayFloat = CCS_WHITEPOINT_RED_COLOR """*DRAGONcolor2* colourspace whitepoint chromaticity coordinates.""" -MATRIX_DRAGON_COLOR_2_TO_XYZ: NDArray = normalised_primary_matrix( +MATRIX_DRAGON_COLOR_2_TO_XYZ: NDArrayFloat = normalised_primary_matrix( PRIMARIES_DRAGON_COLOR_2, CCS_WHITEPOINT_DRAGON_COLOR_2 ) """*DRAGONcolor2* colourspace to *CIE XYZ* tristimulus values matrix.""" -MATRIX_XYZ_TO_DRAGON_COLOR_2: NDArray = np.linalg.inv( +MATRIX_XYZ_TO_DRAGON_COLOR_2: NDArrayFloat = np.linalg.inv( MATRIX_DRAGON_COLOR_2_TO_XYZ ) """*CIE XYZ* tristimulus values to *DRAGONcolor2* colourspace matrix.""" @@ -342,7 +350,7 @@ :cite:`Mansencal2015d`, :cite:`SonyImageworks2012a` """ -PRIMARIES_RED_WIDE_GAMUT_RGB: NDArray = np.array( +PRIMARIES_RED_WIDE_GAMUT_RGB: NDArrayFloat = np.array( [ [0.780308, 0.304253], [0.121595, 1.493994], @@ -357,7 +365,7 @@ CCS_WHITEPOINT_RED_WIDE_GAMUT_RGB = CCS_WHITEPOINT_RED_COLOR """*REDWideGamutRGB* colourspace whitepoint chromaticity coordinates.""" -MATRIX_RED_WIDE_GAMUT_RGB_TO_XYZ: NDArray = np.array( +MATRIX_RED_WIDE_GAMUT_RGB_TO_XYZ: NDArrayFloat = np.array( [ [0.735275, 0.068609, 0.146571], [0.286694, 0.842979, -0.129673], @@ -366,7 +374,7 @@ ) """*REDWideGamutRGB* colourspace to *CIE XYZ* tristimulus values matrix.""" -MATRIX_XYZ_TO_RED_WIDE_GAMUT_RGB: NDArray = np.linalg.inv( +MATRIX_XYZ_TO_RED_WIDE_GAMUT_RGB: NDArrayFloat = np.linalg.inv( MATRIX_RED_WIDE_GAMUT_RGB_TO_XYZ ) """*CIE XYZ* tristimulus values to *REDWideGamutRGB* colourspace matrix.""" diff --git a/colour/models/rgb/datasets/rimm_romm_rgb.py b/colour/models/rgb/datasets/rimm_romm_rgb.py index d4b532aaa9..5a41a72882 100644 --- a/colour/models/rgb/datasets/rimm_romm_rgb.py +++ b/colour/models/rgb/datasets/rimm_romm_rgb.py @@ -23,7 +23,7 @@ import numpy as np from colour.colorimetry import CCS_ILLUMINANTS -from colour.hints import NDArray +from colour.hints import NDArrayFloat from colour.models.rgb import ( RGB_Colourspace, cctf_encoding_ROMMRGB, @@ -69,7 +69,7 @@ "RGB_COLOURSPACE_PROPHOTO_RGB", ] -PRIMARIES_ROMM_RGB: NDArray = np.array( +PRIMARIES_ROMM_RGB: NDArrayFloat = np.array( [ [0.7347, 0.2653], [0.1596, 0.8404], @@ -81,12 +81,12 @@ WHITEPOINT_NAME_ROMM_RGB: str = "D50" """*ROMM RGB* colourspace whitepoint name.""" -CCS_WHITEPOINT_ROMM_RGB: NDArray = CCS_ILLUMINANTS[ +CCS_WHITEPOINT_ROMM_RGB: NDArrayFloat = CCS_ILLUMINANTS[ "CIE 1931 2 Degree Standard Observer" ][WHITEPOINT_NAME_ROMM_RGB] """*ROMM RGB* colourspace whitepoint chromaticity coordinates.""" -MATRIX_ROMM_RGB_TO_XYZ: NDArray = np.array( +MATRIX_ROMM_RGB_TO_XYZ: NDArrayFloat = np.array( [ [0.7977, 0.1352, 0.0313], [0.2880, 0.7119, 0.0001], @@ -95,7 +95,7 @@ ) """*ROMM RGB* colourspace to *CIE XYZ* tristimulus values matrix.""" -MATRIX_XYZ_TO_ROMM_RGB: NDArray = np.array( +MATRIX_XYZ_TO_ROMM_RGB: NDArrayFloat = np.array( [ [1.3460, -0.2556, -0.0511], [-0.5446, 1.5082, 0.0205], @@ -122,19 +122,19 @@ :cite:`ANSI2003a`, :cite:`Spaulding2000b` """ -PRIMARIES_RIMM_RGB: NDArray = PRIMARIES_ROMM_RGB +PRIMARIES_RIMM_RGB: NDArrayFloat = PRIMARIES_ROMM_RGB """*RIMM RGB* colourspace primaries.""" WHITEPOINT_NAME_RIMM_RGB: str = WHITEPOINT_NAME_ROMM_RGB """*RIMM RGB* colourspace whitepoint name.""" -CCS_WHITEPOINT_RIMM_RGB: NDArray = CCS_WHITEPOINT_ROMM_RGB +CCS_WHITEPOINT_RIMM_RGB: NDArrayFloat = CCS_WHITEPOINT_ROMM_RGB """*RIMM RGB* colourspace whitepoint chromaticity coordinates.""" -MATRIX_RIMM_RGB_TO_XYZ: NDArray = MATRIX_ROMM_RGB_TO_XYZ +MATRIX_RIMM_RGB_TO_XYZ: NDArrayFloat = MATRIX_ROMM_RGB_TO_XYZ """*RIMM RGB* colourspace to *CIE XYZ* tristimulus values matrix.""" -MATRIX_XYZ_TO_RIMM_RGB: NDArray = MATRIX_XYZ_TO_ROMM_RGB +MATRIX_XYZ_TO_RIMM_RGB: NDArrayFloat = MATRIX_XYZ_TO_ROMM_RGB """*CIE XYZ* tristimulus values to *RIMM RGB* colourspace matrix.""" RGB_COLOURSPACE_RIMM_RGB: RGB_Colourspace = RGB_Colourspace( @@ -157,19 +157,19 @@ :cite:`Spaulding2000b` """ -PRIMARIES_ERIMM_RGB: NDArray = PRIMARIES_ROMM_RGB +PRIMARIES_ERIMM_RGB: NDArrayFloat = PRIMARIES_ROMM_RGB """*ERIMM RGB* colourspace primaries.""" WHITEPOINT_NAME_ERIMM_RGB: str = WHITEPOINT_NAME_ROMM_RGB """*ERIMM RGB* colourspace whitepoint name.""" -CCS_WHITEPOINT_ERIMM_RGB: NDArray = CCS_WHITEPOINT_ROMM_RGB +CCS_WHITEPOINT_ERIMM_RGB: NDArrayFloat = CCS_WHITEPOINT_ROMM_RGB """*ERIMM RGB* colourspace whitepoint chromaticity coordinates.""" -MATRIX_ERIMM_RGB_TO_XYZ: NDArray = MATRIX_ROMM_RGB_TO_XYZ +MATRIX_ERIMM_RGB_TO_XYZ: NDArrayFloat = MATRIX_ROMM_RGB_TO_XYZ """*ERIMM RGB* colourspace to *CIE XYZ* tristimulus values matrix.""" -MATRIX_XYZ_TO_ERIMM_RGB: NDArray = MATRIX_XYZ_TO_ROMM_RGB +MATRIX_XYZ_TO_ERIMM_RGB: NDArrayFloat = MATRIX_XYZ_TO_ROMM_RGB """*CIE XYZ* tristimulus values to *ERIMM RGB* colourspace matrix.""" RGB_COLOURSPACE_ERIMM_RGB: RGB_Colourspace = RGB_Colourspace( @@ -190,19 +190,19 @@ :cite:`Spaulding2000b` """ -PRIMARIES_PROPHOTO_RGB: NDArray = PRIMARIES_ROMM_RGB +PRIMARIES_PROPHOTO_RGB: NDArrayFloat = PRIMARIES_ROMM_RGB """*ProPhoto RGB* colourspace primaries.""" WHITEPOINT_NAME_PROPHOTO_RGB: str = WHITEPOINT_NAME_ROMM_RGB """*ProPhoto RGB* colourspace whitepoint name.""" -CCS_WHITEPOINT_PROPHOTO_RGB: NDArray = CCS_WHITEPOINT_ROMM_RGB +CCS_WHITEPOINT_PROPHOTO_RGB: NDArrayFloat = CCS_WHITEPOINT_ROMM_RGB """*ProPhoto RGB* colourspace whitepoint chromaticity coordinates.""" -MATRIX_PROPHOTO_RGB_TO_XYZ: NDArray = MATRIX_ROMM_RGB_TO_XYZ +MATRIX_PROPHOTO_RGB_TO_XYZ: NDArrayFloat = MATRIX_ROMM_RGB_TO_XYZ """*ProPhoto RGB* colourspace to *CIE XYZ* tristimulus values matrix.""" -MATRIX_XYZ_TO_PROPHOTO_RGB: NDArray = MATRIX_XYZ_TO_ROMM_RGB +MATRIX_XYZ_TO_PROPHOTO_RGB: NDArrayFloat = MATRIX_XYZ_TO_ROMM_RGB """*CIE XYZ* tristimulus values to *ProPhoto RGB* colourspace matrix.""" RGB_COLOURSPACE_PROPHOTO_RGB: RGB_Colourspace = RGB_Colourspace( diff --git a/colour/models/rgb/datasets/russell_rgb.py b/colour/models/rgb/datasets/russell_rgb.py index b9c1769bbb..ded0bce68c 100644 --- a/colour/models/rgb/datasets/russell_rgb.py +++ b/colour/models/rgb/datasets/russell_rgb.py @@ -18,7 +18,7 @@ from functools import partial from colour.colorimetry.datasets import CCS_ILLUMINANTS -from colour.hints import NDArray +from colour.hints import NDArrayFloat from colour.models.rgb import ( RGB_Colourspace, gamma_function, @@ -41,7 +41,7 @@ "RGB_COLOURSPACE_RUSSELL_RGB", ] -PRIMARIES_RUSSELL_RGB: NDArray = np.array( +PRIMARIES_RUSSELL_RGB: NDArrayFloat = np.array( [ [0.6900, 0.3100], [0.1800, 0.7700], @@ -53,17 +53,19 @@ WHITEPOINT_NAME_RUSSELL_RGB: str = "D55" """*Russell RGB* colourspace whitepoint name.""" -CCS_WHITEPOINT_RUSSELL_RGB: NDArray = CCS_ILLUMINANTS[ +CCS_WHITEPOINT_RUSSELL_RGB: NDArrayFloat = CCS_ILLUMINANTS[ "CIE 1931 2 Degree Standard Observer" ][WHITEPOINT_NAME_RUSSELL_RGB] """*Russell RGB* colourspace whitepoint chromaticity coordinates.""" -MATRIX_RUSSELL_RGB_TO_XYZ: NDArray = normalised_primary_matrix( +MATRIX_RUSSELL_RGB_TO_XYZ: NDArrayFloat = normalised_primary_matrix( PRIMARIES_RUSSELL_RGB, CCS_WHITEPOINT_RUSSELL_RGB ) """*Russell RGB* colourspace to *CIE XYZ* tristimulus values matrix.""" -MATRIX_XYZ_TO_RUSSELL_RGB: NDArray = np.linalg.inv(MATRIX_RUSSELL_RGB_TO_XYZ) +MATRIX_XYZ_TO_RUSSELL_RGB: NDArrayFloat = np.linalg.inv( + MATRIX_RUSSELL_RGB_TO_XYZ +) """*CIE XYZ* tristimulus values to *Russell RGB* colourspace matrix.""" RGB_COLOURSPACE_RUSSELL_RGB: RGB_Colourspace = RGB_Colourspace( diff --git a/colour/models/rgb/datasets/sharp.py b/colour/models/rgb/datasets/sharp.py index 2e5b1f4a6e..4cee27a534 100644 --- a/colour/models/rgb/datasets/sharp.py +++ b/colour/models/rgb/datasets/sharp.py @@ -25,7 +25,7 @@ import numpy as np from colour.colorimetry import CCS_ILLUMINANTS -from colour.hints import NDArray +from colour.hints import NDArrayFloat from colour.models.rgb import ( RGB_Colourspace, linear_function, @@ -48,7 +48,7 @@ "RGB_COLOURSPACE_SHARP_RGB", ] -PRIMARIES_SHARP_RGB: NDArray = np.array( +PRIMARIES_SHARP_RGB: NDArrayFloat = np.array( [ [0.6898, 0.3206], [0.0736, 0.9003], @@ -83,17 +83,17 @@ WHITEPOINT_NAME_SHARP_RGB: str = "E" """*Sharp RGB* colourspace whitepoint name.""" -CCS_WHITEPOINT_SHARP_RGB: NDArray = CCS_ILLUMINANTS[ +CCS_WHITEPOINT_SHARP_RGB: NDArrayFloat = CCS_ILLUMINANTS[ "CIE 1931 2 Degree Standard Observer" ][WHITEPOINT_NAME_SHARP_RGB] """*Sharp RGB* colourspace whitepoint chromaticity coordinates.""" -MATRIX_SHARP_RGB_TO_XYZ: NDArray = normalised_primary_matrix( +MATRIX_SHARP_RGB_TO_XYZ: NDArrayFloat = normalised_primary_matrix( PRIMARIES_SHARP_RGB, CCS_WHITEPOINT_SHARP_RGB ) """*Sharp RGB* colourspace to *CIE XYZ* tristimulus values matrix.""" -MATRIX_XYZ_TO_SHARP_RGB: NDArray = np.linalg.inv(MATRIX_SHARP_RGB_TO_XYZ) +MATRIX_XYZ_TO_SHARP_RGB: NDArrayFloat = np.linalg.inv(MATRIX_SHARP_RGB_TO_XYZ) """*CIE XYZ* tristimulus values to *Sharp RGB* colourspace matrix.""" RGB_COLOURSPACE_SHARP_RGB: RGB_Colourspace = RGB_Colourspace( diff --git a/colour/models/rgb/datasets/smpte_240m.py b/colour/models/rgb/datasets/smpte_240m.py index ebeca43f4d..61dd418511 100644 --- a/colour/models/rgb/datasets/smpte_240m.py +++ b/colour/models/rgb/datasets/smpte_240m.py @@ -20,7 +20,7 @@ import numpy as np from colour.colorimetry import CCS_ILLUMINANTS -from colour.hints import NDArray +from colour.hints import NDArrayFloat from colour.models.rgb import ( RGB_Colourspace, normalised_primary_matrix, @@ -44,7 +44,7 @@ "RGB_COLOURSPACE_SMPTE_240M", ] -PRIMARIES_SMPTE_240M: NDArray = np.array( +PRIMARIES_SMPTE_240M: NDArrayFloat = np.array( [ [0.6300, 0.3400], [0.3100, 0.5950], @@ -56,17 +56,19 @@ WHITEPOINT_NAME_SMPTE_240M: str = "D65" """*SMPTE 240M* colourspace whitepoint name.""" -CCS_WHITEPOINT_SMPTE_240M: NDArray = CCS_ILLUMINANTS[ +CCS_WHITEPOINT_SMPTE_240M: NDArrayFloat = CCS_ILLUMINANTS[ "CIE 1931 2 Degree Standard Observer" ][WHITEPOINT_NAME_SMPTE_240M] """*SMPTE 240M* colourspace whitepoint chromaticity coordinates.""" -MATRIX_SMPTE_240M_TO_XYZ: NDArray = normalised_primary_matrix( +MATRIX_SMPTE_240M_TO_XYZ: NDArrayFloat = normalised_primary_matrix( PRIMARIES_SMPTE_240M, CCS_WHITEPOINT_SMPTE_240M ) """*SMPTE 240M* colourspace to *CIE XYZ* tristimulus values matrix.""" -MATRIX_XYZ_TO_SMPTE_240M: NDArray = np.linalg.inv(MATRIX_SMPTE_240M_TO_XYZ) +MATRIX_XYZ_TO_SMPTE_240M: NDArrayFloat = np.linalg.inv( + MATRIX_SMPTE_240M_TO_XYZ +) """*CIE XYZ* tristimulus values to *SMPTE 240M* colourspace matrix.""" RGB_COLOURSPACE_SMPTE_240M: RGB_Colourspace = RGB_Colourspace( diff --git a/colour/models/rgb/datasets/smpte_c.py b/colour/models/rgb/datasets/smpte_c.py index 8691d250cd..145e14b9d8 100644 --- a/colour/models/rgb/datasets/smpte_c.py +++ b/colour/models/rgb/datasets/smpte_c.py @@ -20,7 +20,7 @@ from functools import partial from colour.colorimetry import CCS_ILLUMINANTS -from colour.hints import NDArray +from colour.hints import NDArrayFloat from colour.models.rgb import ( RGB_Colourspace, gamma_function, @@ -43,7 +43,7 @@ "RGB_COLOURSPACE_SMPTE_C", ] -PRIMARIES_SMPTE_C: NDArray = np.array( +PRIMARIES_SMPTE_C: NDArrayFloat = np.array( [ [0.630, 0.340], [0.310, 0.595], @@ -55,17 +55,17 @@ WHITEPOINT_NAME_SMPTE_C: str = "D65" """*SMPTE C* colourspace whitepoint name.""" -CCS_WHITEPOINT_SMPTE_C: NDArray = CCS_ILLUMINANTS[ +CCS_WHITEPOINT_SMPTE_C: NDArrayFloat = CCS_ILLUMINANTS[ "CIE 1931 2 Degree Standard Observer" ][WHITEPOINT_NAME_SMPTE_C] """*SMPTE C* colourspace whitepoint chromaticity coordinates.""" -MATRIX_SMPTE_C_TO_XYZ: NDArray = normalised_primary_matrix( +MATRIX_SMPTE_C_TO_XYZ: NDArrayFloat = normalised_primary_matrix( PRIMARIES_SMPTE_C, CCS_WHITEPOINT_SMPTE_C ) """*SMPTE C* colourspace to *CIE XYZ* tristimulus values matrix.""" -MATRIX_XYZ_TO_SMPTE_C: NDArray = np.linalg.inv(MATRIX_SMPTE_C_TO_XYZ) +MATRIX_XYZ_TO_SMPTE_C: NDArrayFloat = np.linalg.inv(MATRIX_SMPTE_C_TO_XYZ) """*CIE XYZ* tristimulus values to *SMPTE C* colourspace matrix.""" RGB_COLOURSPACE_SMPTE_C: RGB_Colourspace = RGB_Colourspace( diff --git a/colour/models/rgb/datasets/sony.py b/colour/models/rgb/datasets/sony.py index 84580e93f4..959f303a9d 100644 --- a/colour/models/rgb/datasets/sony.py +++ b/colour/models/rgb/datasets/sony.py @@ -48,7 +48,7 @@ import numpy as np from colour.colorimetry import CCS_ILLUMINANTS -from colour.hints import NDArray +from colour.hints import NDArrayFloat from colour.models.rgb import ( RGB_Colourspace, log_encoding_SLog2, @@ -98,7 +98,7 @@ "RGB_COLOURSPACE_VENICE_S_GAMUT3_CINE", ] -PRIMARIES_S_GAMUT: NDArray = np.array( +PRIMARIES_S_GAMUT: NDArrayFloat = np.array( [ [0.7300, 0.2800], [0.1400, 0.8550], @@ -110,12 +110,12 @@ WHITEPOINT_NAME_S_GAMUT: str = "D65" """*S-Gamut* colourspace whitepoint name.""" -CCS_WHITEPOINT_S_GAMUT: NDArray = CCS_ILLUMINANTS[ +CCS_WHITEPOINT_S_GAMUT: NDArrayFloat = CCS_ILLUMINANTS[ "CIE 1931 2 Degree Standard Observer" ][WHITEPOINT_NAME_S_GAMUT] """*S-Gamut* colourspace whitepoint chromaticity coordinates.""" -MATRIX_S_GAMUT_TO_XYZ: NDArray = np.array( +MATRIX_S_GAMUT_TO_XYZ: NDArrayFloat = np.array( [ [0.7064827132, 0.1288010498, 0.1151721641], [0.2709796708, 0.7866064112, -0.0575860820], @@ -124,7 +124,7 @@ ) """*S-Gamut* colourspace to *CIE XYZ* tristimulus values matrix.""" -MATRIX_XYZ_TO_S_GAMUT: NDArray = np.array( +MATRIX_XYZ_TO_S_GAMUT: NDArrayFloat = np.array( [ [1.5073998991, -0.2458221374, -0.1716116808], [-0.5181517271, 1.3553912409, 0.1258786682], @@ -151,19 +151,19 @@ :cite:`Gaggioni`, :cite:`SonyCorporation` """ -PRIMARIES_S_GAMUT3: NDArray = PRIMARIES_S_GAMUT +PRIMARIES_S_GAMUT3: NDArrayFloat = PRIMARIES_S_GAMUT """*S-Gamut3* colourspace primaries.""" WHITEPOINT_NAME_S_GAMUT3: str = WHITEPOINT_NAME_S_GAMUT """*S-Gamut3* colourspace whitepoint name.""" -CCS_WHITEPOINT_S_GAMUT3: NDArray = CCS_WHITEPOINT_S_GAMUT +CCS_WHITEPOINT_S_GAMUT3: NDArrayFloat = CCS_WHITEPOINT_S_GAMUT """*S-Gamut3* colourspace whitepoint chromaticity coordinates.""" -MATRIX_S_GAMUT3_TO_XYZ: NDArray = MATRIX_S_GAMUT_TO_XYZ +MATRIX_S_GAMUT3_TO_XYZ: NDArrayFloat = MATRIX_S_GAMUT_TO_XYZ """*S-Gamut3* colourspace to *CIE XYZ* tristimulus values matrix.""" -MATRIX_XYZ_TO_S_GAMUT3: NDArray = MATRIX_XYZ_TO_S_GAMUT +MATRIX_XYZ_TO_S_GAMUT3: NDArrayFloat = MATRIX_XYZ_TO_S_GAMUT """*CIE XYZ* tristimulus values to *S-Gamut3* colourspace matrix.""" RGB_COLOURSPACE_S_GAMUT3: RGB_Colourspace = RGB_Colourspace( @@ -184,7 +184,7 @@ :cite:`SonyCorporationd` """ -PRIMARIES_S_GAMUT3_CINE: NDArray = np.array( +PRIMARIES_S_GAMUT3_CINE: NDArrayFloat = np.array( [ [0.76600, 0.27500], [0.22500, 0.80000], @@ -196,10 +196,10 @@ WHITEPOINT_NAME_S_GAMUT3_CINE: str = WHITEPOINT_NAME_S_GAMUT """*S-Gamut3.Cine* colourspace whitepoint name.""" -CCS_WHITEPOINT_S_GAMUT3_CINE: NDArray = CCS_WHITEPOINT_S_GAMUT +CCS_WHITEPOINT_S_GAMUT3_CINE: NDArrayFloat = CCS_WHITEPOINT_S_GAMUT """*S-Gamut3.Cine* colourspace whitepoint chromaticity coordinates.""" -MATRIX_S_GAMUT3_CINE_TO_XYZ: NDArray = np.array( +MATRIX_S_GAMUT3_CINE_TO_XYZ: NDArrayFloat = np.array( [ [0.5990839208, 0.2489255161, 0.1024464902], [0.2150758201, 0.8850685017, -0.1001443219], @@ -208,7 +208,7 @@ ) """*S-Gamut3.Cine* colourspace to *CIE XYZ* tristimulus values matrix.""" -MATRIX_XYZ_TO_S_GAMUT3_CINE: NDArray = np.array( +MATRIX_XYZ_TO_S_GAMUT3_CINE: NDArrayFloat = np.array( [ [1.8467789693, -0.5259861230, -0.2105452114], [-0.4441532629, 1.2594429028, 0.1493999729], @@ -235,7 +235,7 @@ :cite:`SonyCorporatione` """ -PRIMARIES_VENICE_S_GAMUT3: NDArray = np.array( +PRIMARIES_VENICE_S_GAMUT3: NDArrayFloat = np.array( [ [0.740464264304292, 0.279364374750660], [0.089241145423286, 0.893809528608105], @@ -247,15 +247,15 @@ WHITEPOINT_NAME_VENICE_S_GAMUT3: str = WHITEPOINT_NAME_S_GAMUT """*Venice S-Gamut3* colourspace whitepoint name.""" -CCS_WHITEPOINT_VENICE_S_GAMUT3: NDArray = CCS_WHITEPOINT_S_GAMUT +CCS_WHITEPOINT_VENICE_S_GAMUT3: NDArrayFloat = CCS_WHITEPOINT_S_GAMUT """*Venice S-Gamut3* colourspace whitepoint chromaticity coordinates.""" -MATRIX_VENICE_S_GAMUT3_TO_XYZ: NDArray = normalised_primary_matrix( +MATRIX_VENICE_S_GAMUT3_TO_XYZ: NDArrayFloat = normalised_primary_matrix( PRIMARIES_VENICE_S_GAMUT3, CCS_WHITEPOINT_VENICE_S_GAMUT3 ) """*Venice S-Gamut3* colourspace to *CIE XYZ* tristimulus values matrix.""" -MATRIX_XYZ_TO_VENICE_S_GAMUT3: NDArray = np.linalg.inv( +MATRIX_XYZ_TO_VENICE_S_GAMUT3: NDArrayFloat = np.linalg.inv( MATRIX_VENICE_S_GAMUT3_TO_XYZ ) """*CIE XYZ* tristimulus values to *Venice S-Gamut3* colourspace matrix.""" @@ -278,7 +278,7 @@ :cite:`SonyElectronicsCorporation2020` """ -PRIMARIES_VENICE_S_GAMUT3_CINE: NDArray = np.array( +PRIMARIES_VENICE_S_GAMUT3_CINE: NDArrayFloat = np.array( [ [0.775901871567345, 0.274502392854799], [0.188682902773355, 0.828684937020288], @@ -290,15 +290,15 @@ WHITEPOINT_NAME_VENICE_S_GAMUT3_CINE: str = WHITEPOINT_NAME_S_GAMUT """*Venice S-Gamut3.Cine* colourspace whitepoint name.""" -CCS_WHITEPOINT_VENICE_S_GAMUT3_CINE: NDArray = CCS_WHITEPOINT_S_GAMUT +CCS_WHITEPOINT_VENICE_S_GAMUT3_CINE: NDArrayFloat = CCS_WHITEPOINT_S_GAMUT """*Venice S-Gamut3.Cine* colourspace whitepoint chromaticity coordinates.""" -MATRIX_VENICE_S_GAMUT3_CINE_TO_XYZ: NDArray = normalised_primary_matrix( +MATRIX_VENICE_S_GAMUT3_CINE_TO_XYZ: NDArrayFloat = normalised_primary_matrix( PRIMARIES_VENICE_S_GAMUT3_CINE, CCS_WHITEPOINT_VENICE_S_GAMUT3_CINE ) """*Venice S-Gamut3.Cine* colourspace to *CIE XYZ* tristimulus values matrix.""" -MATRIX_XYZ_TO_VENICE_S_GAMUT3_CINE: NDArray = np.linalg.inv( +MATRIX_XYZ_TO_VENICE_S_GAMUT3_CINE: NDArrayFloat = np.linalg.inv( MATRIX_VENICE_S_GAMUT3_CINE_TO_XYZ ) """*CIE XYZ* tristimulus values to *Venice S-Gamut3.Cine* colourspace matrix.""" diff --git a/colour/models/rgb/datasets/srgb.py b/colour/models/rgb/datasets/srgb.py index e8b8514afb..e1d143a45a 100644 --- a/colour/models/rgb/datasets/srgb.py +++ b/colour/models/rgb/datasets/srgb.py @@ -26,7 +26,7 @@ import numpy as np from colour.colorimetry import CCS_ILLUMINANTS -from colour.hints import NDArray +from colour.hints import NDArrayFloat from colour.models.rgb import RGB_Colourspace, eotf_inverse_sRGB, eotf_sRGB __author__ = "Colour Developers" @@ -45,7 +45,7 @@ "RGB_COLOURSPACE_sRGB", ] -PRIMARIES_sRGB: NDArray = np.array( +PRIMARIES_sRGB: NDArrayFloat = np.array( [ [0.6400, 0.3300], [0.3000, 0.6000], @@ -57,12 +57,12 @@ WHITEPOINT_NAME_sRGB: str = "D65" """*sRGB* colourspace whitepoint name.""" -CCS_WHITEPOINT_sRGB: NDArray = CCS_ILLUMINANTS[ +CCS_WHITEPOINT_sRGB: NDArrayFloat = CCS_ILLUMINANTS[ "CIE 1931 2 Degree Standard Observer" ][WHITEPOINT_NAME_sRGB] """*sRGB* colourspace whitepoint chromaticity coordinates.""" -MATRIX_sRGB_TO_XYZ: NDArray = np.array( +MATRIX_sRGB_TO_XYZ: NDArrayFloat = np.array( [ [0.4124, 0.3576, 0.1805], [0.2126, 0.7152, 0.0722], @@ -71,7 +71,7 @@ ) """*sRGB* colourspace to *CIE XYZ* tristimulus values matrix.""" -MATRIX_XYZ_TO_sRGB: NDArray = np.array( +MATRIX_XYZ_TO_sRGB: NDArrayFloat = np.array( [ [3.2406, -1.5372, -0.4986], [-0.9689, 1.8758, 0.0415], diff --git a/colour/models/rgb/datasets/xtreme_rgb.py b/colour/models/rgb/datasets/xtreme_rgb.py index a60f631c5d..c4241ea319 100644 --- a/colour/models/rgb/datasets/xtreme_rgb.py +++ b/colour/models/rgb/datasets/xtreme_rgb.py @@ -18,7 +18,7 @@ from functools import partial from colour.colorimetry import CCS_ILLUMINANTS -from colour.hints import NDArray +from colour.hints import NDArrayFloat from colour.models.rgb import ( RGB_Colourspace, gamma_function, @@ -41,7 +41,7 @@ "RGB_COLOURSPACE_XTREME_RGB", ] -PRIMARIES_XTREME_RGB: NDArray = np.array( +PRIMARIES_XTREME_RGB: NDArrayFloat = np.array( [ [1.0, 0.0], [0.0, 1.0], @@ -53,17 +53,19 @@ WHITEPOINT_NAME_XTREME_RGB: str = "D50" """*Xtreme RGB* colourspace whitepoint name.""" -CCS_WHITEPOINT_XTREME_RGB: NDArray = CCS_ILLUMINANTS[ +CCS_WHITEPOINT_XTREME_RGB: NDArrayFloat = CCS_ILLUMINANTS[ "CIE 1931 2 Degree Standard Observer" ][WHITEPOINT_NAME_XTREME_RGB] """*Xtreme RGB* colourspace whitepoint chromaticity coordinates.""" -MATRIX_XTREME_RGB_TO_XYZ: NDArray = normalised_primary_matrix( +MATRIX_XTREME_RGB_TO_XYZ: NDArrayFloat = normalised_primary_matrix( PRIMARIES_XTREME_RGB, CCS_WHITEPOINT_XTREME_RGB ) """*Xtreme RGB* colourspace to *CIE XYZ* tristimulus values matrix.""" -MATRIX_XYZ_TO_XTREME_RGB: NDArray = np.linalg.inv(MATRIX_XTREME_RGB_TO_XYZ) +MATRIX_XYZ_TO_XTREME_RGB: NDArrayFloat = np.linalg.inv( + MATRIX_XTREME_RGB_TO_XYZ +) """*CIE XYZ* tristimulus values to *Xtreme RGB* colourspace matrix.""" RGB_COLOURSPACE_XTREME_RGB: RGB_Colourspace = RGB_Colourspace( diff --git a/colour/models/rgb/derivation.py b/colour/models/rgb/derivation.py index 766723d878..6646372e80 100644 --- a/colour/models/rgb/derivation.py +++ b/colour/models/rgb/derivation.py @@ -29,12 +29,9 @@ from colour.adaptation import chromatic_adaptation_VonKries from colour.hints import ( - Floating, - FloatingOrNDArray, ArrayLike, Literal, - NDArray, - Tuple, + NDArrayFloat, Union, ) from colour.models import XYZ_to_xy, XYZ_to_xyY, xy_to_XYZ @@ -57,7 +54,7 @@ ] -def xy_to_z(xy: ArrayLike) -> Floating: +def xy_to_z(xy: ArrayLike) -> float: """ Return the *z* coordinate using given :math:`xy` chromaticity coordinates. @@ -68,7 +65,7 @@ def xy_to_z(xy: ArrayLike) -> Floating: Returns ------- - :class:`numpy.floating` + :class:`float` *z* coordinate. Examples @@ -86,7 +83,7 @@ def xy_to_z(xy: ArrayLike) -> Floating: def normalised_primary_matrix( primaries: ArrayLike, whitepoint: ArrayLike -) -> NDArray: +) -> NDArrayFloat: """ Compute the *Normalised Primary Matrix* (NPM) converting a *RGB* colourspace array to *CIE XYZ* tristimulus values using given *primaries* @@ -154,7 +151,7 @@ def chromatically_adapted_primaries( ], str, ] = "CAT02", -) -> NDArray: +) -> NDArrayFloat: """ Chromatically adapt given *primaries* :math:`xy` chromaticity coordinates from test ``whitepoint_t`` to reference ``whitepoint_r``. @@ -204,7 +201,7 @@ def chromatically_adapted_primaries( return P_a -def primaries_whitepoint(npm: ArrayLike) -> Tuple[NDArray, NDArray]: +def primaries_whitepoint(npm: ArrayLike) -> tuple[NDArrayFloat, NDArrayFloat]: """ Compute the *primaries* and *whitepoint* :math:`xy` chromaticity coordinates using given *Normalised Primary Matrix* (NPM). @@ -282,7 +279,7 @@ def RGB_luminance_equation(primaries: ArrayLike, whitepoint: ArrayLike) -> str: def RGB_luminance( RGB: ArrayLike, primaries: ArrayLike, whitepoint: ArrayLike -) -> FloatingOrNDArray: +) -> NDArrayFloat: """ Return the *luminance* :math:`Y` of given *RGB* components from given *primaries* and *whitepoint*. @@ -298,7 +295,7 @@ def RGB_luminance( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` *Luminance* :math:`Y`. Examples diff --git a/colour/models/rgb/hanbury2003.py b/colour/models/rgb/hanbury2003.py index a0d5355242..e24aa29db4 100644 --- a/colour/models/rgb/hanbury2003.py +++ b/colour/models/rgb/hanbury2003.py @@ -20,7 +20,7 @@ import numpy as np from colour.algebra import sdiv, sdiv_mode, vector_dot -from colour.hints import ArrayLike, NDArray, cast +from colour.hints import ArrayLike, NDArrayFloat from colour.utilities import ( from_range_1, to_domain_1, @@ -41,7 +41,7 @@ "IHLS_to_RGB", ] -MATRIX_RGB_TO_YC_1_C_2: NDArray = np.array( +MATRIX_RGB_TO_YC_1_C_2: NDArrayFloat = np.array( [ [0.2126, 0.7152, 0.0722], [1, -0.5, -0.5], @@ -50,11 +50,11 @@ ) """*RGB* colourspace to *YC_1C_2* colourspace matrix.""" -MATRIX_YC_1_C_2_TO_RGB: NDArray = np.linalg.inv(MATRIX_RGB_TO_YC_1_C_2) +MATRIX_YC_1_C_2_TO_RGB: NDArrayFloat = np.linalg.inv(MATRIX_RGB_TO_YC_1_C_2) """*YC_1C_2* colourspace to *RGB* colourspace matrix.""" -def RGB_to_IHLS(RGB: ArrayLike) -> NDArray: +def RGB_to_IHLS(RGB: ArrayLike) -> NDArrayFloat: """ Convert from *RGB* colourspace to *IHLS* (Improved HLS) colourspace. @@ -101,7 +101,7 @@ def RGB_to_IHLS(RGB: ArrayLike) -> NDArray: C = np.sqrt(C_1**2 + C_2**2) with sdiv_mode(): - C_1_C = cast(NDArray, sdiv(C_1, C)) + C_1_C = sdiv(C_1, C) arcos_C_1_C_2 = zeros(C_1_C.shape) arcos_C_1_C_2[C_1_C != 0] = np.arccos(C_1_C[C_1_C != 0]) @@ -115,7 +115,7 @@ def RGB_to_IHLS(RGB: ArrayLike) -> NDArray: return from_range_1(HYS) -def IHLS_to_RGB(HYS: ArrayLike) -> NDArray: +def IHLS_to_RGB(HYS: ArrayLike) -> NDArrayFloat: """ Convert from *IHLS* (Improved HLS) colourspace to *RGB* colourspace. diff --git a/colour/models/rgb/ictcp.py b/colour/models/rgb/ictcp.py index 261a6bbe3c..8eefee9a04 100644 --- a/colour/models/rgb/ictcp.py +++ b/colour/models/rgb/ictcp.py @@ -31,7 +31,7 @@ from colour.algebra import vector_dot from colour.colorimetry import CCS_ILLUMINANTS -from colour.hints import ArrayLike, Floating, Literal, NDArray, Optional, Union +from colour.hints import ArrayLike, Literal, NDArrayFloat, Optional, Union from colour.models.rgb import RGB_COLOURSPACES, RGB_to_XYZ, XYZ_to_RGB from colour.models.rgb.transfer_functions import ( eotf_ST2084, @@ -65,7 +65,7 @@ "ICtCp_to_XYZ", ] -MATRIX_ICTCP_RGB_TO_LMS: NDArray = ( +MATRIX_ICTCP_RGB_TO_LMS: NDArrayFloat = ( np.array( [ [1688, 2146, 262], @@ -77,13 +77,13 @@ ) """*ITU-R BT.2020* colourspace to normalised cone responses matrix.""" -MATRIX_ICTCP_LMS_TO_RGB: NDArray = np.linalg.inv(MATRIX_ICTCP_RGB_TO_LMS) +MATRIX_ICTCP_LMS_TO_RGB: NDArrayFloat = np.linalg.inv(MATRIX_ICTCP_RGB_TO_LMS) """ :math:`IC_TC_P` colourspace normalised cone responses to *ITU-R BT.2020* colourspace matrix. """ -MATRIX_ICTCP_LMS_P_TO_ICTCP: NDArray = ( +MATRIX_ICTCP_LMS_P_TO_ICTCP: NDArrayFloat = ( np.array( [ [2048, 2048, 0], @@ -98,7 +98,7 @@ :math:`IC_TC_P` colour encoding matrix. """ -MATRIX_ICTCP_ICTCP_TO_LMS_P: NDArray = np.linalg.inv( +MATRIX_ICTCP_ICTCP_TO_LMS_P: NDArrayFloat = np.linalg.inv( MATRIX_ICTCP_LMS_P_TO_ICTCP ) """ @@ -106,7 +106,7 @@ normalised cone responses matrix. """ -MATRIX_ICTCP_LMS_P_TO_ICTCP_BT2100_HLG_2: NDArray = ( +MATRIX_ICTCP_LMS_P_TO_ICTCP_BT2100_HLG_2: NDArrayFloat = ( np.array( [ [2048, 2048, 0], @@ -121,7 +121,7 @@ :math:`IC_TC_P` colour encoding matrix as given in *ITU-R BT.2100-2*. """ -MATRIX_ICTCP_ICTCP_TO_LMS_P_BT2100_HLG_2: NDArray = np.linalg.inv( +MATRIX_ICTCP_ICTCP_TO_LMS_P_BT2100_HLG_2: NDArrayFloat = np.linalg.inv( MATRIX_ICTCP_LMS_P_TO_ICTCP_BT2100_HLG_2 ) """ @@ -142,8 +142,8 @@ def RGB_to_ICtCp( ], str, ] = "Dolby 2016", - L_p: Floating = 10000, -) -> NDArray: + L_p: float = 10000, +) -> NDArrayFloat: """ Convert from *ITU-R BT.2020* colourspace to :math:`IC_TC_P` colour encoding. @@ -278,8 +278,8 @@ def ICtCp_to_RGB( ], str, ] = "Dolby 2016", - L_p: Floating = 10000, -) -> NDArray: + L_p: float = 10000, +) -> NDArrayFloat: """ Convert from :math:`IC_TC_P` colour encoding to *ITU-R BT.2020* colourspace. @@ -433,8 +433,8 @@ def XYZ_to_ICtCp( ], str, ] = "Dolby 2016", - L_p: Floating = 10000, -) -> NDArray: + L_p: float = 10000, +) -> NDArrayFloat: """ Convert from *CIE XYZ* tristimulus values to :math:`IC_TC_P` colour encoding. @@ -573,8 +573,8 @@ def ICtCp_to_XYZ( ], str, ] = "Dolby 2016", - L_p: Floating = 10000, -) -> NDArray: + L_p: float = 10000, +) -> NDArrayFloat: """ Convert from :math:`IC_TC_P` colour encoding to *CIE XYZ* tristimulus values. diff --git a/colour/models/rgb/itut_h_273.py b/colour/models/rgb/itut_h_273.py index 11d1c08812..8c53678bfb 100644 --- a/colour/models/rgb/itut_h_273.py +++ b/colour/models/rgb/itut_h_273.py @@ -142,13 +142,8 @@ ) from colour.hints import ( Any, - Boolean, Callable, - Dict, - Integer, - List, - NDArray, - Tuple, + NDArrayFloat, Union, ) from colour.utilities import message_box, multiline_str @@ -196,7 +191,7 @@ def _clipped_domain_function( - function: Callable, domain: Union[List, Tuple] = (0, 1) + function: Callable, domain: Union[list, tuple] = (0, 1) ) -> Callable: """ Wrap given function and produce a new callable clipping the input value to @@ -260,7 +255,7 @@ def _unspecified(*args: Any): ) -COLOUR_PRIMARIES_ITUTH273: Dict[Integer, NDArray] = { +COLOUR_PRIMARIES_ITUTH273: dict[int, NDArrayFloat] = { 0: np.array("Reserved"), # For future use by ITU-T | ISO/IEC. # @@ -405,7 +400,7 @@ class FFmpegConstantsColourPrimaries_ITUTH273(IntEnum): NB = AVCOL_PRI_NB -TRANSFER_CHARACTERISTICS_ITUTH273: Dict[Integer, Callable] = { +TRANSFER_CHARACTERISTICS_ITUTH273: dict[int, Callable] = { 0: _reserved, # For future use by ITU-T | ISO/IEC. # @@ -582,7 +577,7 @@ class FFmpegConstantsTransferCharacteristics_ITUTH273(IntEnum): NB = AVCOL_TRC_NB -MATRIX_COEFFICIENTS_ITUTH273: Dict[Integer, NDArray] = { +MATRIX_COEFFICIENTS_ITUTH273: dict[int, NDArrayFloat] = { 0: np.array("Identity"), # The identity matrix. Typically used for GBR (often referred to as RGB); # however, may also be used for YZX (often referred to as XYZ); @@ -722,7 +717,7 @@ class FFmpegConstantsMatrixCoefficients_ITUTH273(IntEnum): NB = AVCOL_SPC_NB -CCS_WHITEPOINTS_ITUTH273: Dict[Integer, NDArray] = { +CCS_WHITEPOINTS_ITUTH273: dict[int, NDArrayFloat] = { 0: np.array("Reserved"), 1: CCS_WHITEPOINT_BT709, 2: np.array("Unspecified"), @@ -764,7 +759,7 @@ class FFmpegConstantsMatrixCoefficients_ITUTH273(IntEnum): """ -WHITEPOINT_NAMES_ITUTH273: Dict[Integer, str] = { +WHITEPOINT_NAMES_ITUTH273: dict[int, str] = { 0: "Reserved", 1: WHITEPOINT_NAME_BT709, 2: "Unspecified", @@ -904,7 +899,7 @@ class FFmpegConstantsMatrixCoefficients_ITUTH273(IntEnum): def describe_video_signal_colour_primaries( - code_point: Integer, print_description: Boolean = True, **kwargs + code_point: int, print_description: bool = True, **kwargs ) -> str: """ Describe given video signal colour primaries code point. @@ -1007,13 +1002,13 @@ def describe_video_signal_colour_primaries( class SpecificationColourPrimaries: """Specification for video signal colour primaries code point.""" - code_point: Integer - primaries: NDArray - whitepoint: NDArray + code_point: int + primaries: NDArrayFloat + whitepoint: NDArrayFloat whitepoint_name: str - matrix_RGB_to_XYZ: NDArray - matrix_XYZ_to_RGB: NDArray - ffmpeg_constants: List + matrix_RGB_to_XYZ: NDArrayFloat + matrix_XYZ_to_RGB: NDArrayFloat + ffmpeg_constants: list members = FFmpegConstantsColourPrimaries_ITUTH273.__members__.items() ffmpeg_constants = [ @@ -1060,7 +1055,7 @@ class SpecificationColourPrimaries: def describe_video_signal_transfer_characteristics( - code_point: Integer, print_description: Boolean = True, **kwargs + code_point: int, print_description: bool = True, **kwargs ) -> str: """ Describe given video signal transfer characteristics code point. @@ -1147,9 +1142,9 @@ def describe_video_signal_transfer_characteristics( class SpecificationTransferCharacteristics: """Specification for video signal transfer characteristics code point.""" - code_point: Integer + code_point: int function: Callable - ffmpeg_constants: List + ffmpeg_constants: list members = ( FFmpegConstantsTransferCharacteristics_ITUTH273.__members__.items() @@ -1190,7 +1185,7 @@ class SpecificationTransferCharacteristics: def describe_video_signal_matrix_coefficients( - code_point: Integer, print_description: Boolean = True, **kwargs + code_point: int, print_description: bool = True, **kwargs ) -> str: """ Describe given video signal matrix coefficients code point. @@ -1269,9 +1264,9 @@ def describe_video_signal_matrix_coefficients( class SpecificationMatrixCoefficients: """Specification for video signal matrix coefficients code point.""" - code_point: Integer - matrix_coefficients: NDArray - ffmpeg_constants: List + code_point: int + matrix_coefficients: NDArrayFloat + ffmpeg_constants: list members = FFmpegConstantsMatrixCoefficients_ITUTH273.__members__.items() ffmpeg_constants = [ diff --git a/colour/models/rgb/prismatic.py b/colour/models/rgb/prismatic.py index fa0981cb94..60c64cabb0 100644 --- a/colour/models/rgb/prismatic.py +++ b/colour/models/rgb/prismatic.py @@ -18,7 +18,7 @@ import numpy as np from colour.algebra import sdiv, sdiv_mode -from colour.hints import ArrayLike, NDArray +from colour.hints import ArrayLike, NDArrayFloat from colour.utilities import from_range_1, to_domain_1, tsplit, tstack __author__ = "Colour Developers" @@ -34,7 +34,7 @@ ] -def RGB_to_Prismatic(RGB: ArrayLike) -> NDArray: +def RGB_to_Prismatic(RGB: ArrayLike) -> NDArrayFloat: """ Convert from *RGB* colourspace to *Prismatic* :math:`L\\rho\\gamma\\beta` colourspace array. @@ -96,7 +96,7 @@ def RGB_to_Prismatic(RGB: ArrayLike) -> NDArray: return from_range_1(Lrgb) -def Prismatic_to_RGB(Lrgb: ArrayLike) -> NDArray: +def Prismatic_to_RGB(Lrgb: ArrayLike) -> NDArrayFloat: """ Convert from *Prismatic* :math:`L\\rho\\gamma\\beta` colourspace array to *RGB* colourspace. diff --git a/colour/models/rgb/rgb_colourspace.py b/colour/models/rgb/rgb_colourspace.py index 1d3cef4eae..a6e857240f 100644 --- a/colour/models/rgb/rgb_colourspace.py +++ b/colour/models/rgb/rgb_colourspace.py @@ -33,10 +33,9 @@ from colour.hints import ( Any, ArrayLike, - Boolean, Callable, Literal, - NDArray, + NDArrayFloat, Optional, Union, cast, @@ -249,31 +248,31 @@ def __init__( matrix_XYZ_to_RGB: Optional[ArrayLike] = None, cctf_encoding: Optional[Callable] = None, cctf_decoding: Optional[Callable] = None, - use_derived_matrix_RGB_to_XYZ: Boolean = False, - use_derived_matrix_XYZ_to_RGB: Boolean = False, + use_derived_matrix_RGB_to_XYZ: bool = False, + use_derived_matrix_XYZ_to_RGB: bool = False, ) -> None: - self._derived_matrix_RGB_to_XYZ: NDArray = np.array([]) - self._derived_matrix_XYZ_to_RGB: NDArray = np.array([]) + self._derived_matrix_RGB_to_XYZ: NDArrayFloat = np.array([]) + self._derived_matrix_XYZ_to_RGB: NDArrayFloat = np.array([]) self._name: str = f"{self.__class__.__name__} ({id(self)})" self.name = name - self._primaries: NDArray = np.array([]) - self.primaries = primaries # type: ignore[assignment] - self._whitepoint: NDArray = np.array([]) - self.whitepoint = whitepoint # type: ignore[assignment] + self._primaries: NDArrayFloat = np.array([]) + self.primaries = primaries + self._whitepoint: NDArrayFloat = np.array([]) + self.whitepoint = whitepoint self._whitepoint_name: Optional[str] = None self.whitepoint_name = whitepoint_name - self._matrix_RGB_to_XYZ: Optional[NDArray] = None - self.matrix_RGB_to_XYZ = matrix_RGB_to_XYZ # type: ignore[assignment] - self._matrix_XYZ_to_RGB: Optional[NDArray] = None - self.matrix_XYZ_to_RGB = matrix_XYZ_to_RGB # type: ignore[assignment] + self._matrix_RGB_to_XYZ: Optional[NDArrayFloat] = None + self.matrix_RGB_to_XYZ = matrix_RGB_to_XYZ + self._matrix_XYZ_to_RGB: Optional[NDArrayFloat] = None + self.matrix_XYZ_to_RGB = matrix_XYZ_to_RGB self._cctf_encoding: Optional[Callable] = None self.cctf_encoding = cctf_encoding self._cctf_decoding: Optional[Callable] = None self.cctf_decoding = cctf_decoding - self._use_derived_matrix_RGB_to_XYZ: Boolean = False + self._use_derived_matrix_RGB_to_XYZ: bool = False self.use_derived_matrix_RGB_to_XYZ = use_derived_matrix_RGB_to_XYZ - self._use_derived_matrix_XYZ_to_RGB: Boolean = False + self._use_derived_matrix_XYZ_to_RGB: bool = False self.use_derived_matrix_XYZ_to_RGB = use_derived_matrix_XYZ_to_RGB @property @@ -306,7 +305,7 @@ def name(self, value: str): self._name = value @property - def primaries(self) -> NDArray: + def primaries(self) -> NDArrayFloat: """ Getter and setter property for the primaries. @@ -342,7 +341,7 @@ def primaries(self, value: ArrayLike): self._derive_transformation_matrices() @property - def whitepoint(self) -> NDArray: + def whitepoint(self) -> NDArrayFloat: """ Getter and setter property for the whitepoint. @@ -406,7 +405,7 @@ def whitepoint_name(self, value: Optional[str]): self._whitepoint_name = value @property - def matrix_RGB_to_XYZ(self) -> NDArray: + def matrix_RGB_to_XYZ(self) -> NDArrayFloat: """ Getter and setter property for the transformation matrix from colourspace to *CIE XYZ* tristimulus values. @@ -448,7 +447,7 @@ def matrix_RGB_to_XYZ(self, value: Optional[ArrayLike]): self._matrix_RGB_to_XYZ = value @property - def matrix_XYZ_to_RGB(self) -> NDArray: + def matrix_XYZ_to_RGB(self) -> NDArrayFloat: """ Getter and setter property for the transformation matrix from *CIE XYZ* tristimulus values to colourspace. @@ -558,7 +557,7 @@ def cctf_decoding(self, value: Optional[Callable]): self._cctf_decoding = value @property - def use_derived_matrix_RGB_to_XYZ(self) -> Boolean: + def use_derived_matrix_RGB_to_XYZ(self) -> bool: """ Getter and setter property for whether to use the instantiation time normalised primary matrix or to use a computed derived normalised @@ -580,7 +579,7 @@ def use_derived_matrix_RGB_to_XYZ(self) -> Boolean: return self._use_derived_matrix_RGB_to_XYZ @use_derived_matrix_RGB_to_XYZ.setter - def use_derived_matrix_RGB_to_XYZ(self, value: Boolean): + def use_derived_matrix_RGB_to_XYZ(self, value: bool): """Setter for the **self.use_derived_matrix_RGB_to_XYZ** property.""" attest( @@ -592,7 +591,7 @@ def use_derived_matrix_RGB_to_XYZ(self, value: Boolean): self._use_derived_matrix_RGB_to_XYZ = value @property - def use_derived_matrix_XYZ_to_RGB(self) -> Boolean: + def use_derived_matrix_XYZ_to_RGB(self) -> bool: """ Getter and setter property for Whether to use the instantiation time inverse normalised primary matrix or to use a computed derived inverse @@ -616,7 +615,7 @@ def use_derived_matrix_XYZ_to_RGB(self) -> Boolean: return self._use_derived_matrix_XYZ_to_RGB @use_derived_matrix_XYZ_to_RGB.setter - def use_derived_matrix_XYZ_to_RGB(self, value: Boolean): + def use_derived_matrix_XYZ_to_RGB(self, value: bool): """Setter for the **self.use_derived_matrix_XYZ_to_RGB** property.""" attest( @@ -819,7 +818,7 @@ def _derive_transformation_matrices(self): self._derived_matrix_RGB_to_XYZ = npm self._derived_matrix_XYZ_to_RGB = np.linalg.inv(npm) - def use_derived_transformation_matrices(self, usage: Boolean = True): + def use_derived_transformation_matrices(self, usage: bool = True): """ Enable or disables usage of both derived transformations matrices, the normalised primary matrix and its inverse in subsequent @@ -916,7 +915,7 @@ def chromatically_adapt( whitepoint, chromatic_adaptation_transform, ) - colourspace.whitepoint = whitepoint # type: ignore[assignment] + colourspace.whitepoint = whitepoint colourspace.whitepoint_name = whitepoint_name colourspace._matrix_RGB_to_XYZ = None @@ -969,7 +968,7 @@ def XYZ_to_RGB( ] ] = "CAT02", cctf_encoding: Optional[Callable] = None, -) -> NDArray: +) -> NDArrayFloat: """ Convert from *CIE XYZ* tristimulus values to *RGB* colourspace array. @@ -1084,7 +1083,7 @@ def RGB_to_XYZ( ] ] = "CAT02", cctf_decoding: Optional[Callable] = None, -) -> NDArray: +) -> NDArrayFloat: """ Convert given *RGB* colourspace array to *CIE XYZ* tristimulus values. @@ -1196,7 +1195,7 @@ def matrix_RGB_to_RGB( str, ] ] = "CAT02", -) -> NDArray: +) -> NDArrayFloat: """ Compute the matrix :math:`M` converting from given input *RGB* colourspace to output *RGB* colourspace using given *chromatic @@ -1269,10 +1268,10 @@ def RGB_to_RGB( str, ] ] = "CAT02", - apply_cctf_decoding: Boolean = False, - apply_cctf_encoding: Boolean = False, + apply_cctf_decoding: bool = False, + apply_cctf_encoding: bool = False, **kwargs: Any, -) -> NDArray: +) -> NDArrayFloat: """ Convert given *RGB* colourspace array from given input *RGB* colourspace to output *RGB* colourspace using given *chromatic adaptation* method. diff --git a/colour/models/rgb/transfer_functions/__init__.py b/colour/models/rgb/transfer_functions/__init__.py index 77214268c8..3e0acb8c9e 100644 --- a/colour/models/rgb/transfer_functions/__init__.py +++ b/colour/models/rgb/transfer_functions/__init__.py @@ -2,10 +2,9 @@ from colour.hints import ( Any, - FloatingOrArrayLike, - FloatingOrNDArray, - IntegerOrArrayLike, - IntegerOrNDArray, + ArrayLike, + NDArrayFloat, + NDArrayInt, Literal, Union, ) @@ -384,7 +383,7 @@ def log_encoding( - value: FloatingOrArrayLike, + value: ArrayLike, function: Union[ Literal[ "ACEScc", @@ -420,7 +419,7 @@ def log_encoding( str, ] = "Cineon", **kwargs: Any -) -> Union[FloatingOrNDArray, IntegerOrNDArray]: +) -> Union[NDArrayFloat, NDArrayInt]: """ Encode *scene-referred* exposure values to :math:`R'G'B'` video component signal value using given *log* encoding function. @@ -468,7 +467,7 @@ def log_encoding( Returns ------- - :class:`numpy.floating` or :class:`numpy.integer` or :class:`numpy.ndarray` + :class:`numpy.ndarray` *Log* values. Examples @@ -534,7 +533,7 @@ def log_encoding( def log_decoding( - value: Union[FloatingOrArrayLike, IntegerOrArrayLike], + value: Union[ArrayLike, ArrayLike], function: Union[ Literal[ "ACEScc", @@ -570,7 +569,7 @@ def log_decoding( str, ] = "Cineon", **kwargs: Any -) -> FloatingOrNDArray: +) -> NDArrayFloat: """ Decode :math:`R'G'B'` video component signal value to *scene-referred* exposure values using given *log* decoding function. @@ -618,7 +617,7 @@ def log_decoding( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` *Scene-referred* exposure values. Examples @@ -678,7 +677,7 @@ def log_decoding( def oetf( - value: FloatingOrArrayLike, + value: ArrayLike, function: Union[ Literal[ "ARIB STD-B67", @@ -697,7 +696,7 @@ def oetf( str, ] = "ITU-R BT.709", **kwargs: Any -) -> FloatingOrNDArray: +) -> NDArrayFloat: """ Encode estimated tristimulus values in a scene to :math:`R'G'B'` video component signal value using given opto-electronic transfer function @@ -726,7 +725,7 @@ def oetf( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` :math:`R'G'B'` video component signal value. Examples @@ -767,7 +766,7 @@ def oetf( def oetf_inverse( - value: FloatingOrArrayLike, + value: ArrayLike, function: Union[ Literal[ "ARIB STD-B67", @@ -785,7 +784,7 @@ def oetf_inverse( str, ] = "ITU-R BT.709", **kwargs: Any -) -> FloatingOrNDArray: +) -> NDArrayFloat: """ Decode :math:`R'G'B'` video component signal value to tristimulus values at the display using given inverse opto-electronic transfer function @@ -814,7 +813,7 @@ def oetf_inverse( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Tristimulus values at the display. Examples @@ -857,7 +856,7 @@ def oetf_inverse( def eotf( - value: Union[FloatingOrArrayLike, IntegerOrArrayLike], + value: Union[ArrayLike, ArrayLike], function: Union[ Literal[ "DCDM", @@ -873,7 +872,7 @@ def eotf( str, ] = "ITU-R BT.1886", **kwargs: Any -) -> FloatingOrNDArray: +) -> NDArrayFloat: """ Decode :math:`R'G'B'` video component signal value to tristimulus values at the display using given electro-optical transfer function (EOTF). @@ -900,7 +899,7 @@ def eotf( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Tristimulus values at the display. Examples @@ -939,7 +938,7 @@ def eotf( def eotf_inverse( - value: FloatingOrArrayLike, + value: ArrayLike, function: Union[ Literal[ "DCDM", @@ -954,7 +953,7 @@ def eotf_inverse( str, ] = "ITU-R BT.1886", **kwargs -) -> Union[FloatingOrNDArray, IntegerOrNDArray]: +) -> Union[NDArrayFloat, NDArrayInt]: """ Encode estimated tristimulus values in a scene to :math:`R'G'B'` video component signal value using given inverse electro-optical transfer @@ -981,7 +980,7 @@ def eotf_inverse( Returns ------- - :class:`numpy.floating` or :class:`numpy.integer` or :class:`numpy.ndarray` + :class:`numpy.ndarray` :math:`R'G'B'` video component signal value. Examples @@ -1050,7 +1049,7 @@ def eotf_inverse( def cctf_encoding( - value: FloatingOrArrayLike, + value: ArrayLike, function: Union[ Literal[ "ACEScc", @@ -1105,7 +1104,7 @@ def cctf_encoding( str, ] = "sRGB", **kwargs: Any -) -> Union[FloatingOrNDArray, IntegerOrNDArray]: +) -> Union[NDArrayFloat, NDArrayInt]: """ Encode linear :math:`RGB` values to non-linear :math:`R'G'B'` values using given encoding colour component transfer function (Encoding CCTF). @@ -1133,7 +1132,7 @@ def cctf_encoding( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Non-linear :math:`R'G'B'` values. Examples @@ -1206,7 +1205,7 @@ def cctf_encoding( def cctf_decoding( - value: Union[FloatingOrArrayLike, IntegerOrArrayLike], + value: Union[ArrayLike, ArrayLike], function: Union[ Literal[ "ACEScc", @@ -1261,7 +1260,7 @@ def cctf_decoding( str, ] = "sRGB", **kwargs: Any -) -> FloatingOrNDArray: +) -> NDArrayFloat: """ Decode non-linear :math:`R'G'B'` values to linear :math:`RGB` values using given decoding colour component transfer function (Decoding CCTF). @@ -1289,7 +1288,7 @@ def cctf_decoding( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Linear :math:`RGB` values. Examples @@ -1346,12 +1345,12 @@ def cctf_decoding( def ootf( - value: FloatingOrArrayLike, + value: ArrayLike, function: Union[ Literal["ITU-R BT.2100 HLG", "ITU-R BT.2100 PQ"], str ] = "ITU-R BT.2100 PQ", **kwargs: Any -) -> FloatingOrNDArray: +) -> NDArrayFloat: """ Map relative scene linear light to display linear light using given opto-optical transfer function (OOTF / OOCF). @@ -1372,7 +1371,7 @@ def ootf( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Luminance of a displayed linear component. Examples @@ -1404,12 +1403,12 @@ def ootf( def ootf_inverse( - value: FloatingOrArrayLike, + value: ArrayLike, function: Union[ Literal["ITU-R BT.2100 HLG", "ITU-R BT.2100 PQ"], str ] = "ITU-R BT.2100 PQ", **kwargs: Any -) -> FloatingOrNDArray: +) -> NDArrayFloat: """ Map relative display linear light to scene linear light using given inverse opto-optical transfer function (OOTF / OOCF). @@ -1430,7 +1429,7 @@ def ootf_inverse( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Luminance of scene linear light. Examples diff --git a/colour/models/rgb/transfer_functions/aces.py b/colour/models/rgb/transfer_functions/aces.py index b408ac7a4b..8be271ebac 100644 --- a/colour/models/rgb/transfer_functions/aces.py +++ b/colour/models/rgb/transfer_functions/aces.py @@ -27,7 +27,7 @@ - :cite:`TheAcademyofMotionPictureArtsandSciences2014s` : The Academy of Motion Picture Arts and Sciences, Science and Technology Council, & Academy Color Encoding System (ACES) Project Subcommittee. (2013). Specification - S-2013-001 - ACESproxy, an Integer Log Encoding of ACES Image Data. + S-2013-001 - ACESproxy, an int Log Encoding of ACES Image Data. Retrieved December 19, 2014, from http://j.mp/S-2013-001 - :cite:`TheAcademyofMotionPictureArtsandSciences2014t` : The Academy of Motion Picture Arts and Sciences, Science and Technology Council, & Academy @@ -52,13 +52,9 @@ import numpy as np from colour.hints import ( - Boolean, - Dict, - Floating, - FloatingOrArrayLike, - FloatingOrNDArray, - IntegerOrArrayLike, - IntegerOrNDArray, + ArrayLike, + NDArrayFloat, + NDArrayInt, Literal, Union, ) @@ -108,7 +104,7 @@ ) """*ACESproxy* 12 bit constants.""" -CONSTANTS_ACES_PROXY: Dict = { +CONSTANTS_ACES_PROXY: dict = { 10: CONSTANTS_ACES_PROXY_10, 12: CONSTANTS_ACES_PROXY_12, } @@ -125,11 +121,11 @@ # pylint: disable=W0102 def log_encoding_ACESproxy( - lin_AP1: FloatingOrArrayLike, + lin_AP1: ArrayLike, bit_depth: Literal[10, 12] = 10, - out_int: Boolean = False, - constants: Dict = CONSTANTS_ACES_PROXY, -) -> Union[FloatingOrNDArray, IntegerOrNDArray]: + out_int: bool = False, + constants: dict = CONSTANTS_ACES_PROXY, +) -> Union[NDArrayFloat, NDArrayInt]: """ Define the *ACESproxy* colourspace log encoding curve / opto-electronic transfer function. @@ -141,14 +137,14 @@ def log_encoding_ACESproxy( bit_depth *ACESproxy* bit depth. out_in - Whether to return value as integer code value or float equivalent of a + Whether to return value as int code value or float equivalent of a code value at a given bit depth. constants *ACESproxy* constants. Returns ------- - :class:`numpy.floating` or :class:`numpy.integer` or :class:`numpy.ndarray` + :class:`numpy.ndarray` *ACESproxy* non-linear value. Notes @@ -165,8 +161,8 @@ def log_encoding_ACESproxy( | ``ACESproxy`` | [0, 1] | [0, 1] | +----------------+-----------------------+---------------+ - \\* This definition has an output integer switch, thus the domain-range - scale information is only given for the floating point mode. + \\* This definition has an output int switch, thus the domain-range + scale information is only given for the float point mode. References ---------- @@ -191,7 +187,7 @@ def log_encoding_ACESproxy( mid_log_offset = constants[bit_depth].mid_log_offset steps_per_stop = constants[bit_depth].steps_per_stop - def float_2_cv(x: Floating) -> Floating: + def float_2_cv(x: float) -> float: """Convert given numeric to code value.""" return np.maximum(CV_min, np.minimum(CV_max, np.round(x))) @@ -213,11 +209,11 @@ def float_2_cv(x: Floating) -> Floating: # pylint: disable=W0102 def log_decoding_ACESproxy( - ACESproxy: Union[FloatingOrArrayLike, IntegerOrArrayLike], + ACESproxy: Union[ArrayLike, ArrayLike], bit_depth: Literal[10, 12] = 10, - in_int: Boolean = False, - constants: Dict = CONSTANTS_ACES_PROXY, -) -> FloatingOrNDArray: + in_int: bool = False, + constants: dict = CONSTANTS_ACES_PROXY, +) -> NDArrayFloat: """ Define the *ACESproxy* colourspace log decoding curve / electro-optical transfer function. @@ -229,14 +225,14 @@ def log_decoding_ACESproxy( bit_depth *ACESproxy* bit depth. in_int - Whether to treat the input value as integer code value or float + Whether to treat the input value as int code value or float equivalent of a code value at a given bit depth. constants *ACESproxy* constants. Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` *lin_AP1* value. Notes @@ -253,8 +249,8 @@ def log_decoding_ACESproxy( | ``lin_AP1`` | [0, 1] | [0, 1] | +----------------+-----------------------+---------------+ - \\* This definition has an input integer switch, thus the domain-range - scale information is only given for the floating point mode. + \\* This definition has an input int switch, thus the domain-range + scale information is only given for the float point mode. References ---------- @@ -287,7 +283,7 @@ def log_decoding_ACESproxy( return as_float(from_range_1(lin_AP1)) -def log_encoding_ACEScc(lin_AP1: FloatingOrArrayLike) -> FloatingOrNDArray: +def log_encoding_ACEScc(lin_AP1: ArrayLike) -> NDArrayFloat: """ Define the *ACEScc* colourspace log encoding / opto-electronic transfer function. @@ -299,7 +295,7 @@ def log_encoding_ACEScc(lin_AP1: FloatingOrArrayLike) -> FloatingOrNDArray: Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` *ACEScc* non-linear value. Notes @@ -345,7 +341,7 @@ def log_encoding_ACEScc(lin_AP1: FloatingOrArrayLike) -> FloatingOrNDArray: return as_float(from_range_1(ACEScc)) -def log_decoding_ACEScc(ACEScc: FloatingOrArrayLike) -> FloatingOrNDArray: +def log_decoding_ACEScc(ACEScc: ArrayLike) -> NDArrayFloat: """ Define the *ACEScc* colourspace log decoding / electro-optical transfer function. @@ -357,7 +353,7 @@ def log_decoding_ACEScc(ACEScc: FloatingOrArrayLike) -> FloatingOrNDArray: Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` *lin_AP1* value. Notes @@ -405,8 +401,8 @@ def log_decoding_ACEScc(ACEScc: FloatingOrArrayLike) -> FloatingOrNDArray: # pylint: disable=W0102 def log_encoding_ACEScct( - lin_AP1: FloatingOrArrayLike, constants: Structure = CONSTANTS_ACES_CCT -) -> FloatingOrNDArray: + lin_AP1: ArrayLike, constants: Structure = CONSTANTS_ACES_CCT +) -> NDArrayFloat: """ Define the *ACEScct* colourspace log encoding / opto-electronic transfer function. @@ -420,7 +416,7 @@ def log_encoding_ACEScct( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` *ACEScct* non-linear value. Notes @@ -463,8 +459,8 @@ def log_encoding_ACEScct( # pylint: disable=W0102 def log_decoding_ACEScct( - ACEScct: FloatingOrArrayLike, constants: Structure = CONSTANTS_ACES_CCT -) -> FloatingOrNDArray: + ACEScct: ArrayLike, constants: Structure = CONSTANTS_ACES_CCT +) -> NDArrayFloat: """ Define the *ACEScct* colourspace log decoding / electro-optical transfer function. @@ -478,7 +474,7 @@ def log_decoding_ACEScct( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` *lin_AP1* value. References diff --git a/colour/models/rgb/transfer_functions/arib_std_b67.py b/colour/models/rgb/transfer_functions/arib_std_b67.py index d2355df021..b908b418da 100644 --- a/colour/models/rgb/transfer_functions/arib_std_b67.py +++ b/colour/models/rgb/transfer_functions/arib_std_b67.py @@ -21,7 +21,7 @@ import numpy as np -from colour.hints import FloatingOrArrayLike, FloatingOrNDArray +from colour.hints import ArrayLike, NDArrayFloat from colour.models.rgb.transfer_functions import gamma_function from colour.utilities import ( Structure, @@ -52,10 +52,10 @@ def oetf_ARIBSTDB67( - E: FloatingOrArrayLike, - r: FloatingOrArrayLike = 0.5, + E: ArrayLike, + r: ArrayLike = 0.5, constants: Structure = CONSTANTS_ARIBSTDB67, -) -> FloatingOrNDArray: +) -> NDArrayFloat: """ Define *ARIB STD-B67 (Hybrid Log-Gamma)* opto-electrical transfer function (OETF). @@ -73,7 +73,7 @@ def oetf_ARIBSTDB67( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Resulting non-linear signal :math:`E'`. Notes @@ -119,10 +119,10 @@ def oetf_ARIBSTDB67( def oetf_inverse_ARIBSTDB67( - E_p: FloatingOrArrayLike, - r: FloatingOrArrayLike = 0.5, + E_p: ArrayLike, + r: ArrayLike = 0.5, constants: Structure = CONSTANTS_ARIBSTDB67, -) -> FloatingOrNDArray: +) -> NDArrayFloat: """ Define *ARIB STD-B67 (Hybrid Log-Gamma)* inverse opto-electrical transfer function (OETF). @@ -138,7 +138,7 @@ def oetf_inverse_ARIBSTDB67( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Voltage :math:`E` normalised by the reference white level and proportional to the implicit light intensity that would be detected with a reference camera color channel R, G, B. diff --git a/colour/models/rgb/transfer_functions/arri.py b/colour/models/rgb/transfer_functions/arri.py index e2c156b307..b1acbf1f8c 100644 --- a/colour/models/rgb/transfer_functions/arri.py +++ b/colour/models/rgb/transfer_functions/arri.py @@ -21,7 +21,7 @@ import numpy as np -from colour.hints import FloatingOrArrayLike, FloatingOrNDArray, Literal, Union +from colour.hints import ArrayLike, NDArrayFloat, Literal, Union from colour.utilities import ( CanonicalMapping, Structure, @@ -551,7 +551,7 @@ def log_encoding_ARRILogC3( - x: FloatingOrArrayLike, + x: ArrayLike, firmware: Union[Literal["SUP 2.x", "SUP 3.x"], str] = "SUP 3.x", method: Union[ Literal["Linear Scene Exposure Factor", "Normalised Sensor Signal"], @@ -560,7 +560,7 @@ def log_encoding_ARRILogC3( EI: Literal[ 160, 200, 250, 320, 400, 500, 640, 800, 1000, 1280, 1600 ] = 800, -) -> FloatingOrNDArray: +) -> NDArrayFloat: """ Define the *ARRI LogC3* log encoding curve / opto-electronic transfer function. @@ -578,7 +578,7 @@ def log_encoding_ARRILogC3( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` *ARRI LogC3* encoded data :math:`t`. References @@ -621,7 +621,7 @@ def log_encoding_ARRILogC3( def log_decoding_ARRILogC3( - t: FloatingOrArrayLike, + t: ArrayLike, firmware: Union[Literal["SUP 2.x", "SUP 3.x"], str] = "SUP 3.x", method: Union[ Literal["Linear Scene Exposure Factor", "Normalised Sensor Signal"], @@ -630,7 +630,7 @@ def log_decoding_ARRILogC3( EI: Literal[ 160, 200, 250, 320, 400, 500, 640, 800, 1000, 1280, 1600 ] = 800, -) -> FloatingOrNDArray: +) -> NDArrayFloat: """ Define the *ARRI LogC3* log decoding curve / electro-optical transfer function. @@ -648,7 +648,7 @@ def log_decoding_ARRILogC3( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Linear data :math:`x`. Notes @@ -707,9 +707,9 @@ def log_decoding_ARRILogC3( def log_encoding_ARRILogC4( - E_scene: FloatingOrArrayLike, + E_scene: ArrayLike, constants: Structure = CONSTANTS_ARRILOGC4, -) -> FloatingOrNDArray: +) -> NDArrayFloat: """ Define the *ARRI LogC4* log encoding curve / opto-electronic transfer function. @@ -723,7 +723,7 @@ def log_encoding_ARRILogC4( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` *ARRI LogC4* encoded signal :math:`E'`. References @@ -768,9 +768,9 @@ def log_encoding_ARRILogC4( def log_decoding_ARRILogC4( - E_p: FloatingOrArrayLike, + E_p: ArrayLike, constants: Structure = CONSTANTS_ARRILOGC4, -) -> FloatingOrNDArray: +) -> NDArrayFloat: """ Define the *ARRI LogC4* log decoding curve / electro-optical transfer function. @@ -784,7 +784,7 @@ def log_decoding_ARRILogC4( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Linear data :math:`E_{scene}`. Notes diff --git a/colour/models/rgb/transfer_functions/blackmagic_design.py b/colour/models/rgb/transfer_functions/blackmagic_design.py index a2def561d9..988259c677 100644 --- a/colour/models/rgb/transfer_functions/blackmagic_design.py +++ b/colour/models/rgb/transfer_functions/blackmagic_design.py @@ -18,7 +18,7 @@ import numpy as np -from colour.hints import FloatingOrArrayLike, FloatingOrNDArray +from colour.hints import ArrayLike, NDArrayFloat from colour.utilities import Structure, as_float, from_range_1, to_domain_1 __author__ = "Colour Developers" @@ -46,9 +46,9 @@ def oetf_BlackmagicFilmGeneration5( - x: FloatingOrArrayLike, + x: ArrayLike, constants: Structure = CONSTANTS_BLACKMAGIC_FILM_GENERATION_5, -) -> FloatingOrNDArray: +) -> NDArrayFloat: """ Define the *Blackmagic Film Generation 5* opto-electronic transfer function (OETF). @@ -62,7 +62,7 @@ def oetf_BlackmagicFilmGeneration5( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Encoded value :math:`y`. Notes @@ -108,9 +108,9 @@ def oetf_BlackmagicFilmGeneration5( def oetf_inverse_BlackmagicFilmGeneration5( - y: FloatingOrArrayLike, + y: ArrayLike, constants: Structure = CONSTANTS_BLACKMAGIC_FILM_GENERATION_5, -) -> FloatingOrNDArray: +) -> NDArrayFloat: """ Define the *Blackmagic Film Generation 5* inverse opto-electronic transfer function (OETF). @@ -124,7 +124,7 @@ def oetf_inverse_BlackmagicFilmGeneration5( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Linear light value :math`x`. Notes diff --git a/colour/models/rgb/transfer_functions/canon.py b/colour/models/rgb/transfer_functions/canon.py index 00f4eedcac..2254db3b3a 100644 --- a/colour/models/rgb/transfer_functions/canon.py +++ b/colour/models/rgb/transfer_functions/canon.py @@ -33,10 +33,8 @@ import numpy as np from colour.hints import ( - Boolean, - FloatingOrArrayLike, - FloatingOrNDArray, - Integer, + ArrayLike, + NDArrayFloat, ) from colour.models.rgb.transfer_functions import full_to_legal, legal_to_full from colour.utilities import ( @@ -64,11 +62,11 @@ def log_encoding_CanonLog( - x: FloatingOrArrayLike, - bit_depth: Integer = 10, - out_normalised_code_value: Boolean = True, - in_reflection: Boolean = True, -) -> FloatingOrNDArray: + x: ArrayLike, + bit_depth: int = 10, + out_normalised_code_value: bool = True, + in_reflection: bool = True, +) -> NDArrayFloat: """ Define the *Canon Log* log encoding curve / opto-electronic transfer function. @@ -87,7 +85,7 @@ def log_encoding_CanonLog( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` *Canon Log* non-linear data. References @@ -143,11 +141,11 @@ def log_encoding_CanonLog( def log_decoding_CanonLog( - clog: FloatingOrArrayLike, - bit_depth: Integer = 10, - in_normalised_code_value: Boolean = True, - out_reflection: Boolean = True, -) -> FloatingOrNDArray: + clog: ArrayLike, + bit_depth: int = 10, + in_normalised_code_value: bool = True, + out_reflection: bool = True, +) -> NDArrayFloat: """ Define the *Canon Log* log decoding curve / electro-optical transfer function. @@ -166,7 +164,7 @@ def log_decoding_CanonLog( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Linear data :math:`x`. Notes @@ -210,11 +208,11 @@ def log_decoding_CanonLog( def log_encoding_CanonLog2( - x: FloatingOrArrayLike, - bit_depth: Integer = 10, - out_normalised_code_value: Boolean = True, - in_reflection: Boolean = True, -) -> FloatingOrNDArray: + x: ArrayLike, + bit_depth: int = 10, + out_normalised_code_value: bool = True, + in_reflection: bool = True, +) -> NDArrayFloat: """ Define the *Canon Log 2* log encoding curve / opto-electronic transfer function. @@ -233,7 +231,7 @@ def log_encoding_CanonLog2( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` *Canon Log 2* non-linear data. Notes @@ -280,11 +278,11 @@ def log_encoding_CanonLog2( def log_decoding_CanonLog2( - clog2: FloatingOrArrayLike, - bit_depth: Integer = 10, - in_normalised_code_value: Boolean = True, - out_reflection: Boolean = True, -) -> FloatingOrNDArray: + clog2: ArrayLike, + bit_depth: int = 10, + in_normalised_code_value: bool = True, + out_reflection: bool = True, +) -> NDArrayFloat: """ Define the *Canon Log 2* log decoding curve / electro-optical transfer function. @@ -303,7 +301,7 @@ def log_decoding_CanonLog2( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Linear data :math:`x`. Notes @@ -349,11 +347,11 @@ def log_decoding_CanonLog2( def log_encoding_CanonLog3( - x: FloatingOrArrayLike, - bit_depth: Integer = 10, - out_normalised_code_value: Boolean = True, - in_reflection: Boolean = True, -) -> FloatingOrNDArray: + x: ArrayLike, + bit_depth: int = 10, + out_normalised_code_value: bool = True, + in_reflection: bool = True, +) -> NDArrayFloat: """ Define the *Canon Log 3* log encoding curve / opto-electronic transfer function. @@ -372,7 +370,7 @@ def log_encoding_CanonLog3( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` *Canon Log 3* non-linear data. Notes @@ -442,11 +440,11 @@ def log_encoding_CanonLog3( def log_decoding_CanonLog3( - clog3: FloatingOrArrayLike, - bit_depth: Integer = 10, - in_normalised_code_value: Boolean = True, - out_reflection: Boolean = True, -) -> FloatingOrNDArray: + clog3: ArrayLike, + bit_depth: int = 10, + in_normalised_code_value: bool = True, + out_reflection: bool = True, +) -> NDArrayFloat: """ Define the *Canon Log 3* log decoding curve / electro-optical transfer function. @@ -465,7 +463,7 @@ def log_decoding_CanonLog3( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Linear data :math:`x`. Notes diff --git a/colour/models/rgb/transfer_functions/cineon.py b/colour/models/rgb/transfer_functions/cineon.py index 986ff74270..8a8d32209a 100644 --- a/colour/models/rgb/transfer_functions/cineon.py +++ b/colour/models/rgb/transfer_functions/cineon.py @@ -19,7 +19,7 @@ import numpy as np -from colour.hints import FloatingOrArrayLike, FloatingOrNDArray +from colour.hints import ArrayLike, NDArrayFloat from colour.utilities import ( as_float, as_float_array, @@ -41,9 +41,9 @@ def log_encoding_Cineon( - x: FloatingOrArrayLike, - black_offset: FloatingOrArrayLike = 10 ** ((95 - 685) / 300), -) -> FloatingOrNDArray: + x: ArrayLike, + black_offset: ArrayLike = 10 ** ((95 - 685) / 300), +) -> NDArrayFloat: """ Define the *Cineon* log encoding curve / opto-electronic transfer function. @@ -57,7 +57,7 @@ def log_encoding_Cineon( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Non-linear data :math:`y`. Notes @@ -93,9 +93,9 @@ def log_encoding_Cineon( def log_decoding_Cineon( - y: FloatingOrArrayLike, - black_offset: FloatingOrArrayLike = 10 ** ((95 - 685) / 300), -) -> FloatingOrNDArray: + y: ArrayLike, + black_offset: ArrayLike = 10 ** ((95 - 685) / 300), +) -> NDArrayFloat: """ Define the *Cineon* log decoding curve / electro-optical transfer function. @@ -109,7 +109,7 @@ def log_decoding_Cineon( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Linear data :math:`x`. Notes diff --git a/colour/models/rgb/transfer_functions/common.py b/colour/models/rgb/transfer_functions/common.py index 939ec53a9d..0a231eee83 100644 --- a/colour/models/rgb/transfer_functions/common.py +++ b/colour/models/rgb/transfer_functions/common.py @@ -10,13 +10,8 @@ import numpy as np from colour.hints import ( - Boolean, - FloatingOrArrayLike, - FloatingOrNDArray, - Integer, - IntegerOrArrayLike, - IntegerOrNDArray, - NDArray, + ArrayLike, + NDArrayNumber, Union, ) from colour.utilities import as_float, as_int, as_float_array, as_int_array @@ -36,8 +31,8 @@ def CV_range( - bit_depth: Integer = 10, is_legal: Boolean = False, is_int: Boolean = False -) -> NDArray: + bit_depth: int = 10, is_legal: bool = False, is_int: bool = False +) -> NDArrayNumber: """ Return the code value :math:`CV` range for given bit depth, range legality and representation. @@ -49,7 +44,7 @@ def CV_range( is_legal Whether the code value :math:`CV` range is legal. is_int - Whether the code value :math:`CV` range represents integer code values. + Whether the code value :math:`CV` range represents int code values. Returns ------- @@ -79,11 +74,11 @@ def CV_range( def legal_to_full( - CV: Union[FloatingOrArrayLike, IntegerOrArrayLike], - bit_depth: Integer = 10, - in_int: Boolean = False, - out_int: Boolean = False, -) -> Union[FloatingOrNDArray, IntegerOrNDArray]: + CV: Union[ArrayLike, ArrayLike], + bit_depth: int = 10, + in_int: bool = False, + out_int: bool = False, +) -> NDArrayNumber: """ Convert given code value :math:`CV` or float equivalent of a code value at a given bit depth from legal range (studio swing) to full range @@ -97,15 +92,15 @@ def legal_to_full( bit_depth Bit depth used for conversion. in_int - Whether to treat the input value as integer code value or float + Whether to treat the input value as int code value or float equivalent of a code value at a given bit depth. out_int - Whether to return value as integer code value or float equivalent of a + Whether to return value as int code value or float equivalent of a code value at a given bit depth. Returns ------- - :class:`numpy.floating` or :class:`numpy.integer` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Full range code value :math:`CV` or float equivalent of a code value at a given bit depth. @@ -146,11 +141,11 @@ def legal_to_full( def full_to_legal( - CV: Union[FloatingOrArrayLike, IntegerOrArrayLike], - bit_depth: Integer = 10, - in_int: Boolean = False, - out_int: Boolean = False, -) -> Union[FloatingOrNDArray, IntegerOrNDArray]: + CV: Union[ArrayLike, ArrayLike], + bit_depth: int = 10, + in_int: bool = False, + out_int: bool = False, +) -> NDArrayNumber: """ Convert given code value :math:`CV` or float equivalent of a code value at a given bit depth from full range (full swing) to legal range @@ -164,15 +159,15 @@ def full_to_legal( bit_depth Bit depth used for conversion. in_int - Whether to treat the input value as integer code value or float + Whether to treat the input value as int code value or float equivalent of a code value at a given bit depth. out_int - Whether to return value as integer code value or float equivalent of a + Whether to return value as int code value or float equivalent of a code value at a given bit depth. Returns ------- - :class:`numpy.floating` or :class:`numpy.integer` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Legal range code value :math:`CV` or float equivalent of a code value at a given bit depth. diff --git a/colour/models/rgb/transfer_functions/davinci_intermediate.py b/colour/models/rgb/transfer_functions/davinci_intermediate.py index 527d0d76b5..29880077fb 100644 --- a/colour/models/rgb/transfer_functions/davinci_intermediate.py +++ b/colour/models/rgb/transfer_functions/davinci_intermediate.py @@ -20,7 +20,7 @@ import numpy as np -from colour.hints import FloatingOrArrayLike, FloatingOrNDArray +from colour.hints import ArrayLike, NDArrayFloat from colour.utilities import Structure, as_float, from_range_1, to_domain_1 __author__ = "Colour Developers" @@ -48,9 +48,9 @@ def oetf_DaVinciIntermediate( - L: FloatingOrArrayLike, + L: ArrayLike, constants: Structure = CONSTANTS_DAVINCI_INTERMEDIATE, -) -> FloatingOrNDArray: +) -> NDArrayFloat: """ Define the *DaVinci Intermediate* opto-electronic transfer function. @@ -63,7 +63,7 @@ def oetf_DaVinciIntermediate( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Encoded value :math:`V`. Notes @@ -108,9 +108,9 @@ def oetf_DaVinciIntermediate( def oetf_inverse_DaVinciIntermediate( - V: FloatingOrArrayLike, + V: ArrayLike, constants: Structure = CONSTANTS_DAVINCI_INTERMEDIATE, -) -> FloatingOrNDArray: +) -> NDArrayFloat: """ Define the *DaVinci Intermediate* inverse opto-electronic transfer function (OETF). @@ -124,7 +124,7 @@ def oetf_inverse_DaVinciIntermediate( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Linear light value :math`L`. Notes diff --git a/colour/models/rgb/transfer_functions/dcdm.py b/colour/models/rgb/transfer_functions/dcdm.py index 05ce0797a7..1a3e6d3eee 100644 --- a/colour/models/rgb/transfer_functions/dcdm.py +++ b/colour/models/rgb/transfer_functions/dcdm.py @@ -25,11 +25,9 @@ from colour.algebra import spow from colour.hints import ( - Boolean, - FloatingOrArrayLike, - FloatingOrNDArray, - IntegerOrArrayLike, - IntegerOrNDArray, + ArrayLike, + NDArrayFloat, + NDArrayInt, Union, ) from colour.utilities import as_float_array, as_float, as_int @@ -48,8 +46,8 @@ def eotf_inverse_DCDM( - XYZ: FloatingOrArrayLike, out_int: Boolean = False -) -> Union[FloatingOrNDArray, IntegerOrNDArray]: + XYZ: ArrayLike, out_int: bool = False +) -> Union[NDArrayFloat, NDArrayInt]: """ Define the *DCDM* inverse electro-optical transfer function (EOTF). @@ -58,12 +56,12 @@ def eotf_inverse_DCDM( XYZ *CIE XYZ* tristimulus values. out_int - Whether to return value as integer code value or float equivalent of a + Whether to return value as int code value or float equivalent of a code value at a given bit depth. Returns ------- - :class:`numpy.floating` or :class:`numpy.integer` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Non-linear *CIE XYZ'* tristimulus values. Warnings @@ -88,8 +86,8 @@ def eotf_inverse_DCDM( | ``XYZ_p`` | ``UN`` | ``UN`` | +----------------+-----------------------+---------------+ - \\* This definition has an output integer switch, thus the domain-range - scale information is only given for the floating point mode. + \\* This definition has an output int switch, thus the domain-range + scale information is only given for the float point mode. References ---------- @@ -114,9 +112,9 @@ def eotf_inverse_DCDM( def eotf_DCDM( - XYZ_p: Union[FloatingOrArrayLike, IntegerOrArrayLike], - in_int: Boolean = False, -) -> FloatingOrNDArray: + XYZ_p: Union[ArrayLike, ArrayLike], + in_int: bool = False, +) -> NDArrayFloat: """ Define the *DCDM* electro-optical transfer function (EOTF). @@ -125,12 +123,12 @@ def eotf_DCDM( XYZ_p Non-linear *CIE XYZ'* tristimulus values. in_int - Whether to treat the input value as integer code value or float + Whether to treat the input value as int code value or float equivalent of a code value at a given bit depth. Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` *CIE XYZ* tristimulus values. Warnings @@ -155,8 +153,8 @@ def eotf_DCDM( | ``XYZ`` | ``UN`` | ``UN`` | +----------------+-----------------------+---------------+ - \\* This definition has an input integer switch, thus the domain-range - scale information is only given for the floating point mode. + \\* This definition has an input int switch, thus the domain-range + scale information is only given for the float point mode. References ---------- diff --git a/colour/models/rgb/transfer_functions/dicom_gsdf.py b/colour/models/rgb/transfer_functions/dicom_gsdf.py index c6c4924272..4ad0761b02 100644 --- a/colour/models/rgb/transfer_functions/dicom_gsdf.py +++ b/colour/models/rgb/transfer_functions/dicom_gsdf.py @@ -28,11 +28,9 @@ import numpy as np from colour.hints import ( - Boolean, - FloatingOrArrayLike, - FloatingOrNDArray, - IntegerOrArrayLike, - IntegerOrNDArray, + ArrayLike, + NDArrayFloat, + NDArrayInt, Union, ) from colour.utilities import ( @@ -81,10 +79,10 @@ def eotf_inverse_DICOMGSDF( - L: FloatingOrArrayLike, - out_int: Boolean = False, + L: ArrayLike, + out_int: bool = False, constants: Structure = CONSTANTS_DICOMGSDF, -) -> Union[FloatingOrNDArray, IntegerOrNDArray]: +) -> Union[NDArrayFloat, NDArrayInt]: """ Define the *DICOM - Grayscale Standard Display Function* inverse electro-optical transfer function (EOTF). @@ -94,14 +92,14 @@ def eotf_inverse_DICOMGSDF( L *Luminance* :math:`L`. out_int - Whether to return value as integer code value or float equivalent of a + Whether to return value as int code value or float equivalent of a code value at a given bit depth. constants *DICOM - Grayscale Standard Display Function* constants. Returns ------- - :class:`numpy.floating` or :class:`numpy.integer` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Just-Noticeable Difference (JND) Index, :math:`j`. Notes @@ -163,10 +161,10 @@ def eotf_inverse_DICOMGSDF( def eotf_DICOMGSDF( - J: Union[FloatingOrArrayLike, IntegerOrArrayLike], - in_int: Boolean = False, + J: Union[ArrayLike, ArrayLike], + in_int: bool = False, constants: Structure = CONSTANTS_DICOMGSDF, -) -> FloatingOrNDArray: +) -> NDArrayFloat: """ Define the *DICOM - Grayscale Standard Display Function* electro-optical transfer function (EOTF). @@ -176,14 +174,14 @@ def eotf_DICOMGSDF( J Just-Noticeable Difference (JND) Index, :math:`j`. in_int - Whether to treat the input value as integer code value or float + Whether to treat the input value as int code value or float equivalent of a code value at a given bit depth. constants *DICOM - Grayscale Standard Display Function* constants. Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Corresponding *luminance* :math:`L`. Notes diff --git a/colour/models/rgb/transfer_functions/dji_d_log.py b/colour/models/rgb/transfer_functions/dji_d_log.py index 445e474233..31c43a3a46 100644 --- a/colour/models/rgb/transfer_functions/dji_d_log.py +++ b/colour/models/rgb/transfer_functions/dji_d_log.py @@ -19,7 +19,7 @@ import numpy as np -from colour.hints import FloatingOrArrayLike, FloatingOrNDArray +from colour.hints import ArrayLike, NDArrayFloat from colour.utilities import as_float, from_range_1, to_domain_1 __author__ = "Colour Developers" @@ -35,7 +35,7 @@ ] -def log_encoding_DJIDLog(x: FloatingOrArrayLike) -> FloatingOrNDArray: +def log_encoding_DJIDLog(x: ArrayLike) -> NDArrayFloat: """ Define the *DJI D-Log* log encoding curve. @@ -46,7 +46,7 @@ def log_encoding_DJIDLog(x: FloatingOrArrayLike) -> FloatingOrNDArray: Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` *DJI D-Log* encoded data :math:`y`. References @@ -84,7 +84,7 @@ def log_encoding_DJIDLog(x: FloatingOrArrayLike) -> FloatingOrNDArray: return as_float(from_range_1(y)) -def log_decoding_DJIDLog(y: FloatingOrArrayLike) -> FloatingOrNDArray: +def log_decoding_DJIDLog(y: ArrayLike) -> NDArrayFloat: """ Define the *DJI D-Log* log decoding curve. @@ -95,7 +95,7 @@ def log_decoding_DJIDLog(y: FloatingOrArrayLike) -> FloatingOrNDArray: Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Linear reflection data :math`x`. References diff --git a/colour/models/rgb/transfer_functions/exponent.py b/colour/models/rgb/transfer_functions/exponent.py index 52ed885cf4..1bbc3bb77e 100644 --- a/colour/models/rgb/transfer_functions/exponent.py +++ b/colour/models/rgb/transfer_functions/exponent.py @@ -21,10 +21,9 @@ from colour.algebra import sdiv, sdiv_mode from colour.hints import ( - FloatingOrArrayLike, - FloatingOrNDArray, + ArrayLike, Literal, - NDArray, + NDArrayFloat, Union, ) from colour.utilities import ( @@ -48,8 +47,8 @@ def exponent_function_basic( - x: FloatingOrArrayLike, - exponent: FloatingOrArrayLike = 1, + x: ArrayLike, + exponent: ArrayLike = 1, style: Union[ Literal[ "basicFwd", @@ -61,7 +60,7 @@ def exponent_function_basic( ], str, ] = "basicFwd", -) -> FloatingOrNDArray: +) -> NDArrayFloat: """ Define the *basic* exponent transfer function. @@ -101,7 +100,7 @@ def exponent_function_basic( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Exponentially converted data. Examples @@ -163,12 +162,12 @@ def exponent_function_basic( '"{0}" style is invalid, it must be one of {1}!', ) - def exponent_forward(x: NDArray) -> NDArray: + def exponent_forward(x: NDArrayFloat) -> NDArrayFloat: """Return the input raised to the exponent value.""" return x**exponent - def exponent_reverse(y: NDArray) -> NDArray: + def exponent_reverse(y: NDArrayFloat) -> NDArrayFloat: """Return the input raised to the inverse exponent value.""" return y ** (as_float_array(1) / exponent) @@ -196,9 +195,9 @@ def exponent_reverse(y: NDArray) -> NDArray: def exponent_function_monitor_curve( - x: FloatingOrArrayLike, - exponent: FloatingOrArrayLike = 1, - offset: FloatingOrArrayLike = 0, + x: ArrayLike, + exponent: ArrayLike = 1, + offset: ArrayLike = 0, style: Union[ Literal[ "monCurveFwd", @@ -208,7 +207,7 @@ def exponent_function_monitor_curve( ], str, ] = "monCurveFwd", -) -> FloatingOrNDArray: +) -> NDArrayFloat: """ Define the *Monitor Curve* exponent transfer function. @@ -240,7 +239,7 @@ def exponent_function_monitor_curve( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Exponentially converted data. Examples @@ -299,8 +298,8 @@ def exponent_function_monitor_curve( ) def monitor_curve_forward( - x: NDArray, offset: NDArray, exponent: NDArray - ) -> NDArray: + x: NDArrayFloat, offset: NDArrayFloat, exponent: NDArrayFloat + ) -> NDArrayFloat: """Define the *Monitor Curve Forward* function.""" with sdiv_mode(): @@ -315,8 +314,8 @@ def monitor_curve_forward( return y def monitor_curve_reverse( - y: NDArray, offset: NDArray, exponent: NDArray - ) -> NDArray: + y: NDArrayFloat, offset: NDArrayFloat, exponent: NDArrayFloat + ) -> NDArrayFloat: """Define the *Monitor Curve Reverse* function.""" with sdiv_mode(): diff --git a/colour/models/rgb/transfer_functions/filmic_pro.py b/colour/models/rgb/transfer_functions/filmic_pro.py index e1e42bf1a4..e1513f9edf 100644 --- a/colour/models/rgb/transfer_functions/filmic_pro.py +++ b/colour/models/rgb/transfer_functions/filmic_pro.py @@ -19,8 +19,8 @@ from colour.algebra import Extrapolator, LinearInterpolator from colour.hints import ( - FloatingOrArrayLike, - FloatingOrNDArray, + ArrayLike, + NDArrayFloat, Optional, ) from colour.utilities import as_float, from_range_1, to_domain_1 @@ -38,7 +38,7 @@ ] -def log_encoding_FilmicPro6(t: FloatingOrArrayLike) -> FloatingOrNDArray: +def log_encoding_FilmicPro6(t: ArrayLike) -> NDArrayFloat: """ Define the *FiLMiC Pro 6* log encoding curve / opto-electronic transfer function. @@ -50,7 +50,7 @@ def log_encoding_FilmicPro6(t: FloatingOrArrayLike) -> FloatingOrNDArray: Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Non-linear data :math:`y`. Notes @@ -120,7 +120,7 @@ def _log_decoding_FilmicPro6_interpolator() -> Extrapolator: return _CACHE_LOG_DECODING_FILMICPRO_INTERPOLATOR -def log_decoding_FilmicPro6(y: FloatingOrArrayLike) -> FloatingOrNDArray: +def log_decoding_FilmicPro6(y: ArrayLike) -> NDArrayFloat: """ Define the *FiLMiC Pro 6* log decoding curve / electro-optical transfer function. @@ -132,7 +132,7 @@ def log_decoding_FilmicPro6(y: FloatingOrArrayLike) -> FloatingOrNDArray: Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Linear data :math:`t`. Notes diff --git a/colour/models/rgb/transfer_functions/filmlight_t_log.py b/colour/models/rgb/transfer_functions/filmlight_t_log.py index 1bc2721db6..d24e81f5ef 100644 --- a/colour/models/rgb/transfer_functions/filmlight_t_log.py +++ b/colour/models/rgb/transfer_functions/filmlight_t_log.py @@ -17,7 +17,7 @@ import numpy as np -from colour.hints import Floating, FloatingOrArrayLike, FloatingOrNDArray +from colour.hints import ArrayLike, NDArrayFloat from colour.utilities import as_float, from_range_1, to_domain_1 __author__ = "Colour Developers" @@ -34,11 +34,11 @@ def log_encoding_FilmLightTLog( - x: FloatingOrArrayLike, - w: Floating = 128.0, - g: Floating = 16.0, - o: Floating = 0.075, -) -> FloatingOrNDArray: + x: ArrayLike, + w: float = 128.0, + g: float = 16.0, + o: float = 0.075, +) -> NDArrayFloat: """ Define the *FilmLight T-Log* log encoding curve. @@ -55,7 +55,7 @@ def log_encoding_FilmLightTLog( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` *FilmLight T-Log* encoded data :math:`t`. References @@ -128,11 +128,11 @@ def log_encoding_FilmLightTLog( def log_decoding_FilmLightTLog( - t: FloatingOrArrayLike, - w: Floating = 128.0, - g: Floating = 16.0, - o: Floating = 0.075, -) -> FloatingOrNDArray: + t: ArrayLike, + w: float = 128.0, + g: float = 16.0, + o: float = 0.075, +) -> NDArrayFloat: """ Define the *FilmLight T-Log* log decoding curve. @@ -149,7 +149,7 @@ def log_decoding_FilmLightTLog( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Linear reflection data :math`x`. References diff --git a/colour/models/rgb/transfer_functions/fujifilm_f_log.py b/colour/models/rgb/transfer_functions/fujifilm_f_log.py index b2417f67fd..cf5840320e 100644 --- a/colour/models/rgb/transfer_functions/fujifilm_f_log.py +++ b/colour/models/rgb/transfer_functions/fujifilm_f_log.py @@ -19,10 +19,8 @@ import numpy as np from colour.hints import ( - Boolean, - FloatingOrArrayLike, - FloatingOrNDArray, - Integer, + ArrayLike, + NDArrayFloat, ) from colour.models.rgb.transfer_functions import full_to_legal, legal_to_full from colour.utilities import Structure, as_float, from_range_1, to_domain_1 @@ -54,12 +52,12 @@ def log_encoding_FLog( - in_r: FloatingOrArrayLike, - bit_depth: Integer = 10, - out_normalised_code_value: Boolean = True, - in_reflection: Boolean = True, + in_r: ArrayLike, + bit_depth: int = 10, + out_normalised_code_value: bool = True, + in_reflection: bool = True, constants: Structure = CONSTANTS_FLOG, -) -> FloatingOrNDArray: +) -> NDArrayFloat: """ Define the *Fujifilm F-Log* log encoding curve / opto-electronic transfer function. @@ -80,7 +78,7 @@ def log_encoding_FLog( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Non-linear data :math:`out`. Notes @@ -143,12 +141,12 @@ def log_encoding_FLog( def log_decoding_FLog( - out_r: FloatingOrArrayLike, - bit_depth: Integer = 10, - in_normalised_code_value: Boolean = True, - out_reflection: Boolean = True, + out_r: ArrayLike, + bit_depth: int = 10, + in_normalised_code_value: bool = True, + out_reflection: bool = True, constants: Structure = CONSTANTS_FLOG, -) -> FloatingOrNDArray: +) -> NDArrayFloat: """ Define the *Fujifilm F-Log* log decoding curve / electro-optical transfer function. @@ -169,7 +167,7 @@ def log_decoding_FLog( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Linear reflection data :math`in`. Notes diff --git a/colour/models/rgb/transfer_functions/gamma.py b/colour/models/rgb/transfer_functions/gamma.py index 6e652870f9..eb40571b06 100644 --- a/colour/models/rgb/transfer_functions/gamma.py +++ b/colour/models/rgb/transfer_functions/gamma.py @@ -14,8 +14,8 @@ from colour.algebra import spow from colour.hints import ( - FloatingOrArrayLike, - FloatingOrNDArray, + ArrayLike, + NDArrayFloat, Literal, Union, ) @@ -34,12 +34,12 @@ def gamma_function( - a: FloatingOrArrayLike, - exponent: FloatingOrArrayLike = 1, + a: ArrayLike, + exponent: ArrayLike = 1, negative_number_handling: Union[ Literal["Clamp", "Indeterminate", "Mirror", "Preserve"], str ] = "Indeterminate", -) -> FloatingOrNDArray: +) -> NDArrayFloat: """ Define a typical gamma encoding / decoding function. @@ -65,7 +65,7 @@ def gamma_function( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Encoded / decoded array. Examples diff --git a/colour/models/rgb/transfer_functions/gopro.py b/colour/models/rgb/transfer_functions/gopro.py index 9754d808cd..b759e5f81e 100644 --- a/colour/models/rgb/transfer_functions/gopro.py +++ b/colour/models/rgb/transfer_functions/gopro.py @@ -19,7 +19,7 @@ import numpy as np -from colour.hints import FloatingOrArrayLike, FloatingOrNDArray +from colour.hints import ArrayLike, NDArrayFloat from colour.utilities import as_float, from_range_1, to_domain_1 __author__ = "Colour Developers" @@ -35,7 +35,7 @@ ] -def log_encoding_Protune(x: FloatingOrArrayLike) -> FloatingOrNDArray: +def log_encoding_Protune(x: ArrayLike) -> NDArrayFloat: """ Define the *Protune* log encoding curve / opto-electronic transfer function. @@ -47,7 +47,7 @@ def log_encoding_Protune(x: FloatingOrArrayLike) -> FloatingOrNDArray: Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Non-linear data :math:`y`. Notes @@ -81,7 +81,7 @@ def log_encoding_Protune(x: FloatingOrArrayLike) -> FloatingOrNDArray: return as_float(from_range_1(y)) -def log_decoding_Protune(y: FloatingOrArrayLike) -> FloatingOrNDArray: +def log_decoding_Protune(y: ArrayLike) -> NDArrayFloat: """ Define the *Protune* log decoding curve / electro-optical transfer function. @@ -93,7 +93,7 @@ def log_decoding_Protune(y: FloatingOrArrayLike) -> FloatingOrNDArray: Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Linear data :math:`x`. Notes diff --git a/colour/models/rgb/transfer_functions/itur_bt_1361.py b/colour/models/rgb/transfer_functions/itur_bt_1361.py index c6ee1a0866..210c824170 100644 --- a/colour/models/rgb/transfer_functions/itur_bt_1361.py +++ b/colour/models/rgb/transfer_functions/itur_bt_1361.py @@ -53,7 +53,7 @@ def oetf_BT1361(L): Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Corresponding non-linear primary signal :math:`E'`. Notes @@ -114,7 +114,7 @@ def oetf_inverse_BT1361(E_p): Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Corresponding scene *Luminance* :math:`L`. Notes diff --git a/colour/models/rgb/transfer_functions/itur_bt_1886.py b/colour/models/rgb/transfer_functions/itur_bt_1886.py index 39c3978f60..d3541c1c67 100644 --- a/colour/models/rgb/transfer_functions/itur_bt_1886.py +++ b/colour/models/rgb/transfer_functions/itur_bt_1886.py @@ -22,7 +22,7 @@ import numpy as np -from colour.hints import Floating, FloatingOrArrayLike, FloatingOrNDArray +from colour.hints import ArrayLike, NDArrayFloat from colour.utilities import as_float, from_range_1, to_domain_1 __author__ = "Colour Developers" @@ -39,8 +39,8 @@ def eotf_inverse_BT1886( - L: FloatingOrArrayLike, L_B: Floating = 0, L_W: Floating = 1 -) -> FloatingOrNDArray: + L: ArrayLike, L_B: float = 0, L_W: float = 1 +) -> NDArrayFloat: """ Define *Recommendation ITU-R BT.1886* inverse electro-optical transfer function (EOTF). @@ -56,7 +56,7 @@ def eotf_inverse_BT1886( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Input video signal level (normalised, black at :math:`V = 0`, to white at :math:`V = 1`. @@ -98,9 +98,7 @@ def eotf_inverse_BT1886( return as_float(from_range_1(V)) -def eotf_BT1886( - V: FloatingOrArrayLike, L_B: Floating = 0, L_W: Floating = 1 -) -> FloatingOrNDArray: +def eotf_BT1886(V: ArrayLike, L_B: float = 0, L_W: float = 1) -> NDArrayFloat: """ Define *Recommendation ITU-R BT.1886* electro-optical transfer function (EOTF). @@ -120,7 +118,7 @@ def eotf_BT1886( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Screen luminance in :math:`cd/m^2`. Notes diff --git a/colour/models/rgb/transfer_functions/itur_bt_2020.py b/colour/models/rgb/transfer_functions/itur_bt_2020.py index 256c6b45bf..e4bd865917 100644 --- a/colour/models/rgb/transfer_functions/itur_bt_2020.py +++ b/colour/models/rgb/transfer_functions/itur_bt_2020.py @@ -23,7 +23,7 @@ import numpy as np from colour.algebra import spow -from colour.hints import Boolean, FloatingOrArrayLike, FloatingOrNDArray +from colour.hints import ArrayLike, NDArrayFloat from colour.utilities import ( Structure, as_float, @@ -66,10 +66,10 @@ def oetf_BT2020( - E: FloatingOrArrayLike, - is_12_bits_system: Boolean = False, + E: ArrayLike, + is_12_bits_system: bool = False, constants: Structure = CONSTANTS_BT2020, -) -> FloatingOrNDArray: +) -> NDArrayFloat: """ Define *Recommendation ITU-R BT.2020* opto-electronic transfer function (OETF). @@ -87,7 +87,7 @@ def oetf_BT2020( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Resulting non-linear signal :math:`E'`. Notes @@ -125,10 +125,10 @@ def oetf_BT2020( def oetf_inverse_BT2020( - E_p: FloatingOrArrayLike, - is_12_bits_system: Boolean = False, + E_p: ArrayLike, + is_12_bits_system: bool = False, constants: Structure = CONSTANTS_BT2020, -) -> FloatingOrNDArray: +) -> NDArrayFloat: """ Define *Recommendation ITU-R BT.2020* inverse opto-electronic transfer function (OETF). @@ -144,7 +144,7 @@ def oetf_inverse_BT2020( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Resulting voltage :math:`E`. Notes diff --git a/colour/models/rgb/transfer_functions/itur_bt_2100.py b/colour/models/rgb/transfer_functions/itur_bt_2100.py index 7b3ebfe3f9..a80ed7115e 100644 --- a/colour/models/rgb/transfer_functions/itur_bt_2100.py +++ b/colour/models/rgb/transfer_functions/itur_bt_2100.py @@ -57,11 +57,9 @@ from colour.algebra import spow from colour.hints import ( - Floating, - FloatingOrArrayLike, - FloatingOrNDArray, + ArrayLike, Literal, - NDArray, + NDArrayFloat, Optional, Union, ) @@ -134,7 +132,7 @@ ] -def oetf_BT2100_PQ(E: FloatingOrArrayLike) -> FloatingOrNDArray: +def oetf_BT2100_PQ(E: ArrayLike) -> NDArrayFloat: """ Define *Recommendation ITU-R BT.2100* *Reference PQ* opto-electrical transfer function (OETF). @@ -150,7 +148,7 @@ def oetf_BT2100_PQ(E: FloatingOrArrayLike) -> FloatingOrNDArray: Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` :math:`E'` is the resulting non-linear signal (:math:`R'`, :math:`G'`, :math:`B'`). @@ -181,7 +179,7 @@ def oetf_BT2100_PQ(E: FloatingOrArrayLike) -> FloatingOrNDArray: return eotf_inverse_ST2084(ootf_BT2100_PQ(E), 10000) -def oetf_inverse_BT2100_PQ(E_p: FloatingOrArrayLike) -> FloatingOrNDArray: +def oetf_inverse_BT2100_PQ(E_p: ArrayLike) -> NDArrayFloat: """ Define *Recommendation ITU-R BT.2100* *Reference PQ* inverse opto-electrical transfer function (OETF). @@ -194,7 +192,7 @@ def oetf_inverse_BT2100_PQ(E_p: FloatingOrArrayLike) -> FloatingOrNDArray: Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` :math:`E = {R_S, G_S, B_S; Y_S; or I_S}` is the signal determined by scene light and scaled by camera exposure. @@ -225,7 +223,7 @@ def oetf_inverse_BT2100_PQ(E_p: FloatingOrArrayLike) -> FloatingOrNDArray: return ootf_inverse_BT2100_PQ(eotf_ST2084(E_p, 10000)) -def eotf_BT2100_PQ(E_p: FloatingOrArrayLike) -> FloatingOrNDArray: +def eotf_BT2100_PQ(E_p: ArrayLike) -> NDArrayFloat: """ Define *Recommendation ITU-R BT.2100* *Reference PQ* electro-optical transfer function (EOTF). @@ -240,7 +238,7 @@ def eotf_BT2100_PQ(E_p: FloatingOrArrayLike) -> FloatingOrNDArray: Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` :math:`F_D` is the luminance of a displayed linear component :math:`{R_D, G_D, B_D}` or :math:`Y_D` or :math:`I_D`, in :math:`cd/m^2`. @@ -272,7 +270,7 @@ def eotf_BT2100_PQ(E_p: FloatingOrArrayLike) -> FloatingOrNDArray: return eotf_ST2084(E_p, 10000) -def eotf_inverse_BT2100_PQ(F_D: FloatingOrArrayLike) -> FloatingOrNDArray: +def eotf_inverse_BT2100_PQ(F_D: ArrayLike) -> NDArrayFloat: """ Define *Recommendation ITU-R BT.2100* *Reference PQ* inverse electro-optical transfer function (EOTF). @@ -286,7 +284,7 @@ def eotf_inverse_BT2100_PQ(F_D: FloatingOrArrayLike) -> FloatingOrNDArray: Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` :math:`E'` denotes a non-linear colour value :math:`{R', G', B'}` or :math:`{L', M', S'}` in *PQ* space [0, 1]. @@ -317,7 +315,7 @@ def eotf_inverse_BT2100_PQ(F_D: FloatingOrArrayLike) -> FloatingOrNDArray: return eotf_inverse_ST2084(F_D, 10000) -def ootf_BT2100_PQ(E: FloatingOrArrayLike) -> FloatingOrNDArray: +def ootf_BT2100_PQ(E: ArrayLike) -> NDArrayFloat: """ Define *Recommendation ITU-R BT.2100* *Reference PQ* opto-optical transfer function (OOTF / OOCF). @@ -332,7 +330,7 @@ def ootf_BT2100_PQ(E: FloatingOrArrayLike) -> FloatingOrNDArray: Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` :math:`F_D` is the luminance of a displayed linear component (:math:`R_D`, :math:`G_D`, :math:`B_D`; :math:`Y_D`; or :math:`I_D`). @@ -366,7 +364,7 @@ def ootf_BT2100_PQ(E: FloatingOrArrayLike) -> FloatingOrNDArray: return 100 * eotf_BT1886(oetf_BT709(59.5208 * E)) -def ootf_inverse_BT2100_PQ(F_D: FloatingOrArrayLike) -> FloatingOrNDArray: +def ootf_inverse_BT2100_PQ(F_D: ArrayLike) -> NDArrayFloat: """ Define *Recommendation ITU-R BT.2100* *Reference PQ* inverse opto-optical transfer function (OOTF / OOCF). @@ -379,7 +377,7 @@ def ootf_inverse_BT2100_PQ(F_D: FloatingOrArrayLike) -> FloatingOrNDArray: Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` :math:`E = {R_S, G_S, B_S; Y_S; or I_S}` is the signal determined by scene light and scaled by camera exposure. @@ -413,7 +411,7 @@ def ootf_inverse_BT2100_PQ(F_D: FloatingOrArrayLike) -> FloatingOrNDArray: return oetf_inverse_BT709(eotf_inverse_BT1886(F_D / 100)) / 59.5208 -WEIGHTS_BT2100_HLG: NDArray = np.array([0.2627, 0.6780, 0.0593]) +WEIGHTS_BT2100_HLG: NDArrayFloat = np.array([0.2627, 0.6780, 0.0593]) """Luminance weights for *Recommendation ITU-R BT.2100* *Reference HLG*.""" CONSTANTS_BT2100_HLG: Structure = Structure( @@ -432,7 +430,7 @@ def ootf_inverse_BT2100_PQ(F_D: FloatingOrArrayLike) -> FloatingOrNDArray: """ -def gamma_function_BT2100_HLG(L_W: Floating = 1000) -> Floating: +def gamma_function_BT2100_HLG(L_W: float = 1000) -> float: """ Return the *Reference HLG* system gamma value for given display nominal peak luminance. @@ -445,7 +443,7 @@ def gamma_function_BT2100_HLG(L_W: Floating = 1000) -> Floating: Returns ------- - :class:`numpy.floating` + :class:`float` *Reference HLG* system gamma value. Examples @@ -464,8 +462,8 @@ def gamma_function_BT2100_HLG(L_W: Floating = 1000) -> Floating: def oetf_BT2100_HLG( - E: FloatingOrArrayLike, constants: Structure = CONSTANTS_BT2100_HLG -) -> FloatingOrNDArray: + E: ArrayLike, constants: Structure = CONSTANTS_BT2100_HLG +) -> NDArrayFloat: """ Define *Recommendation ITU-R BT.2100* *Reference HLG* opto-electrical transfer function (OETF). @@ -484,7 +482,7 @@ def oetf_BT2100_HLG( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` :math:`E'` is the resulting non-linear signal :math:`{R', G', B'}`. Notes @@ -517,8 +515,8 @@ def oetf_BT2100_HLG( def oetf_inverse_BT2100_HLG( - E_p: FloatingOrArrayLike, constants: Structure = CONSTANTS_BT2100_HLG -) -> FloatingOrNDArray: + E_p: ArrayLike, constants: Structure = CONSTANTS_BT2100_HLG +) -> NDArrayFloat: """ Define *Recommendation ITU-R BT.2100* *Reference HLG* inverse opto-electrical transfer function (OETF). @@ -532,7 +530,7 @@ def oetf_inverse_BT2100_HLG( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` :math:`E` is the signal for each colour component :math:`{R_S, G_S, B_S}` proportional to scene linear light and scaled by camera exposure. @@ -565,8 +563,8 @@ def oetf_inverse_BT2100_HLG( def black_level_lift_BT2100_HLG( - L_B: Floating = 0, L_W: Floating = 1000, gamma: Optional[Floating] = None -) -> Floating: + L_B: float = 0, L_W: float = 1000, gamma: Optional[float] = None +) -> float: """ Return the *Reference HLG* black level lift :math:`\\beta` for given display luminance for black, nominal peak luminance and system gamma value. @@ -584,7 +582,7 @@ def black_level_lift_BT2100_HLG( Returns ------- - :class:`numpy.floating` + :class:`float` *Reference HLG* black level lift :math:`\\beta`. Examples @@ -607,12 +605,12 @@ def black_level_lift_BT2100_HLG( def eotf_BT2100_HLG_1( - E_p: FloatingOrArrayLike, - L_B: Floating = 0, - L_W: Floating = 1000, - gamma: Optional[Floating] = None, + E_p: ArrayLike, + L_B: float = 0, + L_W: float = 1000, + gamma: Optional[float] = None, constants: Structure = CONSTANTS_BT2100_HLG, -) -> FloatingOrNDArray: +) -> NDArrayFloat: """ Define *Recommendation ITU-R BT.2100* *Reference HLG* electro-optical transfer function (EOTF) as given in *ITU-R BT.2100-1*. @@ -637,7 +635,7 @@ def eotf_BT2100_HLG_1( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Luminance :math:`F_D` of a displayed linear component :math:`{R_D, G_D, B_D}` or :math:`Y_D` or :math:`I_D`, in :math:`cd/m^2`. @@ -674,12 +672,12 @@ def eotf_BT2100_HLG_1( def eotf_BT2100_HLG_2( - E_p: FloatingOrArrayLike, - L_B: Floating = 0, - L_W: Floating = 1000, - gamma: Optional[Floating] = None, + E_p: ArrayLike, + L_B: float = 0, + L_W: float = 1000, + gamma: Optional[float] = None, constants: Structure = CONSTANTS_BT2100_HLG, -) -> FloatingOrNDArray: +) -> NDArrayFloat: """ Define *Recommendation ITU-R BT.2100* *Reference HLG* electro-optical transfer function (EOTF) as given in *ITU-R BT.2100-2* with the @@ -705,7 +703,7 @@ def eotf_BT2100_HLG_2( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Luminance :math:`F_D` of a displayed linear component :math:`{R_D, G_D, B_D}` or :math:`Y_D` or :math:`I_D`, in :math:`cd/m^2`. @@ -766,15 +764,15 @@ def eotf_BT2100_HLG_2( def eotf_BT2100_HLG( - E_p: FloatingOrArrayLike, - L_B: Floating = 0, - L_W: Floating = 1000, - gamma: Optional[Floating] = None, + E_p: ArrayLike, + L_B: float = 0, + L_W: float = 1000, + gamma: Optional[float] = None, constants: Structure = CONSTANTS_BT2100_HLG, method: Union[ Literal["ITU-R BT.2100-1", "ITU-R BT.2100-2"], str ] = "ITU-R BT.2100-2", -) -> FloatingOrNDArray: +) -> NDArrayFloat: """ Define *Recommendation ITU-R BT.2100* *Reference HLG* electro-optical transfer function (EOTF). @@ -801,7 +799,7 @@ def eotf_BT2100_HLG( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Luminance :math:`F_D` of a displayed linear component :math:`{R_D, G_D, B_D}` or :math:`Y_D` or :math:`I_D`, in :math:`cd/m^2`. @@ -843,12 +841,12 @@ def eotf_BT2100_HLG( def eotf_inverse_BT2100_HLG_1( - F_D: FloatingOrArrayLike, - L_B: Floating = 0, - L_W: Floating = 1000, - gamma: Optional[Floating] = None, + F_D: ArrayLike, + L_B: float = 0, + L_W: float = 1000, + gamma: Optional[float] = None, constants: Structure = CONSTANTS_BT2100_HLG, -) -> FloatingOrNDArray: +) -> NDArrayFloat: """ Define *Recommendation ITU-R BT.2100* *Reference HLG* inverse electro-optical transfer function (EOTF) as given in @@ -873,7 +871,7 @@ def eotf_inverse_BT2100_HLG_1( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` :math:`E'` denotes a non-linear colour value :math:`{R', G', B'}` or :math:`{L', M', S'}` in *HLG* space. @@ -911,12 +909,12 @@ def eotf_inverse_BT2100_HLG_1( def eotf_inverse_BT2100_HLG_2( - F_D: FloatingOrArrayLike, - L_B: Floating = 0, - L_W: Floating = 1000, - gamma: Optional[Floating] = None, + F_D: ArrayLike, + L_B: float = 0, + L_W: float = 1000, + gamma: Optional[float] = None, constants: Structure = CONSTANTS_BT2100_HLG, -) -> FloatingOrNDArray: +) -> NDArrayFloat: """ Define *Recommendation ITU-R BT.2100* *Reference HLG* inverse electro-optical transfer function (EOTF) as given in @@ -941,7 +939,7 @@ def eotf_inverse_BT2100_HLG_2( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` :math:`E'` denotes a non-linear colour value :math:`{R', G', B'}` or :math:`{L', M', S'}` in *HLG* space. @@ -1001,15 +999,15 @@ def eotf_inverse_BT2100_HLG_2( def eotf_inverse_BT2100_HLG( - F_D: FloatingOrArrayLike, - L_B: Floating = 0, - L_W: Floating = 1000, - gamma: Optional[Floating] = None, + F_D: ArrayLike, + L_B: float = 0, + L_W: float = 1000, + gamma: Optional[float] = None, constants: Structure = CONSTANTS_BT2100_HLG, method: Union[ Literal["ITU-R BT.2100-1", "ITU-R BT.2100-2"], str ] = "ITU-R BT.2100-2", -) -> FloatingOrNDArray: +) -> NDArrayFloat: """ Define *Recommendation ITU-R BT.2100* *Reference HLG* inverse electro-optical transfer function (EOTF). @@ -1035,7 +1033,7 @@ def eotf_inverse_BT2100_HLG( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` :math:`E'` denotes a non-linear colour value :math:`{R', G', B'}` or :math:`{L', M', S'}` in *HLG* space. @@ -1077,11 +1075,11 @@ def eotf_inverse_BT2100_HLG( def ootf_BT2100_HLG_1( - E: FloatingOrArrayLike, - L_B: Floating = 0, - L_W: Floating = 1000, - gamma: Optional[Floating] = None, -) -> FloatingOrNDArray: + E: ArrayLike, + L_B: float = 0, + L_W: float = 1000, + gamma: Optional[float] = None, +) -> NDArrayFloat: """ Define *Recommendation ITU-R BT.2100* *Reference HLG* opto-optical transfer function (OOTF / OOCF) as given in *ITU-R BT.2100-1*. @@ -1105,7 +1103,7 @@ def ootf_BT2100_HLG_1( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` :math:`F_D` is the luminance of a displayed linear component :math:`{R_D, G_D, or B_D}`, in :math:`cd/m^2`. @@ -1169,10 +1167,10 @@ def ootf_BT2100_HLG_1( def ootf_BT2100_HLG_2( - E: FloatingOrArrayLike, - L_W: Floating = 1000, - gamma: Optional[Floating] = None, -) -> FloatingOrNDArray: + E: ArrayLike, + L_W: float = 1000, + gamma: Optional[float] = None, +) -> NDArrayFloat: """ Define *Recommendation ITU-R BT.2100* *Reference HLG* opto-optical transfer function (OOTF / OOCF) as given in *ITU-R BT.2100-2*. @@ -1194,7 +1192,7 @@ def ootf_BT2100_HLG_2( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` :math:`F_D` is the luminance of a displayed linear component :math:`{R_D, G_D, or B_D}`, in :math:`cd/m^2`. @@ -1271,14 +1269,14 @@ def ootf_BT2100_HLG_2( def ootf_BT2100_HLG( - E: FloatingOrArrayLike, - L_B: Floating = 0, - L_W: Floating = 1000, - gamma: Optional[Floating] = None, + E: ArrayLike, + L_B: float = 0, + L_W: float = 1000, + gamma: Optional[float] = None, method: Union[ Literal["ITU-R BT.2100-1", "ITU-R BT.2100-2"], str ] = "ITU-R BT.2100-2", -) -> FloatingOrNDArray: +) -> NDArrayFloat: """ Define *Recommendation ITU-R BT.2100* *Reference HLG* opto-optical transfer function (OOTF / OOCF). @@ -1304,7 +1302,7 @@ def ootf_BT2100_HLG( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` :math:`F_D` is the luminance of a displayed linear component :math:`{R_D, G_D, or B_D}`, in :math:`cd/m^2`. @@ -1346,11 +1344,11 @@ def ootf_BT2100_HLG( def ootf_inverse_BT2100_HLG_1( - F_D: FloatingOrArrayLike, - L_B: Floating = 0, - L_W: Floating = 1000, - gamma: Optional[Floating] = None, -) -> FloatingOrNDArray: + F_D: ArrayLike, + L_B: float = 0, + L_W: float = 1000, + gamma: Optional[float] = None, +) -> NDArrayFloat: """ Define *Recommendation ITU-R BT.2100* *Reference HLG* inverse opto-optical transfer function (OOTF / OOCF) as given in *ITU-R BT.2100-1*. @@ -1371,7 +1369,7 @@ def ootf_inverse_BT2100_HLG_1( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` :math:`E` is the signal for each colour component :math:`{R_S, G_S, B_S}` proportional to scene linear light and scaled by camera exposure. @@ -1450,10 +1448,10 @@ def ootf_inverse_BT2100_HLG_1( def ootf_inverse_BT2100_HLG_2( - F_D: FloatingOrArrayLike, - L_W: Floating = 1000, - gamma: Optional[Floating] = None, -) -> FloatingOrNDArray: + F_D: ArrayLike, + L_W: float = 1000, + gamma: Optional[float] = None, +) -> NDArrayFloat: """ Define *Recommendation ITU-R BT.2100* *Reference HLG* inverse opto-optical transfer function (OOTF / OOCF) as given in *ITU-R BT.2100-2*. @@ -1472,7 +1470,7 @@ def ootf_inverse_BT2100_HLG_2( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` :math:`E` is the signal for each colour component :math:`{R_S, G_S, B_S}` proportional to scene linear light and scaled by camera exposure. @@ -1564,14 +1562,14 @@ def ootf_inverse_BT2100_HLG_2( def ootf_inverse_BT2100_HLG( - F_D: FloatingOrArrayLike, - L_B: Floating = 0, - L_W: Floating = 1000, - gamma: Optional[Floating] = None, + F_D: ArrayLike, + L_B: float = 0, + L_W: float = 1000, + gamma: Optional[float] = None, method: Union[ Literal["ITU-R BT.2100-1", "ITU-R BT.2100-2"], str ] = "ITU-R BT.2100-2", -) -> FloatingOrNDArray: +) -> NDArrayFloat: """ Define *Recommendation ITU-R BT.2100* *Reference HLG* inverse opto-optical transfer function (OOTF / OOCF). @@ -1594,7 +1592,7 @@ def ootf_inverse_BT2100_HLG( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` :math:`E` is the signal for each colour component :math:`{R_S, G_S, B_S}` proportional to scene linear light and scaled by camera exposure. diff --git a/colour/models/rgb/transfer_functions/itur_bt_601.py b/colour/models/rgb/transfer_functions/itur_bt_601.py index d0b7d259e0..7e1e83bd0e 100644 --- a/colour/models/rgb/transfer_functions/itur_bt_601.py +++ b/colour/models/rgb/transfer_functions/itur_bt_601.py @@ -23,7 +23,7 @@ import numpy as np from colour.algebra import spow -from colour.hints import FloatingOrArrayLike, FloatingOrNDArray +from colour.hints import ArrayLike, NDArrayFloat from colour.utilities import ( as_float, domain_range_scale, @@ -44,7 +44,7 @@ ] -def oetf_BT601(L: FloatingOrArrayLike) -> FloatingOrNDArray: +def oetf_BT601(L: ArrayLike) -> NDArrayFloat: """ Define *Recommendation ITU-R BT.601-7* opto-electronic transfer function (OETF). @@ -56,7 +56,7 @@ def oetf_BT601(L: FloatingOrArrayLike) -> FloatingOrNDArray: Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Corresponding electrical signal :math:`E`. Notes @@ -90,7 +90,7 @@ def oetf_BT601(L: FloatingOrArrayLike) -> FloatingOrNDArray: return as_float(from_range_1(E)) -def oetf_inverse_BT601(E: FloatingOrArrayLike) -> FloatingOrNDArray: +def oetf_inverse_BT601(E: ArrayLike) -> NDArrayFloat: """ Define *Recommendation ITU-R BT.601-7* inverse opto-electronic transfer function (OETF). @@ -102,7 +102,7 @@ def oetf_inverse_BT601(E: FloatingOrArrayLike) -> FloatingOrNDArray: Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Corresponding *luminance* :math:`L` of the image. Notes diff --git a/colour/models/rgb/transfer_functions/itur_bt_709.py b/colour/models/rgb/transfer_functions/itur_bt_709.py index 0ffbe8b348..7fe088fdde 100644 --- a/colour/models/rgb/transfer_functions/itur_bt_709.py +++ b/colour/models/rgb/transfer_functions/itur_bt_709.py @@ -20,7 +20,7 @@ from __future__ import annotations -from colour.hints import FloatingOrArrayLike, FloatingOrNDArray +from colour.hints import ArrayLike, NDArrayFloat from colour.models.rgb.transfer_functions import oetf_BT601, oetf_inverse_BT601 __author__ = "Colour Developers" @@ -36,7 +36,7 @@ ] -def oetf_BT709(L: FloatingOrArrayLike) -> FloatingOrNDArray: +def oetf_BT709(L: ArrayLike) -> NDArrayFloat: """ Define *Recommendation ITU-R BT.709-6* opto-electronic transfer function (OETF). @@ -48,7 +48,7 @@ def oetf_BT709(L: FloatingOrArrayLike) -> FloatingOrNDArray: Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Corresponding electrical signal :math:`V`. Notes @@ -78,7 +78,7 @@ def oetf_BT709(L: FloatingOrArrayLike) -> FloatingOrNDArray: return oetf_BT601(L) -def oetf_inverse_BT709(V: FloatingOrArrayLike) -> FloatingOrNDArray: +def oetf_inverse_BT709(V: ArrayLike) -> NDArrayFloat: """ Define *Recommendation ITU-R BT.709-6* inverse opto-electronic transfer function (OETF). @@ -90,7 +90,7 @@ def oetf_inverse_BT709(V: FloatingOrArrayLike) -> FloatingOrNDArray: Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Corresponding *luminance* :math:`L` of the image. Notes diff --git a/colour/models/rgb/transfer_functions/itut_h_273.py b/colour/models/rgb/transfer_functions/itut_h_273.py index cd5da4af3b..36d6895839 100644 --- a/colour/models/rgb/transfer_functions/itut_h_273.py +++ b/colour/models/rgb/transfer_functions/itut_h_273.py @@ -72,7 +72,7 @@ def oetf_H273_Log(L_c): Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Corresponding electrical signal :math:`V`. Notes @@ -134,7 +134,7 @@ def oetf_inverse_H273_Log(V): Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Corresponding scene *Luminance* :math:`L_c`. Notes @@ -195,7 +195,7 @@ def oetf_H273_LogSqrt(L_c): Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Corresponding electrical signal :math:`V`. Notes @@ -258,7 +258,7 @@ def oetf_inverse_H273_LogSqrt(V): Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Corresponding scene *Luminance* :math:`L_c`. Notes @@ -319,7 +319,7 @@ def oetf_H273_IEC61966_2(L_c): Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Corresponding electrical signal :math:`V`. Notes @@ -378,7 +378,7 @@ def oetf_inverse_H273_IEC61966_2(V): Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Corresponding scene luminance :math:`L_c`. Notes @@ -436,7 +436,7 @@ def eotf_inverse_H273_ST428_1(L_o): Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Corresponding electrical signal :math:`V`. Notes @@ -485,7 +485,7 @@ def eotf_H273_ST428_1(V): Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Corresponding output display *Luminance* :math:`L_o` of the image. Notes diff --git a/colour/models/rgb/transfer_functions/leica_l_log.py b/colour/models/rgb/transfer_functions/leica_l_log.py index 653db227b9..e690a3fc72 100644 --- a/colour/models/rgb/transfer_functions/leica_l_log.py +++ b/colour/models/rgb/transfer_functions/leica_l_log.py @@ -20,10 +20,8 @@ from colour.algebra import spow from colour.hints import ( - Boolean, - FloatingOrArrayLike, - FloatingOrNDArray, - Integer, + ArrayLike, + NDArrayFloat, ) from colour.models.rgb.transfer_functions import full_to_legal, legal_to_full from colour.utilities import Structure, as_float, from_range_1, to_domain_1 @@ -55,12 +53,12 @@ def log_encoding_LLog( - LSR: FloatingOrArrayLike, - bit_depth: Integer = 10, - out_normalised_code_value: Boolean = True, - in_reflection: Boolean = True, + LSR: ArrayLike, + bit_depth: int = 10, + out_normalised_code_value: bool = True, + in_reflection: bool = True, constants: Structure = CONSTANTS_LLOG, -) -> FloatingOrNDArray: +) -> NDArrayFloat: """ Define the *Leica L-Log* log encoding curve / opto-electronic transfer function. @@ -81,7 +79,7 @@ def log_encoding_LLog( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` *L-Log* 10-bit equivalent code value :math:`L-Log`. Notes @@ -135,12 +133,12 @@ def log_encoding_LLog( def log_decoding_LLog( - LLog: FloatingOrArrayLike, - bit_depth: Integer = 10, - in_normalised_code_value: Boolean = True, - out_reflection: Boolean = True, + LLog: ArrayLike, + bit_depth: int = 10, + in_normalised_code_value: bool = True, + out_reflection: bool = True, constants: Structure = CONSTANTS_LLOG, -) -> FloatingOrNDArray: +) -> NDArrayFloat: """ Define the *Leica L-Log* log decoding curve / electro-optical transfer function. @@ -161,7 +159,7 @@ def log_decoding_LLog( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Linear scene reflection :math:`LSR` values. Notes diff --git a/colour/models/rgb/transfer_functions/linear.py b/colour/models/rgb/transfer_functions/linear.py index ae22eb95f9..a693cedd4c 100644 --- a/colour/models/rgb/transfer_functions/linear.py +++ b/colour/models/rgb/transfer_functions/linear.py @@ -10,7 +10,7 @@ from __future__ import annotations -from colour.hints import FloatingOrArrayLike, FloatingOrNDArray +from colour.hints import ArrayLike, NDArrayFloat from colour.utilities import as_float __author__ = "Colour Developers" @@ -25,7 +25,7 @@ ] -def linear_function(a: FloatingOrArrayLike) -> FloatingOrNDArray: +def linear_function(a: ArrayLike) -> NDArrayFloat: """ Define a typical linear encoding / decoding function, essentially a pass-through function. @@ -37,7 +37,7 @@ def linear_function(a: FloatingOrArrayLike) -> FloatingOrNDArray: Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Encoded / decoded array. Examples diff --git a/colour/models/rgb/transfer_functions/log.py b/colour/models/rgb/transfer_functions/log.py index e5555b3612..f58e54f671 100644 --- a/colour/models/rgb/transfer_functions/log.py +++ b/colour/models/rgb/transfer_functions/log.py @@ -41,10 +41,8 @@ from colour.algebra import sdiv, sdiv_mode from colour.hints import ( - Floating, - FloatingOrArrayLike, - FloatingOrNDArray, - Integer, + ArrayLike, + NDArrayFloat, Literal, Optional, Union, @@ -79,13 +77,13 @@ def logarithmic_function_basic( - x: FloatingOrArrayLike, + x: ArrayLike, style: Union[ Literal["log10", "antiLog10", "log2", "antiLog2", "logB", "antiLogB"], str, ] = "log2", - base: Integer = 2, -) -> FloatingOrNDArray: + base: int = 2, +) -> NDArrayFloat: """ Define the basic logarithmic function. @@ -108,7 +106,7 @@ def logarithmic_function_basic( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Logarithmically converted data. Examples @@ -157,14 +155,14 @@ def logarithmic_function_basic( def logarithmic_function_quasilog( - x: FloatingOrArrayLike, + x: ArrayLike, style: Union[Literal["linToLog", "logToLin"], str] = "linToLog", - base: Integer = 2, - log_side_slope: Floating = 1, - lin_side_slope: Floating = 1, - log_side_offset: Floating = 0, - lin_side_offset: Floating = 0, -) -> FloatingOrNDArray: + base: int = 2, + log_side_slope: float = 1, + lin_side_slope: float = 1, + log_side_offset: float = 0, + lin_side_offset: float = 0, +) -> NDArrayFloat: """ Define the quasilog logarithmic function. @@ -196,7 +194,7 @@ def logarithmic_function_quasilog( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Encoded/Decoded data. Examples @@ -239,18 +237,18 @@ def logarithmic_function_quasilog( def logarithmic_function_camera( - x: FloatingOrArrayLike, + x: ArrayLike, style: Union[ Literal["cameraLinToLog", "cameraLogToLin"], str ] = "cameraLinToLog", - base: Integer = 2, - log_side_slope: Floating = 1, - lin_side_slope: Floating = 1, - log_side_offset: Floating = 0, - lin_side_offset: Floating = 0, - lin_side_break: Floating = 0.005, - linear_slope: Optional[Floating] = None, -) -> FloatingOrNDArray: + base: int = 2, + log_side_slope: float = 1, + lin_side_slope: float = 1, + log_side_offset: float = 0, + lin_side_offset: float = 0, + lin_side_break: float = 0.005, + linear_slope: Optional[float] = None, +) -> NDArrayFloat: """ Define the camera logarithmic function. @@ -289,7 +287,7 @@ def logarithmic_function_camera( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Encoded/Decoded data. Examples @@ -322,7 +320,7 @@ def logarithmic_function_camera( with sdiv_mode(): linear_slope = cast( - Floating, + float, optional( linear_slope, ( @@ -371,11 +369,11 @@ def logarithmic_function_camera( def log_encoding_Log2( - lin: FloatingOrArrayLike, - middle_grey: Floating = 0.18, - min_exposure: Floating = -6.5, - max_exposure: Floating = 6.5, -) -> FloatingOrNDArray: + lin: ArrayLike, + middle_grey: float = 0.18, + min_exposure: float = -6.5, + max_exposure: float = 6.5, +) -> NDArrayFloat: """ Define the common *Log2* encoding function. @@ -392,7 +390,7 @@ def log_encoding_Log2( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Non-linear *Log2* encoded data. Notes @@ -427,11 +425,11 @@ def log_encoding_Log2( def log_decoding_Log2( - log_norm: FloatingOrArrayLike, - middle_grey: Floating = 0.18, - min_exposure: Floating = -6.5, - max_exposure: Floating = 6.5, -) -> FloatingOrNDArray: + log_norm: ArrayLike, + middle_grey: float = 0.18, + min_exposure: float = -6.5, + max_exposure: float = 6.5, +) -> NDArrayFloat: """ Define the common *Log2* decoding function. @@ -448,7 +446,7 @@ def log_decoding_Log2( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Linear *Log2* decoded data. Notes diff --git a/colour/models/rgb/transfer_functions/nikon_n_log.py b/colour/models/rgb/transfer_functions/nikon_n_log.py index a8fdaf8be1..d19099f741 100644 --- a/colour/models/rgb/transfer_functions/nikon_n_log.py +++ b/colour/models/rgb/transfer_functions/nikon_n_log.py @@ -21,10 +21,8 @@ from colour.algebra import spow from colour.hints import ( - Boolean, - FloatingOrArrayLike, - FloatingOrNDArray, - Integer, + ArrayLike, + NDArrayFloat, ) from colour.models.rgb.transfer_functions import full_to_legal, legal_to_full from colour.utilities import Structure, as_float, from_range_1, to_domain_1 @@ -54,12 +52,12 @@ def log_encoding_NLog( - y: FloatingOrArrayLike, - bit_depth: Integer = 10, - out_normalised_code_value: Boolean = True, - in_reflection: Boolean = True, + y: ArrayLike, + bit_depth: int = 10, + out_normalised_code_value: bool = True, + in_reflection: bool = True, constants: Structure = CONSTANTS_NLOG, -) -> FloatingOrNDArray: +) -> NDArrayFloat: """ Define the *Nikon N-Log* log encoding curve / opto-electronic transfer function. @@ -80,7 +78,7 @@ def log_encoding_NLog( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` *N-Log* 10-bit equivalent code value :math:`x`. Notes @@ -130,12 +128,12 @@ def log_encoding_NLog( def log_decoding_NLog( - x: FloatingOrArrayLike, - bit_depth: Integer = 10, - in_normalised_code_value: Boolean = True, - out_reflection: Boolean = True, + x: ArrayLike, + bit_depth: int = 10, + in_normalised_code_value: bool = True, + out_reflection: bool = True, constants: Structure = CONSTANTS_NLOG, -) -> FloatingOrNDArray: +) -> NDArrayFloat: """ Define the *Nikon N-Log* log decoding curve / electro-optical transfer function. @@ -156,7 +154,7 @@ def log_decoding_NLog( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Reflectance :math:`y`. Notes diff --git a/colour/models/rgb/transfer_functions/panalog.py b/colour/models/rgb/transfer_functions/panalog.py index 5bbdf20178..5f1f04c88a 100644 --- a/colour/models/rgb/transfer_functions/panalog.py +++ b/colour/models/rgb/transfer_functions/panalog.py @@ -19,7 +19,7 @@ import numpy as np -from colour.hints import FloatingOrArrayLike, FloatingOrNDArray +from colour.hints import ArrayLike, NDArrayFloat from colour.utilities import ( as_float, as_float_array, @@ -41,9 +41,9 @@ def log_encoding_Panalog( - x: FloatingOrArrayLike, - black_offset: FloatingOrArrayLike = 10 ** ((64 - 681) / 444), -) -> FloatingOrNDArray: + x: ArrayLike, + black_offset: ArrayLike = 10 ** ((64 - 681) / 444), +) -> NDArrayFloat: """ Define the *Panalog* log encoding curve / opto-electronic transfer function. @@ -57,7 +57,7 @@ def log_encoding_Panalog( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Non-linear data :math:`y`. Warnings @@ -98,9 +98,9 @@ def log_encoding_Panalog( def log_decoding_Panalog( - y: FloatingOrArrayLike, - black_offset: FloatingOrArrayLike = 10 ** ((64 - 681) / 444), -) -> FloatingOrNDArray: + y: ArrayLike, + black_offset: ArrayLike = 10 ** ((64 - 681) / 444), +) -> NDArrayFloat: """ Define the *Panalog* log decoding curve / electro-optical transfer function. @@ -114,7 +114,7 @@ def log_decoding_Panalog( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Linear data :math:`x`. Warnings diff --git a/colour/models/rgb/transfer_functions/panasonic_v_log.py b/colour/models/rgb/transfer_functions/panasonic_v_log.py index ca2df0c4d0..7e6f99c26d 100644 --- a/colour/models/rgb/transfer_functions/panasonic_v_log.py +++ b/colour/models/rgb/transfer_functions/panasonic_v_log.py @@ -19,10 +19,8 @@ import numpy as np from colour.hints import ( - Boolean, - FloatingOrArrayLike, - FloatingOrNDArray, - Integer, + ArrayLike, + NDArrayFloat, ) from colour.models.rgb.transfer_functions import full_to_legal, legal_to_full from colour.utilities import Structure, as_float, from_range_1, to_domain_1 @@ -47,12 +45,12 @@ def log_encoding_VLog( - L_in: FloatingOrArrayLike, - bit_depth: Integer = 10, - out_normalised_code_value: Boolean = True, - in_reflection: Boolean = True, + L_in: ArrayLike, + bit_depth: int = 10, + out_normalised_code_value: bool = True, + in_reflection: bool = True, constants: Structure = CONSTANTS_VLOG, -) -> FloatingOrNDArray: +) -> NDArrayFloat: """ Define the *Panasonic V-Log* log encoding curve / opto-electronic transfer function. @@ -73,7 +71,7 @@ def log_encoding_VLog( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Non-linear data :math:`V_{out}`. Notes @@ -139,12 +137,12 @@ def log_encoding_VLog( def log_decoding_VLog( - V_out: FloatingOrArrayLike, - bit_depth: Integer = 10, - in_normalised_code_value: Boolean = True, - out_reflection: Boolean = True, + V_out: ArrayLike, + bit_depth: int = 10, + in_normalised_code_value: bool = True, + out_reflection: bool = True, constants: Structure = CONSTANTS_VLOG, -) -> FloatingOrNDArray: +) -> NDArrayFloat: """ Define the *Panasonic V-Log* log decoding curve / electro-optical transfer function. @@ -165,7 +163,7 @@ def log_decoding_VLog( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Linear reflection data :math`L_{in}`. Notes diff --git a/colour/models/rgb/transfer_functions/pivoted_log.py b/colour/models/rgb/transfer_functions/pivoted_log.py index acbccb9c61..dc817dc614 100644 --- a/colour/models/rgb/transfer_functions/pivoted_log.py +++ b/colour/models/rgb/transfer_functions/pivoted_log.py @@ -19,7 +19,7 @@ import numpy as np -from colour.hints import Floating, FloatingOrArrayLike, FloatingOrNDArray +from colour.hints import ArrayLike, NDArrayFloat from colour.utilities import as_float, from_range_1, to_domain_1 __author__ = "Colour Developers" @@ -36,12 +36,12 @@ def log_encoding_PivotedLog( - x: FloatingOrArrayLike, - log_reference: Floating = 445, - linear_reference: Floating = 0.18, - negative_gamma: Floating = 0.6, - density_per_code_value: Floating = 0.002, -) -> FloatingOrNDArray: + x: ArrayLike, + log_reference: float = 445, + linear_reference: float = 0.18, + negative_gamma: float = 0.6, + density_per_code_value: float = 0.002, +) -> NDArrayFloat: """ Define the *Josh Pines* style *Pivoted Log* log encoding curve / opto-electronic transfer function. @@ -61,7 +61,7 @@ def log_encoding_PivotedLog( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Non-linear data :math:`y`. Notes @@ -100,12 +100,12 @@ def log_encoding_PivotedLog( def log_decoding_PivotedLog( - y: FloatingOrArrayLike, - log_reference: Floating = 445, - linear_reference: Floating = 0.18, - negative_gamma: Floating = 0.6, - density_per_code_value: Floating = 0.002, -) -> FloatingOrNDArray: + y: ArrayLike, + log_reference: float = 445, + linear_reference: float = 0.18, + negative_gamma: float = 0.6, + density_per_code_value: float = 0.002, +) -> NDArrayFloat: """ Define the *Josh Pines* style *Pivoted Log* log decoding curve / electro-optical transfer function. @@ -125,7 +125,7 @@ def log_decoding_PivotedLog( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Linear data :math:`x`. Notes diff --git a/colour/models/rgb/transfer_functions/red.py b/colour/models/rgb/transfer_functions/red.py index d31dee1f2f..18370c9310 100644 --- a/colour/models/rgb/transfer_functions/red.py +++ b/colour/models/rgb/transfer_functions/red.py @@ -39,8 +39,8 @@ import numpy as np from colour.hints import ( - FloatingOrArrayLike, - FloatingOrNDArray, + ArrayLike, + NDArrayFloat, Literal, Union, ) @@ -85,9 +85,9 @@ def log_encoding_REDLog( - x: FloatingOrArrayLike, - black_offset: FloatingOrArrayLike = 10 ** ((0 - 1023) / 511), -) -> FloatingOrNDArray: + x: ArrayLike, + black_offset: ArrayLike = 10 ** ((0 - 1023) / 511), +) -> NDArrayFloat: """ Define the *REDLog* log encoding curve / opto-electronic transfer function. @@ -101,7 +101,7 @@ def log_encoding_REDLog( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Non-linear data :math:`y`. Notes @@ -137,9 +137,9 @@ def log_encoding_REDLog( def log_decoding_REDLog( - y: FloatingOrArrayLike, - black_offset: FloatingOrArrayLike = 10 ** ((0 - 1023) / 511), -) -> FloatingOrNDArray: + y: ArrayLike, + black_offset: ArrayLike = 10 ** ((0 - 1023) / 511), +) -> NDArrayFloat: """ Define the *REDLog* log decoding curve / electro-optical transfer function. @@ -153,7 +153,7 @@ def log_decoding_REDLog( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Linear data :math:`x`. Notes @@ -189,9 +189,9 @@ def log_decoding_REDLog( def log_encoding_REDLogFilm( - x: FloatingOrArrayLike, - black_offset: FloatingOrArrayLike = 10 ** ((95 - 685) / 300), -) -> FloatingOrNDArray: + x: ArrayLike, + black_offset: ArrayLike = 10 ** ((95 - 685) / 300), +) -> NDArrayFloat: """ Define the *REDLogFilm* log encoding curve / opto-electronic transfer function. @@ -205,7 +205,7 @@ def log_encoding_REDLogFilm( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Non-linear data :math:`y`. Notes @@ -236,9 +236,9 @@ def log_encoding_REDLogFilm( def log_decoding_REDLogFilm( - y: FloatingOrArrayLike, - black_offset: FloatingOrArrayLike = 10 ** ((95 - 685) / 300), -) -> FloatingOrNDArray: + y: ArrayLike, + black_offset: ArrayLike = 10 ** ((95 - 685) / 300), +) -> NDArrayFloat: """ Define the *REDLogFilm* log decoding curve / electro-optical transfer function. @@ -252,7 +252,7 @@ def log_decoding_REDLogFilm( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Linear data :math:`x`. Notes @@ -282,7 +282,7 @@ def log_decoding_REDLogFilm( return log_decoding_Cineon(y, black_offset) -def log_encoding_Log3G10_v1(x: FloatingOrArrayLike) -> FloatingOrNDArray: +def log_encoding_Log3G10_v1(x: ArrayLike) -> NDArrayFloat: """ Define the *Log3G10* *v1* log encoding curve / opto-electronic transfer function, the curve used in *REDCINE-X PRO Beta 42* and *Resolve 12.5.2*. @@ -294,7 +294,7 @@ def log_encoding_Log3G10_v1(x: FloatingOrArrayLike) -> FloatingOrNDArray: Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Non-linear data :math:`y`. Notes @@ -328,7 +328,7 @@ def log_encoding_Log3G10_v1(x: FloatingOrArrayLike) -> FloatingOrNDArray: return as_float(from_range_1(y)) -def log_decoding_Log3G10_v1(y: FloatingOrArrayLike) -> FloatingOrNDArray: +def log_decoding_Log3G10_v1(y: ArrayLike) -> NDArrayFloat: """ Define the *Log3G10* *v1* log decoding curve / electro-optical transfer function, the curve used in *REDCINE-X PRO Beta 42* and *Resolve 12.5.2*. @@ -340,7 +340,7 @@ def log_decoding_Log3G10_v1(y: FloatingOrArrayLike) -> FloatingOrNDArray: Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Linear data :math:`x`. Notes @@ -374,7 +374,7 @@ def log_decoding_Log3G10_v1(y: FloatingOrArrayLike) -> FloatingOrNDArray: return as_float(from_range_1(x)) -def log_encoding_Log3G10_v2(x: FloatingOrArrayLike) -> FloatingOrNDArray: +def log_encoding_Log3G10_v2(x: ArrayLike) -> NDArrayFloat: """ Define the *Log3G10* *v2* log encoding curve / opto-electronic transfer function, the current curve in *REDCINE-X PRO*. @@ -386,7 +386,7 @@ def log_encoding_Log3G10_v2(x: FloatingOrArrayLike) -> FloatingOrNDArray: Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Non-linear data :math:`y`. Notes @@ -424,7 +424,7 @@ def log_encoding_Log3G10_v2(x: FloatingOrArrayLike) -> FloatingOrNDArray: return as_float(from_range_1(y)) -def log_decoding_Log3G10_v2(y: FloatingOrArrayLike) -> FloatingOrNDArray: +def log_decoding_Log3G10_v2(y: ArrayLike) -> NDArrayFloat: """ Define the *Log3G10* *v2* log decoding curve / electro-optical transfer function, the current curve in *REDCINE-X PRO*. @@ -436,7 +436,7 @@ def log_decoding_Log3G10_v2(y: FloatingOrArrayLike) -> FloatingOrNDArray: Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Linear data :math:`x`. Notes @@ -470,7 +470,7 @@ def log_decoding_Log3G10_v2(y: FloatingOrArrayLike) -> FloatingOrNDArray: return as_float(from_range_1(x)) -def log_encoding_Log3G10_v3(x: FloatingOrArrayLike) -> FloatingOrNDArray: +def log_encoding_Log3G10_v3(x: ArrayLike) -> NDArrayFloat: """ Define the *Log3G10* *v3* log encoding curve / opto-electronic transfer function, the curve described in the *RedLog3G10* Whitepaper. @@ -482,7 +482,7 @@ def log_encoding_Log3G10_v3(x: FloatingOrArrayLike) -> FloatingOrNDArray: Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Non-linear data :math:`y`. Notes @@ -525,7 +525,7 @@ def log_encoding_Log3G10_v3(x: FloatingOrArrayLike) -> FloatingOrNDArray: return as_float(from_range_1(y)) -def log_decoding_Log3G10_v3(y: FloatingOrArrayLike) -> FloatingOrNDArray: +def log_decoding_Log3G10_v3(y: ArrayLike) -> NDArrayFloat: """ Define the *Log3G10* *v3* log decoding curve / electro-optical transfer function, the curve described in the *RedLog3G10* whitepaper. @@ -537,7 +537,7 @@ def log_decoding_Log3G10_v3(y: FloatingOrArrayLike) -> FloatingOrNDArray: Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Linear data :math:`x`. Notes @@ -598,9 +598,9 @@ def log_decoding_Log3G10_v3(y: FloatingOrArrayLike) -> FloatingOrNDArray: def log_encoding_Log3G10( - x: FloatingOrArrayLike, + x: ArrayLike, method: Union[Literal["v1", "v2", "v3"], str] = "v3", -) -> FloatingOrNDArray: +) -> NDArrayFloat: """ Define the *Log3G10* log encoding curve / opto-electronic transfer function. @@ -614,7 +614,7 @@ def log_encoding_Log3G10( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Non-linear data :math:`y`. Notes @@ -697,7 +697,7 @@ def log_encoding_Log3G10( def log_decoding_Log3G10( y, method: Union[Literal["v1", "v2", "v3"], str] = "v3" -) -> FloatingOrNDArray: +) -> NDArrayFloat: """ Define the *Log3G10* log decoding curve / electro-optical transfer function. @@ -711,7 +711,7 @@ def log_decoding_Log3G10( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Linear data :math:`x`. Notes @@ -745,7 +745,7 @@ def log_decoding_Log3G10( return LOG3G10_DECODING_METHODS[method](y) -def log_encoding_Log3G12(x: FloatingOrArrayLike) -> FloatingOrNDArray: +def log_encoding_Log3G12(x: ArrayLike) -> NDArrayFloat: """ Define the *Log3G12* log encoding curve / opto-electronic transfer function. @@ -757,7 +757,7 @@ def log_encoding_Log3G12(x: FloatingOrArrayLike) -> FloatingOrNDArray: Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Non-linear data :math:`y`. Notes @@ -791,7 +791,7 @@ def log_encoding_Log3G12(x: FloatingOrArrayLike) -> FloatingOrNDArray: return as_float(from_range_1(y)) -def log_decoding_Log3G12(y: FloatingOrArrayLike) -> FloatingOrNDArray: +def log_decoding_Log3G12(y: ArrayLike) -> NDArrayFloat: """ Define the *Log3G12* log decoding curve / electro-optical transfer function. @@ -803,7 +803,7 @@ def log_decoding_Log3G12(y: FloatingOrArrayLike) -> FloatingOrNDArray: Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Linear data :math:`x`. Notes diff --git a/colour/models/rgb/transfer_functions/rimm_romm_rgb.py b/colour/models/rgb/transfer_functions/rimm_romm_rgb.py index 4650f62a79..d4865984c5 100644 --- a/colour/models/rgb/transfer_functions/rimm_romm_rgb.py +++ b/colour/models/rgb/transfer_functions/rimm_romm_rgb.py @@ -29,13 +29,9 @@ from colour.algebra import spow from colour.hints import ( - Boolean, - Floating, - FloatingOrArrayLike, - FloatingOrNDArray, - Integer, - IntegerOrArrayLike, - IntegerOrNDArray, + ArrayLike, + NDArrayFloat, + NDArrayInt, Union, ) from colour.utilities import ( @@ -68,8 +64,8 @@ def cctf_encoding_ROMMRGB( - X: FloatingOrArrayLike, bit_depth: Integer = 8, out_int: Boolean = False -) -> Union[FloatingOrNDArray, IntegerOrNDArray]: + X: ArrayLike, bit_depth: int = 8, out_int: bool = False +) -> Union[NDArrayFloat, NDArrayInt]: """ Define the *ROMM RGB* encoding colour component transfer function (Encoding CCTF). @@ -81,12 +77,12 @@ def cctf_encoding_ROMMRGB( bit_depth Bit depth used for conversion. out_int - Whether to return value as integer code value or float equivalent of a + Whether to return value as int code value or float equivalent of a code value at a given bit depth. Returns ------- - :class:`numpy.floating` or :class:`numpy.integer` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Non-linear data :math:`X'_{ROMM}`. Notes @@ -103,8 +99,8 @@ def cctf_encoding_ROMMRGB( | ``X_p`` | [0, 1] | [0, 1] | +----------------+-----------------------+---------------+ - \\* This definition has an output integer switch, thus the domain-range - scale information is only given for the floating point mode. + \\* This definition has an output int switch, thus the domain-range + scale information is only given for the float point mode. References ---------- @@ -133,10 +129,10 @@ def cctf_encoding_ROMMRGB( def cctf_decoding_ROMMRGB( - X_p: Union[FloatingOrArrayLike, IntegerOrArrayLike], - bit_depth: Integer = 8, - in_int: Boolean = False, -) -> FloatingOrNDArray: + X_p: Union[ArrayLike, ArrayLike], + bit_depth: int = 8, + in_int: bool = False, +) -> NDArrayFloat: """ Define the *ROMM RGB* decoding colour component transfer function (Encoding CCTF). @@ -148,12 +144,12 @@ def cctf_decoding_ROMMRGB( bit_depth Bit depth used for conversion. in_int - Whether to treat the input value as integer code value or float + Whether to treat the input value as int code value or float equivalent of a code value at a given bit depth. Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Linear data :math:`X_{ROMM}`. Notes @@ -170,8 +166,8 @@ def cctf_decoding_ROMMRGB( | ``X`` | [0, 1] | [0, 1] | +----------------+-----------------------+---------------+ - \\* This definition has an input integer switch, thus the domain-range - scale information is only given for the floating point mode. + \\* This definition has an input int switch, thus the domain-range + scale information is only given for the float point mode. References ---------- @@ -226,11 +222,11 @@ def cctf_decoding_ROMMRGB( def cctf_encoding_RIMMRGB( - X: FloatingOrArrayLike, - bit_depth: Integer = 8, - out_int: Boolean = False, - E_clip: Floating = 2.0, -) -> Union[FloatingOrNDArray, IntegerOrNDArray]: + X: ArrayLike, + bit_depth: int = 8, + out_int: bool = False, + E_clip: float = 2.0, +) -> Union[NDArrayFloat, NDArrayInt]: """ Define the *RIMM RGB* encoding colour component transfer function (Encoding CCTF). @@ -245,14 +241,14 @@ def cctf_encoding_RIMMRGB( bit_depth Bit depth used for conversion. out_int - Whether to return value as integer code value or float equivalent of a + Whether to return value as int code value or float equivalent of a code value at a given bit depth. E_clip Maximum exposure level. Returns ------- - :class:`numpy.floating` or :class:`numpy.integer` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Non-linear data :math:`X'_{RIMM}`. Notes @@ -269,8 +265,8 @@ def cctf_encoding_RIMMRGB( | ``X_p`` | [0, 1] | [0, 1] | +----------------+-----------------------+---------------+ - \\* This definition has an output integer switch, thus the domain-range - scale information is only given for the floating point mode. + \\* This definition has an output int switch, thus the domain-range + scale information is only given for the float point mode. References ---------- @@ -303,11 +299,11 @@ def cctf_encoding_RIMMRGB( def cctf_decoding_RIMMRGB( - X_p: Union[FloatingOrArrayLike, IntegerOrArrayLike], - bit_depth: Integer = 8, - in_int: Boolean = False, - E_clip: Floating = 2.0, -) -> FloatingOrNDArray: + X_p: Union[ArrayLike, ArrayLike], + bit_depth: int = 8, + in_int: bool = False, + E_clip: float = 2.0, +) -> NDArrayFloat: """ Define the *RIMM RGB* decoding colour component transfer function (Encoding CCTF). @@ -319,14 +315,14 @@ def cctf_decoding_RIMMRGB( bit_depth Bit depth used for conversion. in_int - Whether to treat the input value as integer code value or float + Whether to treat the input value as int code value or float equivalent of a code value at a given bit depth. E_clip Maximum exposure level. Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Linear data :math:`X_{RIMM}`. Notes @@ -343,8 +339,8 @@ def cctf_decoding_RIMMRGB( | ``X`` | [0, 1] | [0, 1] | +----------------+-----------------------+---------------+ - \\* This definition has an input integer switch, thus the domain-range - scale information is only given for the floating point mode. + \\* This definition has an input int switch, thus the domain-range + scale information is only given for the float point mode. References ---------- @@ -381,12 +377,12 @@ def cctf_decoding_RIMMRGB( def log_encoding_ERIMMRGB( - X: FloatingOrArrayLike, - bit_depth: Integer = 8, - out_int: Boolean = False, - E_min: Floating = 0.001, - E_clip: Floating = 316.2, -) -> Union[FloatingOrNDArray, IntegerOrNDArray]: + X: ArrayLike, + bit_depth: int = 8, + out_int: bool = False, + E_min: float = 0.001, + E_clip: float = 316.2, +) -> Union[NDArrayFloat, NDArrayInt]: """ Define the *ERIMM RGB* log encoding curve / opto-electronic transfer function (OETF). @@ -398,7 +394,7 @@ def log_encoding_ERIMMRGB( bit_depth Bit depth used for conversion. out_int - Whether to return value as integer code value or float equivalent of a + Whether to return value as int code value or float equivalent of a code value at a given bit depth. E_min Minimum exposure limit. @@ -407,7 +403,7 @@ def log_encoding_ERIMMRGB( Returns ------- - :class:`numpy.floating` or :class:`numpy.integer` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Non-linear data :math:`X'_{ERIMM}`. Notes @@ -424,8 +420,8 @@ def log_encoding_ERIMMRGB( | ``X_p`` | [0, 1] | [0, 1] | +----------------+-----------------------+---------------+ - \\* This definition has an output integer switch, thus the domain-range - scale information is only given for the floating point mode. + \\* This definition has an output int switch, thus the domain-range + scale information is only given for the float point mode. References ---------- @@ -470,12 +466,12 @@ def log_encoding_ERIMMRGB( def log_decoding_ERIMMRGB( - X_p: Union[FloatingOrArrayLike, IntegerOrArrayLike], - bit_depth: Integer = 8, - in_int: Boolean = False, - E_min: Floating = 0.001, - E_clip: Floating = 316.2, -) -> FloatingOrNDArray: + X_p: Union[ArrayLike, ArrayLike], + bit_depth: int = 8, + in_int: bool = False, + E_min: float = 0.001, + E_clip: float = 316.2, +) -> NDArrayFloat: """ Define the *ERIMM RGB* log decoding curve / electro-optical transfer function (EOTF). @@ -487,7 +483,7 @@ def log_decoding_ERIMMRGB( bit_depth Bit depth used for conversion. in_int - Whether to treat the input value as integer code value or float + Whether to treat the input value as int code value or float equivalent of a code value at a given bit depth. E_min Minimum exposure limit. @@ -496,7 +492,7 @@ def log_decoding_ERIMMRGB( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Linear data :math:`X_{ERIMM}`. Notes @@ -513,8 +509,8 @@ def log_decoding_ERIMMRGB( | ``X`` | [0, 1] | [0, 1] | +----------------+-----------------------+---------------+ - \\* This definition has an input integer switch, thus the domain-range - scale information is only given for the floating point mode. + \\* This definition has an input int switch, thus the domain-range + scale information is only given for the float point mode. References ---------- diff --git a/colour/models/rgb/transfer_functions/smpte_240m.py b/colour/models/rgb/transfer_functions/smpte_240m.py index 82b0cef4d2..50d8e00315 100644 --- a/colour/models/rgb/transfer_functions/smpte_240m.py +++ b/colour/models/rgb/transfer_functions/smpte_240m.py @@ -22,7 +22,7 @@ import numpy as np from colour.algebra import spow -from colour.hints import FloatingOrArrayLike, FloatingOrNDArray +from colour.hints import ArrayLike, NDArrayFloat from colour.utilities import ( as_float, domain_range_scale, @@ -43,7 +43,7 @@ ] -def oetf_SMPTE240M(L_c: FloatingOrArrayLike) -> FloatingOrNDArray: +def oetf_SMPTE240M(L_c: ArrayLike) -> NDArrayFloat: """ Define *SMPTE 240M* opto-electrical transfer function (OETF). @@ -55,7 +55,7 @@ def oetf_SMPTE240M(L_c: FloatingOrArrayLike) -> FloatingOrNDArray: Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Video signal output :math:`V_c` of the reference camera normalised to the system reference white. @@ -90,7 +90,7 @@ def oetf_SMPTE240M(L_c: FloatingOrArrayLike) -> FloatingOrNDArray: return as_float(from_range_1(V_c)) -def eotf_SMPTE240M(V_r: FloatingOrArrayLike) -> FloatingOrNDArray: +def eotf_SMPTE240M(V_r: ArrayLike) -> NDArrayFloat: """ Define *SMPTE 240M* electro-optical transfer function (EOTF). @@ -102,7 +102,7 @@ def eotf_SMPTE240M(V_r: FloatingOrArrayLike) -> FloatingOrNDArray: Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Light output :math:`L_r` from the reference reproducer normalised to the system reference white. diff --git a/colour/models/rgb/transfer_functions/sony.py b/colour/models/rgb/transfer_functions/sony.py index e926055aac..6fdc43dbf7 100644 --- a/colour/models/rgb/transfer_functions/sony.py +++ b/colour/models/rgb/transfer_functions/sony.py @@ -27,10 +27,8 @@ import numpy as np from colour.hints import ( - Boolean, - FloatingOrArrayLike, - FloatingOrNDArray, - Integer, + ArrayLike, + NDArrayFloat, ) from colour.models.rgb.transfer_functions import full_to_legal, legal_to_full from colour.utilities import ( @@ -59,11 +57,11 @@ def log_encoding_SLog( - x: FloatingOrArrayLike, - bit_depth: Integer = 10, - out_normalised_code_value: Boolean = True, - in_reflection: Boolean = True, -) -> FloatingOrNDArray: + x: ArrayLike, + bit_depth: int = 10, + out_normalised_code_value: bool = True, + in_reflection: bool = True, +) -> NDArrayFloat: """ Define the *Sony S-Log* log encoding curve / opto-electronic transfer function. @@ -83,7 +81,7 @@ def log_encoding_SLog( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Non-linear *Sony S-Log* data :math:`y`. Notes @@ -136,11 +134,11 @@ def log_encoding_SLog( def log_decoding_SLog( - y: FloatingOrArrayLike, - bit_depth: Integer = 10, - in_normalised_code_value: Boolean = True, - out_reflection: Boolean = True, -) -> FloatingOrNDArray: + y: ArrayLike, + bit_depth: int = 10, + in_normalised_code_value: bool = True, + out_reflection: bool = True, +) -> NDArrayFloat: """ Define the *Sony S-Log* log decoding curve / electro-optical transfer function. @@ -159,7 +157,7 @@ def log_decoding_SLog( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Reflection or :math:`IRE / 100` input light level :math:`x` to a camera. @@ -205,11 +203,11 @@ def log_decoding_SLog( def log_encoding_SLog2( - x: FloatingOrArrayLike, - bit_depth: Integer = 10, - out_normalised_code_value: Boolean = True, - in_reflection: Boolean = True, -) -> FloatingOrNDArray: + x: ArrayLike, + bit_depth: int = 10, + out_normalised_code_value: bool = True, + in_reflection: bool = True, +) -> NDArrayFloat: """ Define the *Sony S-Log2* log encoding curve / opto-electronic transfer function. @@ -229,7 +227,7 @@ def log_encoding_SLog2( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Non-linear *Sony S-Log2* data :math:`y`. Notes @@ -273,11 +271,11 @@ def log_encoding_SLog2( def log_decoding_SLog2( - y: FloatingOrArrayLike, - bit_depth: Integer = 10, - in_normalised_code_value: Boolean = True, - out_reflection: Boolean = True, -) -> FloatingOrNDArray: + y: ArrayLike, + bit_depth: int = 10, + in_normalised_code_value: bool = True, + out_reflection: bool = True, +) -> NDArrayFloat: """ Define the *Sony S-Log2* log decoding curve / electro-optical transfer function. @@ -296,7 +294,7 @@ def log_decoding_SLog2( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Reflection or :math:`IRE / 100` input light level :math:`x` to a camera. @@ -334,11 +332,11 @@ def log_decoding_SLog2( def log_encoding_SLog3( - x: FloatingOrArrayLike, - bit_depth: Integer = 10, - out_normalised_code_value: Boolean = True, - in_reflection: Boolean = True, -) -> FloatingOrNDArray: + x: ArrayLike, + bit_depth: int = 10, + out_normalised_code_value: bool = True, + in_reflection: bool = True, +) -> NDArrayFloat: """ Define the *Sony S-Log3* log encoding curve / opto-electronic transfer function. @@ -358,7 +356,7 @@ def log_encoding_SLog3( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Non-linear *Sony S-Log3* data :math:`y`. Notes @@ -411,11 +409,11 @@ def log_encoding_SLog3( def log_decoding_SLog3( - y: FloatingOrArrayLike, - bit_depth: Integer = 10, - in_normalised_code_value: Boolean = True, - out_reflection: Boolean = True, -) -> FloatingOrNDArray: + y: ArrayLike, + bit_depth: int = 10, + in_normalised_code_value: bool = True, + out_reflection: bool = True, +) -> NDArrayFloat: """ Define the *Sony S-Log3* log decoding curve / electro-optical transfer function. @@ -434,7 +432,7 @@ def log_decoding_SLog3( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Reflection or :math:`IRE / 100` input light level :math:`x` to a camera. diff --git a/colour/models/rgb/transfer_functions/srgb.py b/colour/models/rgb/transfer_functions/srgb.py index 669daf5a69..cefe6ffdfe 100644 --- a/colour/models/rgb/transfer_functions/srgb.py +++ b/colour/models/rgb/transfer_functions/srgb.py @@ -28,7 +28,7 @@ import numpy as np from colour.algebra import spow -from colour.hints import FloatingOrArrayLike, FloatingOrNDArray +from colour.hints import ArrayLike, NDArrayFloat from colour.utilities import ( as_float, domain_range_scale, @@ -49,7 +49,7 @@ ] -def eotf_inverse_sRGB(L: FloatingOrArrayLike) -> FloatingOrNDArray: +def eotf_inverse_sRGB(L: ArrayLike) -> NDArrayFloat: """ Define the *IEC 61966-2-1:1999* *sRGB* inverse electro-optical transfer function (EOTF). @@ -61,7 +61,7 @@ def eotf_inverse_sRGB(L: FloatingOrArrayLike) -> FloatingOrNDArray: Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Corresponding electrical signal :math:`V`. Notes @@ -96,7 +96,7 @@ def eotf_inverse_sRGB(L: FloatingOrArrayLike) -> FloatingOrNDArray: return as_float(from_range_1(V)) -def eotf_sRGB(V: FloatingOrArrayLike) -> FloatingOrNDArray: +def eotf_sRGB(V: ArrayLike) -> NDArrayFloat: """ Define the *IEC 61966-2-1:1999* *sRGB* electro-optical transfer function (EOTF). @@ -108,7 +108,7 @@ def eotf_sRGB(V: FloatingOrArrayLike) -> FloatingOrNDArray: Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Corresponding *luminance* :math:`L` of the image. Notes diff --git a/colour/models/rgb/transfer_functions/st_2084.py b/colour/models/rgb/transfer_functions/st_2084.py index 70c6239547..bd6706cf0a 100644 --- a/colour/models/rgb/transfer_functions/st_2084.py +++ b/colour/models/rgb/transfer_functions/st_2084.py @@ -25,7 +25,7 @@ import numpy as np from colour.algebra import spow -from colour.hints import Floating, FloatingOrArrayLike, FloatingOrNDArray +from colour.hints import ArrayLike, NDArrayFloat from colour.utilities import Structure, as_float_array, as_float __author__ = "Colour Developers" @@ -55,10 +55,10 @@ def eotf_inverse_ST2084( - C: FloatingOrArrayLike, - L_p: Floating = 10000, + C: ArrayLike, + L_p: float = 10000, constants: Structure = CONSTANTS_ST2084, -) -> FloatingOrNDArray: +) -> NDArrayFloat: """ Define *SMPTE ST 2084:2014* optimised perceptual inverse electro-optical transfer function (EOTF). @@ -77,7 +77,7 @@ def eotf_inverse_ST2084( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Color value abbreviated as :math:`N`, that is directly proportional to the encoded signal representation, and which is not directly proportional to the optical output of a display device. @@ -133,10 +133,10 @@ def eotf_inverse_ST2084( def eotf_ST2084( - N: FloatingOrArrayLike, - L_p: Floating = 10000, + N: ArrayLike, + L_p: float = 10000, constants: Structure = CONSTANTS_ST2084, -) -> FloatingOrNDArray: +) -> NDArrayFloat: """ Define *SMPTE ST 2084:2014* optimised perceptual electro-optical transfer function (EOTF). @@ -159,7 +159,7 @@ def eotf_ST2084( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Target optical output :math:`C` in :math:`cd/m^2` of the ideal reference display. diff --git a/colour/models/rgb/transfer_functions/viper_log.py b/colour/models/rgb/transfer_functions/viper_log.py index 41504de2a0..93d492ad9d 100644 --- a/colour/models/rgb/transfer_functions/viper_log.py +++ b/colour/models/rgb/transfer_functions/viper_log.py @@ -19,7 +19,7 @@ import numpy as np -from colour.hints import FloatingOrArrayLike, FloatingOrNDArray +from colour.hints import ArrayLike, NDArrayFloat from colour.utilities import as_float, from_range_1, to_domain_1 __author__ = "Colour Developers" @@ -35,7 +35,7 @@ ] -def log_encoding_ViperLog(x: FloatingOrArrayLike) -> FloatingOrNDArray: +def log_encoding_ViperLog(x: ArrayLike) -> NDArrayFloat: """ Define the *Viper Log* log encoding curve / opto-electronic transfer function. @@ -47,7 +47,7 @@ def log_encoding_ViperLog(x: FloatingOrArrayLike) -> FloatingOrNDArray: Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Non-linear data :math:`y`. Notes @@ -81,7 +81,7 @@ def log_encoding_ViperLog(x: FloatingOrArrayLike) -> FloatingOrNDArray: return as_float(from_range_1(y)) -def log_decoding_ViperLog(y: FloatingOrArrayLike) -> FloatingOrNDArray: +def log_decoding_ViperLog(y: ArrayLike) -> NDArrayFloat: """ Define the *Viper Log* log decoding curve / electro-optical transfer function. @@ -93,7 +93,7 @@ def log_decoding_ViperLog(y: FloatingOrArrayLike) -> FloatingOrNDArray: Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Linear data :math:`x`. Notes diff --git a/colour/models/rgb/ycbcr.py b/colour/models/rgb/ycbcr.py index 58bbd7ac5d..6f0b1453d8 100644 --- a/colour/models/rgb/ycbcr.py +++ b/colour/models/rgb/ycbcr.py @@ -55,7 +55,7 @@ import numpy as np -from colour.hints import Any, ArrayLike, Boolean, Integer, NDArray +from colour.hints import Any, ArrayLike, NDArrayFloat, NDArrayNumber from colour.models.rgb.transfer_functions import ( CV_range, oetf_BT2020, @@ -112,9 +112,9 @@ """ -def round_BT2100(a: ArrayLike) -> NDArray: +def round_BT2100(a: ArrayLike) -> NDArrayFloat: """ - Round given array :math:`a` to the nearest integer using the method define + Round given array :math:`a` to the nearest int using the method define as `Round` in *RecommendationITU-R BT.2100*. Parameters @@ -140,7 +140,7 @@ def round_BT2100(a: ArrayLike) -> NDArray: return as_float_array(np.sign(a) * np.floor(np.abs(a) + 0.5)) -def ranges_YCbCr(bits: Integer, is_legal: Boolean, is_int: Boolean) -> NDArray: +def ranges_YCbCr(bits: int, is_legal: bool, is_int: bool) -> NDArrayFloat: """ Return the *Y'CbCr* colour encoding ranges array for given bit depth, range legality and representation. @@ -152,7 +152,7 @@ def ranges_YCbCr(bits: Integer, is_legal: Boolean, is_int: Boolean) -> NDArray: is_legal Whether the *Y'CbCr* colour encoding ranges array is legal. is_int - Whether the *Y'CbCr* colour encoding ranges array represents integer + Whether the *Y'CbCr* colour encoding ranges array represents int code values. Returns @@ -195,11 +195,11 @@ def ranges_YCbCr(bits: Integer, is_legal: Boolean, is_int: Boolean) -> NDArray: def matrix_YCbCr( - K: NDArray = WEIGHTS_YCBCR["ITU-R BT.709"], - bits: Integer = 8, - is_legal: Boolean = False, - is_int: Boolean = False, -) -> NDArray: + K: NDArrayFloat = WEIGHTS_YCBCR["ITU-R BT.709"], + bits: int = 8, + is_legal: bool = False, + is_int: bool = False, +) -> NDArrayFloat: """ Compute the *Y'CbCr* to *R'G'B'* matrix for given weights, bit depth, range legality and representation. @@ -218,7 +218,7 @@ def matrix_YCbCr( is_legal Whether the *Y'CbCr* colour encoding ranges array is legal. is_int - Whether the *Y'CbCr* colour encoding ranges array represents integer + Whether the *Y'CbCr* colour encoding ranges array represents int code values. Returns @@ -282,8 +282,8 @@ def matrix_YCbCr( def offset_YCbCr( - bits: Integer = 8, is_legal: Boolean = False, is_int: Boolean = False -) -> NDArray: + bits: int = 8, is_legal: bool = False, is_int: bool = False +) -> NDArrayFloat: """ Compute the *R'G'B'* to *Y'CbCr* offsets for given bit depth, range legality and representation. @@ -298,7 +298,7 @@ def offset_YCbCr( is_legal Whether the *Y'CbCr* colour encoding ranges array is legal. is_int - Whether the *Y'CbCr* colour encoding ranges array represents integer + Whether the *Y'CbCr* colour encoding ranges array represents int code values. Returns @@ -324,16 +324,16 @@ def offset_YCbCr( def RGB_to_YCbCr( RGB: ArrayLike, - K: NDArray = WEIGHTS_YCBCR["ITU-R BT.709"], - in_bits: Integer = 10, - in_legal: Boolean = False, - in_int: Boolean = False, - out_bits: Integer = 8, - out_legal: Boolean = True, - out_int: Boolean = False, - clamp_int: Boolean = True, + K: NDArrayFloat = WEIGHTS_YCBCR["ITU-R BT.709"], + in_bits: int = 10, + in_legal: bool = False, + in_int: bool = False, + out_bits: int = 8, + out_legal: bool = True, + out_int: bool = False, + clamp_int: bool = True, **kwargs: Any, -) -> NDArray: +) -> NDArrayNumber: """ Convert an array of *R'G'B'* values to the corresponding *Y'CbCr* colour encoding values array. @@ -341,32 +341,32 @@ def RGB_to_YCbCr( Parameters ---------- RGB - Input *R'G'B'* array of floats or integer values. + Input *R'G'B'* array of floats or int values. K Luma weighting coefficients of red and blue. See :attr:`colour.WEIGHTS_YCBCR` for presets. Default is *(0.2126, 0.0722)*, the weightings for *ITU-R BT.709*. in_bits - Bit depth for integer input, or used in the calculation of the + Bit depth for int input, or used in the calculation of the denominator for legal range float values, i.e. 8-bit means the float value for legal white is *235 / 255*. Default is *10*. in_legal Whether to treat the input values as legal range. Default is *False*. in_int - Whether to treat the input values as ``in_bits`` integer code values. + Whether to treat the input values as ``in_bits`` int code values. Default is *False*. out_bits - Bit depth for integer output, or used in the calculation of the + Bit depth for int output, or used in the calculation of the denominator for legal range float values, i.e. 8-bit means the float value for legal white is *235 / 255*. Ignored if ``out_legal`` and ``out_int`` are both *False*. Default is *8*. out_legal Whether to return legal range values. Default is *True*. out_int - Whether to return values as ``out_bits`` integer code values. Default + Whether to return values as ``out_bits`` int code values. Default is *False*. clamp_int - Whether to clamp integer output to allowable range for ``out_bits``. + Whether to clamp int output to allowable range for ``out_bits``. Default is *True*. Other Parameters @@ -385,7 +385,7 @@ def RGB_to_YCbCr( Returns ------- :class:`numpy.ndarray` - *Y'CbCr* colour encoding array of integer or float values. + *Y'CbCr* colour encoding array of int or float values. Warnings -------- @@ -408,8 +408,8 @@ def RGB_to_YCbCr( | ``YCbCr`` | [0, 1] | [0, 1] | +----------------+-----------------------+---------------+ - \\* This definition has input and output integer switches, thus the - domain-range scale information is only given for the floating point mode. + \\* This definition has input and output int switches, thus the + domain-range scale information is only given for the float point mode. - The default arguments, ``**{'in_bits': 10, 'in_legal': False, 'in_int': False, 'out_bits': 8, 'out_legal': True, 'out_int': False}`` @@ -417,7 +417,7 @@ def RGB_to_YCbCr( (``in_bits`` is ignored) to a float *Y'CbCr* output array where *Y'* is normalised to range [16 / 255, 235 / 255] and *Cb* and *Cr* are normalised to range [16 / 255, 240./255]. The float values are - calculated based on an [0, 255] integer range, but no 8-bit + calculated based on an [0, 255] int range, but no 8-bit quantisation or clamping are performed. References @@ -449,7 +449,7 @@ def RGB_to_YCbCr( ... # doctest: +ELLIPSIS array([ 1., 0., 0.]) - Creating integer code values as per standard *10-bit SDI*: + Creating int code values as per standard *10-bit SDI*: >>> RGB_to_YCbCr(RGB, out_legal=True, out_bits=10, out_int=True) ... # doctest: +ELLIPSIS @@ -470,9 +470,9 @@ def RGB_to_YCbCr( Note the use of [0.5, 255.5] for the *Cb / Cr* range, which is required so that the *Cb* and *Cr* output is centered about 128. Using 255 centres it - about 127.5, meaning that there is no integer code value to represent + about 127.5, meaning that there is no int code value to represent achromatic colours. This does however create the possibility of output - integer codes with value of 256, which cannot be stored in 8-bit integer + int codes with value of 256, which cannot be stored in 8-bit int representation. *Recommendation ITU-T T.871* specifies these should be clamped to 255, which is applied with the default ``clamp_int=True``. @@ -531,16 +531,16 @@ def RGB_to_YCbCr( def YCbCr_to_RGB( YCbCr: ArrayLike, - K: NDArray = WEIGHTS_YCBCR["ITU-R BT.709"], - in_bits: Integer = 8, - in_legal: Boolean = True, - in_int: Boolean = False, - out_bits: Integer = 10, - out_legal: Boolean = False, - out_int: Boolean = False, - clamp_int: Boolean = True, + K: NDArrayFloat = WEIGHTS_YCBCR["ITU-R BT.709"], + in_bits: int = 8, + in_legal: bool = True, + in_int: bool = False, + out_bits: int = 10, + out_legal: bool = False, + out_int: bool = False, + clamp_int: bool = True, **kwargs: Any, -) -> NDArray: +) -> NDArrayNumber: """ Convert an array of *Y'CbCr* colour encoding values to the corresponding *R'G'B'* values array. @@ -548,32 +548,32 @@ def YCbCr_to_RGB( Parameters ---------- YCbCr - Input *Y'CbCr* colour encoding array of integer or float values. + Input *Y'CbCr* colour encoding array of int or float values. K Luma weighting coefficients of red and blue. See :attr:`colour.WEIGHTS_YCBCR` for presets. Default is *(0.2126, 0.0722)*, the weightings for *ITU-R BT.709*. in_bits - Bit depth for integer input, or used in the calculation of the + Bit depth for int input, or used in the calculation of the denominator for legal range float values, i.e. 8-bit means the float value for legal white is *235 / 255*. Default is *8*. in_legal Whether to treat the input values as legal range. Default is *True*. in_int - Whether to treat the input values as ``in_bits`` integer code values. + Whether to treat the input values as ``in_bits`` int code values. Default is *False*. out_bits - Bit depth for integer output, or used in the calculation of the + Bit depth for int output, or used in the calculation of the denominator for legal range float values, i.e. 8-bit means the float value for legal white is *235 / 255*. Ignored if ``out_legal`` and ``out_int`` are both *False*. Default is *10*. out_legal Whether to return legal range values. Default is *False*. out_int - Whether to return values as ``out_bits`` integer code values. Default + Whether to return values as ``out_bits`` int code values. Default is *False*. clamp_int - Whether to clamp integer output to allowable range for ``out_bits``. + Whether to clamp int output to allowable range for ``out_bits``. Default is *True*. Other Parameters @@ -592,7 +592,7 @@ def YCbCr_to_RGB( Returns ------- :class:`numpy.ndarray` - *R'G'B'* array of integer or float values. + *R'G'B'* array of int or float values. Notes ----- @@ -608,8 +608,8 @@ def YCbCr_to_RGB( | ``RGB`` | [0, 1] | [0, 1] | +----------------+-----------------------+---------------+ - \\* This definition has input and output integer switches, thus the - domain-range scale information is only given for the floating point mode. + \\* This definition has input and output int switches, thus the + domain-range scale information is only given for the float point mode. Warnings -------- @@ -675,12 +675,12 @@ def YCbCr_to_RGB( def RGB_to_YcCbcCrc( RGB: ArrayLike, - out_bits: Integer = 10, - out_legal: Boolean = True, - out_int: Boolean = False, - is_12_bits_system: Boolean = False, + out_bits: int = 10, + out_legal: bool = True, + out_int: bool = False, + is_12_bits_system: bool = False, **kwargs: Any, -) -> NDArray: +) -> NDArrayNumber: """ Convert an array of *RGB* linear values to the corresponding *Yc'Cbc'Crc'* colour encoding values array. @@ -690,14 +690,14 @@ def RGB_to_YcCbcCrc( RGB Input *RGB* array of linear float values. out_bits - Bit depth for integer output, or used in the calculation of the + Bit depth for int output, or used in the calculation of the denominator for legal range float values, i.e. 8-bit means the float value for legal white is *235 / 255*. Ignored if ``out_legal`` and ``out_int`` are both *False*. Default is *10*. out_legal Whether to return legal range values. Default is *True*. out_int - Whether to return values as ``out_bits`` integer code values. Default + Whether to return values as ``out_bits`` int code values. Default is *False*. is_12_bits_system *Recommendation ITU-R BT.2020* OETF (OECF) adopts different parameters @@ -714,7 +714,7 @@ def RGB_to_YcCbcCrc( Returns ------- :class:`numpy.ndarray` - *Yc'Cbc'Crc'* colour encoding array of integer or float values. + *Yc'Cbc'Crc'* colour encoding array of int or float values. Notes ----- @@ -730,8 +730,8 @@ def RGB_to_YcCbcCrc( | ``YcCbcCrc`` | [0, 1] | [0, 1] | +----------------+-----------------------+---------------+ - \\* This definition has input and output integer switches, thus the - domain-range scale information is only given for the floating point mode. + \\* This definition has input and output int switches, thus the + domain-range scale information is only given for the float point mode. Warnings -------- @@ -788,12 +788,12 @@ def RGB_to_YcCbcCrc( def YcCbcCrc_to_RGB( YcCbcCrc: ArrayLike, - in_bits: Integer = 10, - in_legal: Boolean = True, - in_int: Boolean = False, - is_12_bits_system: Boolean = False, + in_bits: int = 10, + in_legal: bool = True, + in_int: bool = False, + is_12_bits_system: bool = False, **kwargs: Any, -) -> NDArray: +) -> NDArrayFloat: """ Convert an array of *Yc'Cbc'Crc'* colour encoding values to the corresponding *RGB* array of linear values. @@ -803,13 +803,13 @@ def YcCbcCrc_to_RGB( YcCbcCrc Input *Yc'Cbc'Crc'* colour encoding array of linear float values. in_bits - Bit depth for integer input, or used in the calculation of the + Bit depth for int input, or used in the calculation of the denominator for legal range float values, i.e. 8-bit means the float value for legal white is *235 / 255*. Default is *10*. in_legal Whether to treat the input values as legal range. Default is *False*. in_int - Whether to treat the input values as ``in_bits`` integer code values. + Whether to treat the input values as ``in_bits`` int code values. Default is *False*. is_12_bits_system *Recommendation ITU-R BT.2020* EOTF (EOCF) adopts different parameters @@ -842,8 +842,8 @@ def YcCbcCrc_to_RGB( | ``RGB`` | [0, 1] | [0, 1] | +----------------+-----------------------+---------------+ - \\* This definition has input and output integer switches, thus the - domain-range scale information is only given for the floating point mode. + \\* This definition has input and output int switches, thus the + domain-range scale information is only given for the float point mode. Warnings -------- diff --git a/colour/models/rgb/ycocg.py b/colour/models/rgb/ycocg.py index 1d85097750..b310827d8b 100644 --- a/colour/models/rgb/ycocg.py +++ b/colour/models/rgb/ycocg.py @@ -20,7 +20,7 @@ import numpy as np from colour.algebra import vector_dot -from colour.hints import ArrayLike, NDArray +from colour.hints import ArrayLike, NDArrayFloat __author__ = "Colour Developers" __copyright__ = "Copyright 2013 Colour Developers" @@ -36,7 +36,7 @@ "YCoCg_to_RGB", ] -MATRIX_RGB_TO_YCOCG: NDArray = np.array( +MATRIX_RGB_TO_YCOCG: NDArrayFloat = np.array( [ [1 / 4, 1 / 2, 1 / 4], [1 / 2, 0, -1 / 2], @@ -45,7 +45,7 @@ ) """*R'G'B'* colourspace to *YCoCg* colour encoding matrix.""" -MATRIX_YCOCG_TO_RGB: NDArray = np.array( +MATRIX_YCOCG_TO_RGB: NDArrayFloat = np.array( [ [1, 1, -1], [1, 0, 1], @@ -55,7 +55,7 @@ """*YCoCg* colour encoding to *R'G'B'* colourspace matrix.""" -def RGB_to_YCoCg(RGB: ArrayLike) -> NDArray: +def RGB_to_YCoCg(RGB: ArrayLike) -> NDArrayFloat: """ Convert an array of *R'G'B'* values to the corresponding *YCoCg* colour encoding values array. @@ -85,7 +85,7 @@ def RGB_to_YCoCg(RGB: ArrayLike) -> NDArray: return vector_dot(MATRIX_RGB_TO_YCOCG, RGB) -def YCoCg_to_RGB(YCoCg: ArrayLike) -> NDArray: +def YCoCg_to_RGB(YCoCg: ArrayLike) -> NDArrayFloat: """ Convert an array of *YCoCg* colour encoding values to the corresponding *R'G'B'* values array. diff --git a/colour/notation/datasets/munsell/all.py b/colour/notation/datasets/munsell/all.py index 1588b33619..ee665dcb5e 100644 --- a/colour/notation/datasets/munsell/all.py +++ b/colour/notation/datasets/munsell/all.py @@ -38,8 +38,6 @@ import numpy as np -from colour.hints import Tuple - __author__ = "Colour Developers" __copyright__ = "Copyright 2013 Colour Developers" __license__ = "New BSD License - https://opensource.org/licenses/BSD-3-Clause" @@ -52,7 +50,7 @@ ] -MUNSELL_COLOURS_ALL: Tuple = ( +MUNSELL_COLOURS_ALL: tuple = ( (("2.5GY", 0.2, 2.0), np.array([0.7130, 1.4140, 0.2370])), (("5GY", 0.2, 2.0), np.array([0.4490, 1.1450, 0.2370])), (("7.5GY", 0.2, 2.0), np.array([0.2620, 0.8370, 0.2370])), diff --git a/colour/notation/datasets/munsell/experimental.py b/colour/notation/datasets/munsell/experimental.py index 62d845e7bb..970353966f 100644 --- a/colour/notation/datasets/munsell/experimental.py +++ b/colour/notation/datasets/munsell/experimental.py @@ -39,8 +39,6 @@ import numpy as np -from colour.hints import Tuple - __author__ = "Colour Developers" __copyright__ = "Copyright 2013 Colour Developers" __license__ = "New BSD License - https://opensource.org/licenses/BSD-3-Clause" @@ -53,7 +51,7 @@ ] -MUNSELL_COLOURS_1929: Tuple = ( +MUNSELL_COLOURS_1929: tuple = ( (("10RP", 2.0, 2.0), np.array([0.3532, 0.2957, 3.1260])), (("10RP", 2.0, 4.0), np.array([0.3850, 0.2778, 3.1260])), (("10RP", 2.0, 6.0), np.array([0.4139, 0.2608, 3.1260])), diff --git a/colour/notation/datasets/munsell/real.py b/colour/notation/datasets/munsell/real.py index bd63b4936e..0c4ef45148 100644 --- a/colour/notation/datasets/munsell/real.py +++ b/colour/notation/datasets/munsell/real.py @@ -39,8 +39,6 @@ import numpy as np -from colour.hints import Tuple - __author__ = "Colour Developers" __copyright__ = "Copyright 2013 Colour Developers" __license__ = "New BSD License - https://opensource.org/licenses/BSD-3-Clause" @@ -53,7 +51,7 @@ ] -MUNSELL_COLOURS_REAL: Tuple = ( +MUNSELL_COLOURS_REAL: tuple = ( (("10RP", 1.0, 2.0), np.array([0.3629, 0.2710, 1.2100])), (("10RP", 1.0, 4.0), np.array([0.3920, 0.2423, 1.2100])), (("10RP", 1.0, 6.0), np.array([0.4151, 0.2169, 1.2100])), diff --git a/colour/notation/hexadecimal.py b/colour/notation/hexadecimal.py index 40f1ef4001..73a9ea31bc 100644 --- a/colour/notation/hexadecimal.py +++ b/colour/notation/hexadecimal.py @@ -13,7 +13,7 @@ import numpy as np from colour.algebra import normalise_maximum -from colour.hints import ArrayLike, List, NDArray, StrOrArrayLike, StrOrNDArray +from colour.hints import ArrayLike, NDArrayFloat, NDArrayStr from colour.models import eotf_inverse_sRGB, eotf_sRGB from colour.utilities import ( as_float_array, @@ -36,7 +36,7 @@ ] -def RGB_to_HEX(RGB: ArrayLike) -> StrOrNDArray: +def RGB_to_HEX(RGB: ArrayLike) -> NDArrayStr: """ Convert from *RGB* colourspace to hexadecimal representation. @@ -91,7 +91,7 @@ def RGB_to_HEX(RGB: ArrayLike) -> StrOrNDArray: return HEX -def HEX_to_RGB(HEX: StrOrArrayLike) -> NDArray: +def HEX_to_RGB(HEX: ArrayLike) -> NDArrayFloat: """ Convert from hexadecimal representation to *RGB* colourspace. @@ -120,15 +120,15 @@ def HEX_to_RGB(HEX: StrOrArrayLike) -> NDArray: array([ 0.6666666..., 0.8666666..., 1. ]) """ - HEX = np.core.defchararray.lstrip(HEX, "#") # type: ignore[arg-type] + HEX = np.core.defchararray.lstrip(HEX, "#") # pyright: ignore - def to_RGB(x: List) -> List: + def to_RGB(x: list) -> list: """Convert given hexadecimal representation to *RGB*.""" l_x = len(x) return [ - int(x[i : i + l_x // 3], 16) # type: ignore[call-overload] + int(x[i : i + l_x // 3], 16) # pyright: ignore for i in range(0, l_x, l_x // 3) ] diff --git a/colour/notation/munsell.py b/colour/notation/munsell.py index 15c6fcefd1..d2e88d870d 100644 --- a/colour/notation/munsell.py +++ b/colour/notation/munsell.py @@ -135,19 +135,12 @@ ) from colour.hints import ( ArrayLike, - Boolean, - Dict, - Floating, - FloatingOrArrayLike, - FloatingOrNDArray, - Integer, Literal, - NDArray, + NDArrayFloat, + NDArrayStr, Optional, - StrOrArrayLike, - StrOrNDArray, - Tuple, Union, + cast, ) from colour.models import Lab_to_LCHab, XYZ_to_Lab, XYZ_to_xy, xyY_to_XYZ from colour.volume import is_within_macadam_limits @@ -258,26 +251,26 @@ ) ILLUMINANT_NAME_MUNSELL: str = "C" -CCS_ILLUMINANT_MUNSELL: NDArray = CCS_ILLUMINANTS[ +CCS_ILLUMINANT_MUNSELL: NDArrayFloat = CCS_ILLUMINANTS[ "CIE 1931 2 Degree Standard Observer" ][ILLUMINANT_NAME_MUNSELL] -_CACHE_MUNSELL_SPECIFICATIONS: Dict = CACHE_REGISTRY.register_cache( +_CACHE_MUNSELL_SPECIFICATIONS: dict = CACHE_REGISTRY.register_cache( f"{__name__}._CACHE_MUNSELL_SPECIFICATIONS" ) -_CACHE_MUNSELL_VALUE_ASTM_D1535_08_INTERPOLATOR: Dict = ( +_CACHE_MUNSELL_VALUE_ASTM_D1535_08_INTERPOLATOR: dict = ( CACHE_REGISTRY.register_cache( f"{__name__}._CACHE_MUNSELL_VALUE_ASTM_D1535_08_INTERPOLATOR" ) ) -_CACHE_MUNSELL_MAXIMUM_CHROMAS_FROM_RENOTATION: Dict = ( +_CACHE_MUNSELL_MAXIMUM_CHROMAS_FROM_RENOTATION: dict = ( CACHE_REGISTRY.register_cache( f"{__name__}._CACHE_MUNSELL_MAXIMUM_CHROMAS_FROM_RENOTATION" ) ) -def _munsell_specifications() -> NDArray: +def _munsell_specifications() -> NDArrayFloat: """ Return the *Munsell Renotation System* specifications and caches them if not existing. @@ -300,7 +293,7 @@ def _munsell_specifications() -> NDArray: Returns ------- - :class:`numpy.ndarray` + :class:`numpy.NDArrayFloat` *Munsell Renotation System* specifications. """ @@ -356,8 +349,8 @@ def _munsell_value_ASTMD1535_interpolator() -> Extrapolator: return extrapolator -def _munsell_maximum_chromas_from_renotation() -> Tuple[ - Tuple[Tuple[Floating, Floating, Floating], Floating], ... +def _munsell_maximum_chromas_from_renotation() -> tuple[ + tuple[tuple[float, float], float], ... ]: """ Return the maximum *Munsell* chromas from *Munsell Renotation System* data @@ -378,7 +371,7 @@ def _munsell_maximum_chromas_from_renotation() -> Tuple[ "Maximum Chromas From Renotation" ] - chromas: Dict[Tuple[Floating, Floating, Floating], Floating] = {} + chromas = {} for munsell_colour in MUNSELL_COLOURS_ALL: hue, value, chroma, code = tsplit( munsell_colour_to_munsell_specification( @@ -389,7 +382,7 @@ def _munsell_maximum_chromas_from_renotation() -> Tuple[ if index in chromas: chroma = max([chromas[index], chroma]) - chromas[index] = chroma + chromas[index] = cast(float, chroma) maximum_chromas_from_renotation = tuple( zip(chromas.keys(), chromas.values()) @@ -402,7 +395,7 @@ def _munsell_maximum_chromas_from_renotation() -> Tuple[ return maximum_chromas_from_renotation -def munsell_value_Priest1920(Y: FloatingOrArrayLike) -> FloatingOrNDArray: +def munsell_value_Priest1920(Y: ArrayLike) -> NDArrayFloat: """ Return the *Munsell* value :math:`V` of given *luminance* :math:`Y` using *Priest et al. (1920)* method. @@ -414,7 +407,7 @@ def munsell_value_Priest1920(Y: FloatingOrArrayLike) -> FloatingOrNDArray: Returns ------- - :class:`np.floating` or :class:`numpy.ndarray` + :class:`np.float` or :class:`numpy.NDArrayFloat` *Munsell* value :math:`V`. Notes @@ -448,7 +441,7 @@ def munsell_value_Priest1920(Y: FloatingOrArrayLike) -> FloatingOrNDArray: return as_float(from_range_10(V)) -def munsell_value_Munsell1933(Y: FloatingOrArrayLike) -> FloatingOrNDArray: +def munsell_value_Munsell1933(Y: ArrayLike) -> NDArrayFloat: """ Return the *Munsell* value :math:`V` of given *luminance* :math:`Y` using *Munsell et al. (1933)* method. @@ -460,7 +453,7 @@ def munsell_value_Munsell1933(Y: FloatingOrArrayLike) -> FloatingOrNDArray: Returns ------- - :class:`np.floating` or :class:`numpy.ndarray` + :class:`np.float` or :class:`numpy.NDArrayFloat` *Munsell* value :math:`V`. Notes @@ -494,7 +487,7 @@ def munsell_value_Munsell1933(Y: FloatingOrArrayLike) -> FloatingOrNDArray: return as_float(from_range_10(V)) -def munsell_value_Moon1943(Y: FloatingOrArrayLike) -> FloatingOrNDArray: +def munsell_value_Moon1943(Y: ArrayLike) -> NDArrayFloat: """ Return the *Munsell* value :math:`V` of given *luminance* :math:`Y` using *Moon and Spencer (1943)* method. @@ -507,7 +500,7 @@ def munsell_value_Moon1943(Y: FloatingOrArrayLike) -> FloatingOrNDArray: Returns ------- - :class:`np.floating` or :class:`numpy.ndarray` + :class:`np.float` or :class:`numpy.NDArrayFloat` *Munsell* value :math:`V`. Notes @@ -541,7 +534,7 @@ def munsell_value_Moon1943(Y: FloatingOrArrayLike) -> FloatingOrNDArray: return as_float(from_range_10(V)) -def munsell_value_Saunderson1944(Y: FloatingOrArrayLike) -> FloatingOrNDArray: +def munsell_value_Saunderson1944(Y: ArrayLike) -> NDArrayFloat: """ Return the *Munsell* value :math:`V` of given *luminance* :math:`Y` using *Saunderson and Milner (1944)* method. @@ -553,7 +546,7 @@ def munsell_value_Saunderson1944(Y: FloatingOrArrayLike) -> FloatingOrNDArray: Returns ------- - :class:`np.floating` or :class:`numpy.ndarray` + :class:`np.float` or :class:`numpy.NDArrayFloat` *Munsell* value :math:`V`. Notes @@ -587,7 +580,7 @@ def munsell_value_Saunderson1944(Y: FloatingOrArrayLike) -> FloatingOrNDArray: return as_float(from_range_10(V)) -def munsell_value_Ladd1955(Y: FloatingOrArrayLike) -> FloatingOrNDArray: +def munsell_value_Ladd1955(Y: ArrayLike) -> NDArrayFloat: """ Return the *Munsell* value :math:`V` of given *luminance* :math:`Y` using *Ladd and Pinney (1955)* method. @@ -599,7 +592,7 @@ def munsell_value_Ladd1955(Y: FloatingOrArrayLike) -> FloatingOrNDArray: Returns ------- - :class:`np.floating` or :class:`numpy.ndarray` + :class:`np.float` or :class:`numpy.NDArrayFloat` *Munsell* value :math:`V`. Notes @@ -633,7 +626,7 @@ def munsell_value_Ladd1955(Y: FloatingOrArrayLike) -> FloatingOrNDArray: return as_float(from_range_10(V)) -def munsell_value_McCamy1987(Y: FloatingOrArrayLike) -> FloatingOrNDArray: +def munsell_value_McCamy1987(Y: ArrayLike) -> NDArrayFloat: """ Return the *Munsell* value :math:`V` of given *luminance* :math:`Y` using *McCamy (1987)* method. @@ -645,7 +638,7 @@ def munsell_value_McCamy1987(Y: FloatingOrArrayLike) -> FloatingOrNDArray: Returns ------- - :class:`np.floating` or :class:`numpy.ndarray` + :class:`np.float` or :class:`numpy.NDArrayFloat` *Munsell* value :math:`V`. Notes @@ -690,7 +683,7 @@ def munsell_value_McCamy1987(Y: FloatingOrArrayLike) -> FloatingOrNDArray: return as_float(from_range_10(V)) -def munsell_value_ASTMD1535(Y: FloatingOrArrayLike) -> FloatingOrNDArray: +def munsell_value_ASTMD1535(Y: ArrayLike) -> NDArrayFloat: """ Return the *Munsell* value :math:`V` of given *luminance* :math:`Y` using an inverse lookup table from *ASTM D1535-08e1* method. @@ -702,7 +695,7 @@ def munsell_value_ASTMD1535(Y: FloatingOrArrayLike) -> FloatingOrNDArray: Returns ------- - :class:`np.floating` or :class:`numpy.ndarray` + :class:`np.float` or :class:`numpy.NDArrayFloat` *Munsell* value :math:`V`. Notes @@ -765,7 +758,7 @@ def munsell_value_ASTMD1535(Y: FloatingOrArrayLike) -> FloatingOrNDArray: def munsell_value( - Y: FloatingOrArrayLike, + Y: ArrayLike, method: Union[ Literal[ "ASTM D1535", @@ -778,7 +771,7 @@ def munsell_value( ], str, ] = "ASTM D1535", -) -> FloatingOrNDArray: +) -> NDArrayFloat: """ Return the *Munsell* value :math:`V` of given *luminance* :math:`Y` using given method. @@ -792,7 +785,7 @@ def munsell_value( Returns ------- - :class:`np.floating` or :class:`numpy.ndarray` + :class:`np.float` or :class:`numpy.NDArrayFloat` *Munsell* value :math:`V`. Notes @@ -837,20 +830,20 @@ def munsell_value( return MUNSELL_VALUE_METHODS[method](Y) -def _munsell_scale_factor() -> NDArray: +def _munsell_scale_factor() -> NDArrayFloat: """ Return the domain-range scale factor for *Munsell Renotation System*. Returns ------- - :class:`numpy.ndarray` + :class:`numpy.NDArrayFloat` Domain-range scale factor for *Munsell Renotation System*. """ return np.array([10, 10, 50 if get_domain_range_scale() == "1" else 2, 10]) -def _munsell_specification_to_xyY(specification: ArrayLike) -> NDArray: +def _munsell_specification_to_xyY(specification: ArrayLike) -> NDArrayFloat: """ Convert given *Munsell* *Colorlab* specification to *CIE xyY* colourspace. @@ -861,7 +854,7 @@ def _munsell_specification_to_xyY(specification: ArrayLike) -> NDArray: Returns ------- - :class:`numpy.ndarray` + :class:`numpy.NDArrayFloat` *CIE xyY* colourspace array. """ @@ -928,7 +921,7 @@ def _munsell_specification_to_xyY(specification: ArrayLike) -> NDArray: return tstack([x, y, from_range_1(Y / 100)]) -def munsell_specification_to_xyY(specification: ArrayLike) -> NDArray: +def munsell_specification_to_xyY(specification: ArrayLike) -> NDArrayFloat: """ Convert given *Munsell* *Colorlab* specification to *CIE xyY* colourspace. @@ -939,7 +932,7 @@ def munsell_specification_to_xyY(specification: ArrayLike) -> NDArray: Returns ------- - :class:`numpy.ndarray` + :class:`numpy.NDArrayFloat` *CIE xyY* colourspace array. Notes @@ -989,7 +982,7 @@ def munsell_specification_to_xyY(specification: ArrayLike) -> NDArray: return np.reshape(as_float_array(xyY), shape) -def munsell_colour_to_xyY(munsell_colour: StrOrArrayLike) -> NDArray: +def munsell_colour_to_xyY(munsell_colour: ArrayLike) -> NDArrayFloat: """ Convert given *Munsell* colour to *CIE xyY* colourspace. @@ -1000,7 +993,7 @@ def munsell_colour_to_xyY(munsell_colour: StrOrArrayLike) -> NDArray: Returns ------- - :class:`numpy.ndarray` + :class:`numpy.NDArrayFloat` *CIE xyY* colourspace array. Notes @@ -1040,7 +1033,7 @@ def munsell_colour_to_xyY(munsell_colour: StrOrArrayLike) -> NDArray: ) -def _xyY_to_munsell_specification(xyY: ArrayLike) -> NDArray: +def _xyY_to_munsell_specification(xyY: ArrayLike) -> NDArrayFloat: """ Convert from *CIE xyY* colourspace to *Munsell* *Colorlab* specification. @@ -1051,7 +1044,7 @@ def _xyY_to_munsell_specification(xyY: ArrayLike) -> NDArray: Returns ------- - :class:`numpy.ndarray` + :class:`numpy.NDArrayFloat` *Munsell* *Colorlab* specification. Raises @@ -1346,7 +1339,7 @@ def _xyY_to_munsell_specification(xyY: ArrayLike) -> NDArray: ) -def xyY_to_munsell_specification(xyY: ArrayLike) -> NDArray: +def xyY_to_munsell_specification(xyY: ArrayLike) -> NDArrayFloat: """ Convert from *CIE xyY* colourspace to *Munsell* *Colorlab* specification. @@ -1357,7 +1350,7 @@ def xyY_to_munsell_specification(xyY: ArrayLike) -> NDArray: Returns ------- - :class:`numpy.ndarray` + :class:`numpy.NDArrayFloat` *Munsell* *Colorlab* specification. Raises @@ -1414,10 +1407,10 @@ def xyY_to_munsell_specification(xyY: ArrayLike) -> NDArray: def xyY_to_munsell_colour( xyY: ArrayLike, - hue_decimals: Integer = 1, - value_decimals: Integer = 1, - chroma_decimals: Integer = 1, -) -> StrOrNDArray: + hue_decimals: int = 1, + value_decimals: int = 1, + chroma_decimals: int = 1, +) -> Union[str, NDArrayStr]: """ Convert from *CIE xyY* colourspace to *Munsell* colour. @@ -1434,7 +1427,7 @@ def xyY_to_munsell_colour( Returns ------- - :class:`str` or :class:`numpy.ndarray` + :class:`str` or :class:`numpy.NDArrayFloat` *Munsell* colour. Notes @@ -1475,7 +1468,7 @@ def xyY_to_munsell_colour( return str(munsell_colour) if shape == [4] else munsell_colour -def parse_munsell_colour(munsell_colour: str) -> NDArray: +def parse_munsell_colour(munsell_colour: str) -> NDArrayFloat: """ Parse given *Munsell* colour and returns an intermediate *Munsell* *Colorlab* specification. @@ -1487,7 +1480,7 @@ def parse_munsell_colour(munsell_colour: str) -> NDArray: Returns ------- - :class:`numpy.ndarray` + :class:`numpy.NDArrayFloat` Intermediate *Munsell* *Colorlab* specification. Raises @@ -1534,7 +1527,7 @@ def parse_munsell_colour(munsell_colour: str) -> NDArray: ) -def is_grey_munsell_colour(specification: ArrayLike) -> Boolean: +def is_grey_munsell_colour(specification: ArrayLike) -> bool: """ Return if given *Munsell* *Colorlab* specification is a grey colour. @@ -1563,7 +1556,7 @@ def is_grey_munsell_colour(specification: ArrayLike) -> Boolean: return is_numeric(as_float(specification)) -def normalise_munsell_specification(specification: ArrayLike) -> NDArray: +def normalise_munsell_specification(specification: ArrayLike) -> NDArrayFloat: """ Normalise given *Munsell* *Colorlab* specification. @@ -1574,7 +1567,7 @@ def normalise_munsell_specification(specification: ArrayLike) -> NDArray: Returns ------- - :class:`numpy.ndarray` + :class:`numpy.NDArrayFloat` Normalised *Munsell* *Colorlab* specification. Examples @@ -1604,7 +1597,9 @@ def normalise_munsell_specification(specification: ArrayLike) -> NDArray: return tstack([hue, value, chroma, code]) -def munsell_colour_to_munsell_specification(munsell_colour: str) -> NDArray: +def munsell_colour_to_munsell_specification( + munsell_colour: str, +) -> NDArrayFloat: """ Retrieve a normalised *Munsell* *Colorlab* specification from given *Munsell* colour. @@ -1616,7 +1611,7 @@ def munsell_colour_to_munsell_specification(munsell_colour: str) -> NDArray: Returns ------- - :class:`numpy.ndarray` + :class:`numpy.NDArrayFloat` Normalised *Munsell* *Colorlab* specification. Examples @@ -1634,9 +1629,9 @@ def munsell_colour_to_munsell_specification(munsell_colour: str) -> NDArray: def munsell_specification_to_munsell_colour( specification: ArrayLike, - hue_decimals: Integer = 1, - value_decimals: Integer = 1, - chroma_decimals: Integer = 1, + hue_decimals: int = 1, + value_decimals: int = 1, + chroma_decimals: int = 1, ) -> str: """ Convert from *Munsell* *Colorlab* specification to given *Munsell* colour. @@ -1719,7 +1714,7 @@ def munsell_specification_to_munsell_colour( ) -def xyY_from_renotation(specification: ArrayLike) -> NDArray: +def xyY_from_renotation(specification: ArrayLike) -> NDArrayFloat: """ Return given existing *Munsell* *Colorlab* specification *CIE xyY* colourspace vector from *Munsell Renotation System* data. @@ -1731,7 +1726,7 @@ def xyY_from_renotation(specification: ArrayLike) -> NDArray: Returns ------- - :class:`numpy.ndarray` + :class:`numpy.NDArrayFloat` *CIE xyY* colourspace vector. Raises @@ -1761,7 +1756,7 @@ def xyY_from_renotation(specification: ArrayLike) -> NDArray: ) -def is_specification_in_renotation(specification: ArrayLike) -> Boolean: +def is_specification_in_renotation(specification: ArrayLike) -> bool: """ Return whether given *Munsell* *Colorlab* specification is in *Munsell Renotation System* data. @@ -1792,7 +1787,7 @@ def is_specification_in_renotation(specification: ArrayLike) -> Boolean: return False -def bounding_hues_from_renotation(hue_and_code: ArrayLike) -> NDArray: +def bounding_hues_from_renotation(hue_and_code: ArrayLike) -> NDArrayFloat: """ Return for a given *Munsell* *Colorlab* specification hue and *Munsell* *Colorlab* specification code the two bounding hues from @@ -1806,7 +1801,7 @@ def bounding_hues_from_renotation(hue_and_code: ArrayLike) -> NDArray: Returns ------- - :class:`numpy.ndarray` + :class:`numpy.NDArrayFloat` Bounding hues. References @@ -1828,10 +1823,10 @@ def bounding_hues_from_renotation(hue_and_code: ArrayLike) -> NDArray: hue, code = as_float_array(hue_and_code) - hue_cw: Floating - code_cw: Floating - hue_ccw: Floating - code_ccw: Floating + hue_cw: float + code_cw: float + hue_ccw: float + code_ccw: float if hue % 2.5 == 0: if hue == 0: @@ -1860,7 +1855,7 @@ def bounding_hues_from_renotation(hue_and_code: ArrayLike) -> NDArray: return as_float_array([(hue_cw, code_cw), (hue_ccw, code_ccw)]) -def hue_to_hue_angle(hue_and_code: ArrayLike) -> Floating: +def hue_to_hue_angle(hue_and_code: ArrayLike) -> float: """ Convert from the *Munsell* *Colorlab* specification hue and *Munsell* *Colorlab* specification code to hue angle in degrees. @@ -1873,7 +1868,7 @@ def hue_to_hue_angle(hue_and_code: ArrayLike) -> Floating: Returns ------- - :class:`numpy.floating` + :class:`float` Hue angle in degrees. References @@ -1897,7 +1892,7 @@ def hue_to_hue_angle(hue_and_code: ArrayLike) -> Floating: return as_float_scalar(hue_angle) -def hue_angle_to_hue(hue_angle: Floating) -> NDArray: +def hue_angle_to_hue(hue_angle: float) -> NDArrayFloat: """ Convert from hue angle in degrees to the *Munsell* *Colorlab* specification hue and code. @@ -1909,7 +1904,7 @@ def hue_angle_to_hue(hue_angle: Floating) -> NDArray: Returns ------- - :class:`numpy.ndarray` + :class:`numpy.NDArrayFloat` (*Munsell* *Colorlab* specification hue, *Munsell* *Colorlab* specification code). @@ -1954,10 +1949,10 @@ def hue_angle_to_hue(hue_angle: Floating) -> NDArray: if hue == 0: hue = 10 - return tstack([hue, code]) + return tstack(cast(ArrayLike, [hue, code])) -def hue_to_ASTM_hue(hue_and_code) -> Floating: +def hue_to_ASTM_hue(hue_and_code) -> float: """ Convert from the *Munsell* *Colorlab* specification hue and *Munsell* *Colorlab* specification codeto *ASTM* hue number. @@ -1971,7 +1966,7 @@ def hue_to_ASTM_hue(hue_and_code) -> Floating: Returns ------- - :class:`numpy.floating` + :class:`float` *ASTM* hue number. References @@ -2021,9 +2016,7 @@ def interpolation_method_from_renotation_ovoid( specification = normalise_munsell_specification(specification) - interpolation_methods: Dict[ - Integer, Optional[Literal["Linear", "Radial"]] - ] = { + interpolation_methods: dict[int, Optional[Literal["Linear", "Radial"]]] = { 0: None, 1: "Linear", 2: "Radial", @@ -2043,7 +2036,7 @@ def interpolation_method_from_renotation_ovoid( attest( is_integer(value), - f'"{specification}" specification value must be an integer!', + f'"{specification}" specification value must be an int!', ) value = round(value) @@ -2056,7 +2049,7 @@ def interpolation_method_from_renotation_ovoid( attest( abs(2 * (chroma / 2 - round(chroma / 2))) <= INTEGER_THRESHOLD, - f'"{specification}" specification chroma must be an integer and ' + f'"{specification}" specification chroma must be an int and ' f"multiple of 2!", ) @@ -2299,7 +2292,7 @@ def interpolation_method_from_renotation_ovoid( return interpolation_methods[interpolation_method] -def xy_from_renotation_ovoid(specification: ArrayLike) -> NDArray: +def xy_from_renotation_ovoid(specification: ArrayLike) -> NDArrayFloat: """ Convert given *Munsell* *Colorlab* specification to *CIE xy* chromaticity coordinates on *Munsell Renotation System* ovoid. @@ -2314,7 +2307,7 @@ def xy_from_renotation_ovoid(specification: ArrayLike) -> NDArray: Returns ------- - :class:`numpy.ndarray` + :class:`numpy.NDArrayFloat` *CIE xy* chromaticity coordinates. Raises @@ -2352,7 +2345,7 @@ def xy_from_renotation_ovoid(specification: ArrayLike) -> NDArray: attest( is_integer(value), - f'"{specification}" specification value must be an integer!', + f'"{specification}" specification value must be an int!', ) value = round(value) @@ -2365,7 +2358,7 @@ def xy_from_renotation_ovoid(specification: ArrayLike) -> NDArray: attest( abs(2 * (chroma / 2 - round(chroma / 2))) <= INTEGER_THRESHOLD, - f'"{specification}" specification chroma must be an integer and ' + f'"{specification}" specification chroma must be an int and ' f"multiple of 2!", ) @@ -2387,9 +2380,9 @@ def xy_from_renotation_ovoid(specification: ArrayLike) -> NDArray: return tstack([x, y]) - hue_cw, hue_ccw = bounding_hues_from_renotation([hue, code]) - hue_minus, code_minus = hue_cw - hue_plus, code_plus = hue_ccw + hue_code_cw, hue_code_ccw = bounding_hues_from_renotation([hue, code]) + hue_minus, code_minus = hue_code_cw + hue_plus, code_plus = hue_code_ccw x_grey, y_grey = CCS_ILLUMINANT_MUNSELL @@ -2471,7 +2464,7 @@ def xy_from_renotation_ovoid(specification: ArrayLike) -> NDArray: return tstack([x, y]) -def LCHab_to_munsell_specification(LCHab: ArrayLike) -> NDArray: +def LCHab_to_munsell_specification(LCHab: ArrayLike) -> NDArrayFloat: """ Convert from *CIE L\\*C\\*Hab* colourspace to approximate *Munsell* *Colorlab* specification. @@ -2483,7 +2476,7 @@ def LCHab_to_munsell_specification(LCHab: ArrayLike) -> NDArray: Returns ------- - :class:`numpy.ndarray` + :class:`numpy.NDArrayFloat` *Munsell* *Colorlab* specification. References @@ -2529,12 +2522,10 @@ def LCHab_to_munsell_specification(LCHab: ArrayLike) -> NDArray: value = L / 10 chroma = C / 5 - return tstack([hue, value, chroma, code]) + return tstack(cast(ArrayLike, [hue, value, chroma, code])) -def maximum_chroma_from_renotation( - hue_and_value_and_code: ArrayLike, -) -> Floating: +def maximum_chroma_from_renotation(hue_and_value_and_code: ArrayLike) -> float: """ Return the maximum *Munsell* chroma from *Munsell Renotation System* data using given *Munsell* *Colorlab* specification hue, *Munsell* *Colorlab* @@ -2548,7 +2539,7 @@ def maximum_chroma_from_renotation( Returns ------- - :class:`numpy.floating` + :class:`float` Maximum chroma. References @@ -2579,26 +2570,34 @@ def maximum_chroma_from_renotation( value_minus = np.floor(value) value_plus = value_minus + 1 - hue_cw, hue_ccw = bounding_hues_from_renotation([hue, code]) - hue_cw, code_cw = hue_cw - hue_ccw, code_ccw = hue_ccw + hue_code_cw, hue_code_ccw = bounding_hues_from_renotation([hue, code]) + hue_cw, code_cw = hue_code_cw + hue_ccw, code_ccw = hue_code_ccw maximum_chromas = _munsell_maximum_chromas_from_renotation() specification_for_indexes = [chroma[0] for chroma in maximum_chromas] ma_limit_mcw = maximum_chromas[ - specification_for_indexes.index((hue_cw, value_minus, code_cw)) + specification_for_indexes.index( + (hue_cw, value_minus, code_cw) # pyright: ignore + ) ][1] ma_limit_mccw = maximum_chromas[ - specification_for_indexes.index((hue_ccw, value_minus, code_ccw)) + specification_for_indexes.index( + (hue_ccw, value_minus, code_ccw) # pyright: ignore + ) ][1] if value_plus <= 9: ma_limit_pcw = maximum_chromas[ - specification_for_indexes.index((hue_cw, value_plus, code_cw)) + specification_for_indexes.index( + (hue_cw, value_plus, code_cw) # pyright: ignore + ) ][1] ma_limit_pccw = maximum_chromas[ - specification_for_indexes.index((hue_ccw, value_plus, code_ccw)) + specification_for_indexes.index( + (hue_ccw, value_plus, code_ccw) # pyright: ignore + ) ][1] max_chroma = min( [ma_limit_mcw, ma_limit_mccw, ma_limit_pcw, ma_limit_pccw] @@ -2622,7 +2621,7 @@ def maximum_chroma_from_renotation( return max_chroma -def munsell_specification_to_xy(specification: ArrayLike) -> NDArray: +def munsell_specification_to_xy(specification: ArrayLike) -> NDArrayFloat: """ Convert given *Munsell* *Colorlab* specification to *CIE xy* chromaticity coordinates by interpolating over *Munsell Renotation System* data. @@ -2634,7 +2633,7 @@ def munsell_specification_to_xy(specification: ArrayLike) -> NDArray: Returns ------- - :class:`numpy.ndarray` + :class:`numpy.NDArrayFloat` *CIE xy* chromaticity coordinates. References @@ -2666,7 +2665,7 @@ def munsell_specification_to_xy(specification: ArrayLike) -> NDArray: attest( is_integer(value), - f'"{specification}" specification value must be an integer!', + f'"{specification}" specification value must be an int!', ) value = round(value) diff --git a/colour/notation/tests/test_munsell.py b/colour/notation/tests/test_munsell.py index bc572d49a6..05beb28716 100644 --- a/colour/notation/tests/test_munsell.py +++ b/colour/notation/tests/test_munsell.py @@ -7,7 +7,7 @@ import unittest from itertools import product -from colour.hints import List, NDArray, Tuple +from colour.hints import NDArrayFloat from colour.notation.munsell import ( CCS_ILLUMINANT_MUNSELL, ) @@ -104,7 +104,7 @@ ] -def _generate_unit_tests_specifications() -> Tuple: # pragma: no cover +def _generate_unit_tests_specifications() -> tuple: # pragma: no cover """ Generate the unit tests specifications. @@ -154,7 +154,7 @@ def _generate_unit_tests_specifications() -> Tuple: # pragma: no cover return specifications, specifications_r -MUNSELL_SPECIFICATIONS: NDArray = np.array( +MUNSELL_SPECIFICATIONS: NDArrayFloat = np.array( [ [ [7.18927191, 5.34025196, 16.05861170, 3.00000000], @@ -559,7 +559,7 @@ def _generate_unit_tests_specifications() -> Tuple: # pragma: no cover ] ) -MUNSELL_GREYS_SPECIFICATIONS: NDArray = np.array( +MUNSELL_GREYS_SPECIFICATIONS: NDArrayFloat = np.array( list( zip( np.linspace(0, 10, 25)[:, None], @@ -594,7 +594,7 @@ def _generate_unit_tests_specifications() -> Tuple: # pragma: no cover ) ) -MUNSELL_EVEN_SPECIFICATIONS: NDArray = np.array( +MUNSELL_EVEN_SPECIFICATIONS: NDArrayFloat = np.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 +697,10 @@ 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 ) -MUNSELL_BOUNDING_HUES: NDArray = np.array( +MUNSELL_BOUNDING_HUES: NDArrayFloat = np.array( [ ((5.0, 3.0), (7.5, 3.0)), ((5.0, 3.0), (7.5, 3.0)), @@ -805,7 +805,7 @@ def _generate_unit_tests_specifications() -> Tuple: # pragma: no cover ] ) -MUNSELL_HUE_TO_ANGLE: NDArray = np.array( +MUNSELL_HUE_TO_ANGLE: NDArrayFloat = np.array( [ [2.5, 1, 208.750], [2.5, 2, 153.750], @@ -847,10 +847,10 @@ def _generate_unit_tests_specifications() -> Tuple: # pragma: no cover [10.0, 8, 337.500], [10.0, 9, 285.000], [10.0, 10, 247.500], - ] + ] # pyright: ignore ) -MUNSELL_HUE_TO_ASTM_HUE: NDArray = np.array( +MUNSELL_HUE_TO_ASTM_HUE: NDArrayFloat = np.array( [ [2.5, 0, 72.5], [2.5, 1, 62.5], @@ -896,10 +896,10 @@ def _generate_unit_tests_specifications() -> Tuple: # pragma: no cover [10.0, 8, 100.0], [10.0, 9, 90.0], [10.0, 10, 80.0], - ] + ] # pyright: ignore ) -MUNSELL_INTERPOLATION_METHODS: List = [ +MUNSELL_INTERPOLATION_METHODS: list = [ "Linear", "Linear", "Radial", @@ -1003,7 +1003,7 @@ def _generate_unit_tests_specifications() -> Tuple: # pragma: no cover "Radial", ] -MUNSELL_XY_FROM_RENOTATION_OVOID: List = [ +MUNSELL_XY_FROM_RENOTATION_OVOID: list = [ [0.1832, 0.4414], [0.2419, 0.3985], [0.3564, 0.3279], diff --git a/colour/phenomena/rayleigh.py b/colour/phenomena/rayleigh.py index 4c3ffbdf87..0109aff52b 100644 --- a/colour/phenomena/rayleigh.py +++ b/colour/phenomena/rayleigh.py @@ -29,7 +29,7 @@ SpectralShape, ) from colour.constants import CONSTANT_AVOGADRO -from colour.hints import Callable, FloatingOrArrayLike, FloatingOrNDArray +from colour.hints import Callable, ArrayLike, NDArrayFloat from colour.utilities import as_float, as_float_array, filter_kwargs __author__ = "Colour Developers" @@ -80,8 +80,8 @@ def air_refraction_index_Penndorf1957( - wavelength: FloatingOrArrayLike, -) -> FloatingOrNDArray: + wavelength: ArrayLike, +) -> NDArrayFloat: """ Return the air refraction index :math:`n_s` from given wavelength :math:`\\lambda` in micrometers (:math:`\\mu m`) using *Penndorf (1957)* @@ -94,7 +94,7 @@ def air_refraction_index_Penndorf1957( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Air refraction index :math:`n_s`. Examples @@ -113,8 +113,8 @@ def air_refraction_index_Penndorf1957( def air_refraction_index_Edlen1966( - wavelength: FloatingOrArrayLike, -) -> FloatingOrNDArray: + wavelength: ArrayLike, +) -> NDArrayFloat: """ Return the air refraction index :math:`n_s` from given wavelength :math:`\\lambda` in micrometers (:math:`\\mu m`) using *Edlen (1966)* @@ -127,7 +127,7 @@ def air_refraction_index_Edlen1966( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Air refraction index :math:`n_s`. Examples @@ -146,8 +146,8 @@ def air_refraction_index_Edlen1966( def air_refraction_index_Peck1972( - wavelength: FloatingOrArrayLike, -) -> FloatingOrNDArray: + wavelength: ArrayLike, +) -> NDArrayFloat: """ Return the air refraction index :math:`n_s` from given wavelength :math:`\\lambda` in micrometers (:math:`\\mu m`) using @@ -160,7 +160,7 @@ def air_refraction_index_Peck1972( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Air refraction index :math:`n_s`. Examples @@ -183,9 +183,9 @@ def air_refraction_index_Peck1972( def air_refraction_index_Bodhaine1999( - wavelength: FloatingOrArrayLike, - CO2_concentration: FloatingOrArrayLike = CONSTANT_STANDARD_CO2_CONCENTRATION, -) -> FloatingOrNDArray: + wavelength: ArrayLike, + CO2_concentration: ArrayLike = CONSTANT_STANDARD_CO2_CONCENTRATION, +) -> NDArrayFloat: """ Return the air refraction index :math:`n_s` from given wavelength :math:`\\lambda` in micrometers (:math:`\\mu m`) using @@ -200,7 +200,7 @@ def air_refraction_index_Bodhaine1999( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Air refraction index :math:`n_s`. Examples @@ -219,7 +219,7 @@ def air_refraction_index_Bodhaine1999( return as_float(n) -def N2_depolarisation(wavelength: FloatingOrArrayLike) -> FloatingOrNDArray: +def N2_depolarisation(wavelength: ArrayLike) -> NDArrayFloat: """ Return the depolarisation of nitrogen :math:`N_2` as function of wavelength :math:`\\lambda` in micrometers (:math:`\\mu m`). @@ -231,7 +231,7 @@ def N2_depolarisation(wavelength: FloatingOrArrayLike) -> FloatingOrNDArray: Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Nitrogen :math:`N_2` depolarisation. Examples @@ -247,7 +247,7 @@ def N2_depolarisation(wavelength: FloatingOrArrayLike) -> FloatingOrNDArray: return N2 -def O2_depolarisation(wavelength: FloatingOrArrayLike) -> FloatingOrNDArray: +def O2_depolarisation(wavelength: ArrayLike) -> NDArrayFloat: """ Return the depolarisation of oxygen :math:`O_2` as function of wavelength :math:`\\lambda` in micrometers (:math:`\\mu m`). @@ -259,7 +259,7 @@ def O2_depolarisation(wavelength: FloatingOrArrayLike) -> FloatingOrNDArray: Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Oxygen :math:`O_2` depolarisation. Examples @@ -277,7 +277,7 @@ def O2_depolarisation(wavelength: FloatingOrArrayLike) -> FloatingOrNDArray: return O2 -def F_air_Penndorf1957(wavelength: FloatingOrArrayLike) -> FloatingOrNDArray: +def F_air_Penndorf1957(wavelength: ArrayLike) -> NDArrayFloat: """ Return :math:`(6+3_p)/(6-7_p)`, the depolarisation term :math:`F(air)` or *King Factor* using *Penndorf (1957)* method. @@ -289,7 +289,7 @@ def F_air_Penndorf1957(wavelength: FloatingOrArrayLike) -> FloatingOrNDArray: Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Air depolarisation. Notes @@ -309,7 +309,7 @@ def F_air_Penndorf1957(wavelength: FloatingOrArrayLike) -> FloatingOrNDArray: return as_float(np.resize(np.array([1.0608]), wl.shape)) -def F_air_Young1981(wavelength: FloatingOrArrayLike) -> FloatingOrNDArray: +def F_air_Young1981(wavelength: ArrayLike) -> NDArrayFloat: """ Return :math:`(6+3_p)/(6-7_p)`, the depolarisation term :math:`F(air)` or *King Factor* using *Young (1981)* method. @@ -321,7 +321,7 @@ def F_air_Young1981(wavelength: FloatingOrArrayLike) -> FloatingOrNDArray: Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Air depolarisation. Notes @@ -341,7 +341,7 @@ def F_air_Young1981(wavelength: FloatingOrArrayLike) -> FloatingOrNDArray: return as_float(np.resize(np.array([1.0480]), wl.shape)) -def F_air_Bates1984(wavelength: FloatingOrArrayLike) -> FloatingOrNDArray: +def F_air_Bates1984(wavelength: ArrayLike) -> NDArrayFloat: """ Return :math:`(6+3_p)/(6-7_p)`, the depolarisation term :math:`F(air)` or *King Factor* as function of wavelength :math:`\\lambda` in micrometers @@ -354,7 +354,7 @@ def F_air_Bates1984(wavelength: FloatingOrArrayLike) -> FloatingOrNDArray: Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Air depolarisation. Examples @@ -376,9 +376,9 @@ def F_air_Bates1984(wavelength: FloatingOrArrayLike) -> FloatingOrNDArray: def F_air_Bodhaine1999( - wavelength: FloatingOrArrayLike, - CO2_concentration: FloatingOrArrayLike = CONSTANT_STANDARD_CO2_CONCENTRATION, -) -> FloatingOrNDArray: + wavelength: ArrayLike, + CO2_concentration: ArrayLike = CONSTANT_STANDARD_CO2_CONCENTRATION, +) -> NDArrayFloat: """ Return :math:`(6+3_p)/(6-7_p)`, the depolarisation term :math:`F(air)` or *King Factor* as function of wavelength :math:`\\lambda` in micrometers @@ -394,7 +394,7 @@ def F_air_Bodhaine1999( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Air depolarisation. Examples @@ -415,9 +415,9 @@ def F_air_Bodhaine1999( def molecular_density( - temperature: FloatingOrArrayLike = CONSTANT_STANDARD_AIR_TEMPERATURE, - avogadro_constant: FloatingOrArrayLike = CONSTANT_AVOGADRO, -) -> FloatingOrNDArray: + temperature: ArrayLike = CONSTANT_STANDARD_AIR_TEMPERATURE, + avogadro_constant: ArrayLike = CONSTANT_AVOGADRO, +) -> NDArrayFloat: """ Return the molecular density :math:`N_s` (molecules :math:`cm^{-3}`) as function of air temperature :math:`T[K]` in kelvin degrees. @@ -431,7 +431,7 @@ def molecular_density( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Molecular density :math:`N_s` (molecules :math:`cm^{-3}`). Notes @@ -459,8 +459,8 @@ def molecular_density( def mean_molecular_weights( - CO2_concentration: FloatingOrArrayLike = CONSTANT_STANDARD_CO2_CONCENTRATION, -) -> FloatingOrNDArray: + CO2_concentration: ArrayLike = CONSTANT_STANDARD_CO2_CONCENTRATION, +) -> NDArrayFloat: """ Return the mean molecular weights :math:`m_a` for dry air as function of :math:`CO_2` concentration in parts per million (ppm). @@ -472,7 +472,7 @@ def mean_molecular_weights( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Mean molecular weights :math:`m_a` for dry air. Examples @@ -490,13 +490,13 @@ def mean_molecular_weights( def gravity_List1968( - latitude: FloatingOrArrayLike = CONSTANT_DEFAULT_LATITUDE, - altitude: FloatingOrArrayLike = CONSTANT_DEFAULT_ALTITUDE, -) -> FloatingOrNDArray: + latitude: ArrayLike = CONSTANT_DEFAULT_LATITUDE, + altitude: ArrayLike = CONSTANT_DEFAULT_ALTITUDE, +) -> NDArrayFloat: """ Return the gravity :math:`g` in :math:`cm/s_2` (gal) representative of the mass-weighted column of air molecules above the site of given latitude and - altitude using *List (1968)* method. + altitude using *list (1968)* method. Parameters ---------- @@ -507,7 +507,7 @@ def gravity_List1968( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Gravity :math:`g` in :math:`cm/s_2` (gal). Examples @@ -542,13 +542,13 @@ def gravity_List1968( def scattering_cross_section( - wavelength: FloatingOrArrayLike, - CO2_concentration: FloatingOrArrayLike = CONSTANT_STANDARD_CO2_CONCENTRATION, - temperature: FloatingOrArrayLike = CONSTANT_STANDARD_AIR_TEMPERATURE, - avogadro_constant: FloatingOrArrayLike = CONSTANT_AVOGADRO, + wavelength: ArrayLike, + CO2_concentration: ArrayLike = CONSTANT_STANDARD_CO2_CONCENTRATION, + temperature: ArrayLike = CONSTANT_STANDARD_AIR_TEMPERATURE, + avogadro_constant: ArrayLike = CONSTANT_AVOGADRO, n_s_function: Callable = air_refraction_index_Bodhaine1999, F_air_function: Callable = F_air_Bodhaine1999, -) -> FloatingOrNDArray: +) -> NDArrayFloat: """ Return the scattering cross section per molecule :math:`\\sigma` of dry air as function of wavelength :math:`\\lambda` in centimeters (cm) using @@ -573,7 +573,7 @@ def scattering_cross_section( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Scattering cross section per molecule :math:`\\sigma` of dry air. Warnings @@ -620,16 +620,16 @@ def scattering_cross_section( def rayleigh_optical_depth( - wavelength: FloatingOrArrayLike, - CO2_concentration: FloatingOrArrayLike = CONSTANT_STANDARD_CO2_CONCENTRATION, - temperature: FloatingOrArrayLike = CONSTANT_STANDARD_AIR_TEMPERATURE, - pressure: FloatingOrArrayLike = CONSTANT_AVERAGE_PRESSURE_MEAN_SEA_LEVEL, - latitude: FloatingOrArrayLike = CONSTANT_DEFAULT_LATITUDE, - altitude: FloatingOrArrayLike = CONSTANT_DEFAULT_ALTITUDE, - avogadro_constant: FloatingOrArrayLike = CONSTANT_AVOGADRO, + wavelength: ArrayLike, + CO2_concentration: ArrayLike = CONSTANT_STANDARD_CO2_CONCENTRATION, + temperature: ArrayLike = CONSTANT_STANDARD_AIR_TEMPERATURE, + pressure: ArrayLike = CONSTANT_AVERAGE_PRESSURE_MEAN_SEA_LEVEL, + latitude: ArrayLike = CONSTANT_DEFAULT_LATITUDE, + altitude: ArrayLike = CONSTANT_DEFAULT_ALTITUDE, + avogadro_constant: ArrayLike = CONSTANT_AVOGADRO, n_s_function: Callable = air_refraction_index_Bodhaine1999, F_air_function: Callable = F_air_Bodhaine1999, -) -> FloatingOrNDArray: +) -> NDArrayFloat: """ Return the *Rayleigh* optical depth :math:`T_r(\\lambda)` as function of wavelength :math:`\\lambda` in centimeters (cm). @@ -658,7 +658,7 @@ def rayleigh_optical_depth( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` *Rayleigh* optical depth :math:`T_r(\\lambda)`. Warnings @@ -682,6 +682,7 @@ def rayleigh_optical_depth( pressure = as_float_array(pressure) latitude = as_float_array(latitude) altitude = as_float_array(altitude) + avogadro_constant = as_float_array(avogadro_constant) # Conversion from pascal to dyne/cm2. P = as_float_array(pressure * 10) @@ -707,12 +708,12 @@ def rayleigh_optical_depth( def sd_rayleigh_scattering( shape: SpectralShape = SPECTRAL_SHAPE_DEFAULT, - CO2_concentration: FloatingOrArrayLike = CONSTANT_STANDARD_CO2_CONCENTRATION, - temperature: FloatingOrArrayLike = CONSTANT_STANDARD_AIR_TEMPERATURE, - pressure: FloatingOrArrayLike = CONSTANT_AVERAGE_PRESSURE_MEAN_SEA_LEVEL, - latitude: FloatingOrArrayLike = CONSTANT_DEFAULT_LATITUDE, - altitude: FloatingOrArrayLike = CONSTANT_DEFAULT_ALTITUDE, - avogadro_constant: FloatingOrArrayLike = CONSTANT_AVOGADRO, + CO2_concentration: ArrayLike = CONSTANT_STANDARD_CO2_CONCENTRATION, + temperature: ArrayLike = CONSTANT_STANDARD_AIR_TEMPERATURE, + pressure: ArrayLike = CONSTANT_AVERAGE_PRESSURE_MEAN_SEA_LEVEL, + latitude: ArrayLike = CONSTANT_DEFAULT_LATITUDE, + altitude: ArrayLike = CONSTANT_DEFAULT_ALTITUDE, + avogadro_constant: ArrayLike = CONSTANT_AVOGADRO, n_s_function: Callable = air_refraction_index_Bodhaine1999, F_air_function: Callable = F_air_Bodhaine1999, ) -> SpectralDistribution: diff --git a/colour/phenomena/tests/test_rayleigh.py b/colour/phenomena/tests/test_rayleigh.py index 6f42b6c538..fc2a4aed1d 100644 --- a/colour/phenomena/tests/test_rayleigh.py +++ b/colour/phenomena/tests/test_rayleigh.py @@ -6,7 +6,6 @@ import numpy as np import unittest -from colour.hints import Tuple from colour.phenomena.rayleigh import ( air_refraction_index_Penndorf1957, air_refraction_index_Edlen1966, @@ -56,7 +55,7 @@ "TestSdRayleighScattering", ] -DATA_SD_RAYLEIGH_SCATTERING: Tuple = ( +DATA_SD_RAYLEIGH_SCATTERING: tuple = ( 0.59910134, 0.59217069, 0.58534101, diff --git a/colour/plotting/blindness.py b/colour/plotting/blindness.py index 61b8a5bfcd..611ecdd7f1 100644 --- a/colour/plotting/blindness.py +++ b/colour/plotting/blindness.py @@ -16,11 +16,8 @@ from colour.hints import ( Any, ArrayLike, - Dict, - Floating, Literal, Optional, - Tuple, Union, cast, ) @@ -45,10 +42,10 @@ def plot_cvd_simulation_Machado2009( deficiency: Union[ Literal["Deuteranomaly", "Protanomaly", "Tritanomaly"], str ] = "Protanomaly", - severity: Floating = 0.5, + severity: float = 0.5, M_a: Optional[ArrayLike] = None, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> tuple[plt.Figure, plt.Axes]: """ Perform colour vision deficiency simulation on given *RGB* colourspace array using *Machado et al. (2009)* model. @@ -97,7 +94,7 @@ def plot_cvd_simulation_Machado2009( ArrayLike, optional(M_a, matrix_cvd_Machado2009(deficiency, severity)) ) - settings: Dict[str, Any] = { + settings: dict[str, Any] = { "text_kwargs": { "text": f"Deficiency: {deficiency} - Severity: {severity}" } diff --git a/colour/plotting/characterisation.py b/colour/plotting/characterisation.py index 2529a93391..1c99878aeb 100644 --- a/colour/plotting/characterisation.py +++ b/colour/plotting/characterisation.py @@ -13,7 +13,7 @@ import numpy as np import matplotlib.pyplot as plt -from colour.hints import Any, Dict, Sequence, Tuple, Union +from colour.hints import Any, Sequence, Union from colour.characterisation import ColourChecker from colour.models import xyY_to_XYZ from colour.plotting import ( @@ -55,7 +55,7 @@ def plot_single_colour_checker( ColourChecker, str ] = "ColorChecker24 - After November 2014", **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> tuple[plt.Figure, plt.Axes]: """ Plot given colour checker. @@ -106,7 +106,7 @@ def plot_multi_colour_checkers( ColourChecker, str, Sequence[Union[ColourChecker, str]] ], **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> tuple[plt.Figure, plt.Axes]: """ Plot and compares given colour checkers. @@ -180,7 +180,7 @@ def plot_multi_colour_checkers( spacing = 0.25 columns = 6 - settings: Dict[str, Any] = { + settings: dict[str, Any] = { "axes": axes, "width": width, "height": height, diff --git a/colour/plotting/colorimetry.py b/colour/plotting/colorimetry.py index edbe6ae42a..bfd3f4319b 100644 --- a/colour/plotting/colorimetry.py +++ b/colour/plotting/colorimetry.py @@ -53,15 +53,9 @@ ) from colour.hints import ( Any, - Boolean, Callable, - Dict, - Floating, - List, - NDArray, Optional, Sequence, - Tuple, Union, cast, ) @@ -118,11 +112,11 @@ def plot_single_sd( str, Sequence[Union[MultiSpectralDistributions, str]], ] = "CIE 1931 2 Degree Standard Observer", - out_of_gamut_clipping: Boolean = True, - modulate_colours_with_sd_amplitude: Boolean = False, - equalize_sd_amplitude: Boolean = False, + out_of_gamut_clipping: bool = True, + modulate_colours_with_sd_amplitude: bool = False, + equalize_sd_amplitude: bool = False, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> tuple[plt.Figure, plt.Axes]: """ Plot given spectral distribution. @@ -189,7 +183,7 @@ def plot_single_sd( MultiSpectralDistributions, first_item(filter_cmfs(cmfs).values()) ) - sd = cast(SpectralDistribution, sd.copy()) + sd = sd.copy() sd.interpolator = LinearInterpolator wavelengths = cmfs.wavelengths[ np.logical_and( @@ -214,7 +208,7 @@ def plot_single_sd( if modulate_colours_with_sd_amplitude: with sdiv_mode(): - RGB *= cast(NDArray, sdiv(values, np.max(values)))[..., None] + RGB *= sdiv(values, np.max(values))[..., None] RGB = CONSTANTS_COLOUR_STYLE.colour.colourspace.cctf_encoding(RGB) @@ -258,7 +252,7 @@ def plot_single_sd( zorder=CONSTANTS_COLOUR_STYLE.zorder.midground_line, ) - settings: Dict[str, Any] = { + settings: dict[str, Any] = { "axes": axes, "bounding_box": (x_min, x_max, y_min, y_max), "title": f"{sd.display_name} - {cmfs.display_name}", @@ -276,9 +270,9 @@ def plot_multi_sds( Sequence[Union[SpectralDistribution, MultiSpectralDistributions]], MultiSpectralDistributions, ], - plot_kwargs: Optional[Union[Dict, List[Dict]]] = None, + plot_kwargs: Optional[Union[dict, list[dict]]] = None, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> tuple[plt.Figure, plt.Axes]: """ Plot given spectral distributions. @@ -430,7 +424,7 @@ def plot_multi_sds( min(y_limit_min), max(y_limit_max) + np.max(y_limit_max) * 0.05, ) - settings: Dict[str, Any] = { + settings: dict[str, Any] = { "axes": axes, "bounding_box": bounding_box, "legend": True, @@ -450,7 +444,7 @@ def plot_single_cmfs( Sequence[Union[MultiSpectralDistributions, str]], ] = "CIE 1931 2 Degree Standard Observer", **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> tuple[plt.Figure, plt.Axes]: """ Plot given colour matching functions. @@ -488,7 +482,7 @@ def plot_single_cmfs( MultiSpectralDistributions, first_item(filter_cmfs(cmfs).values()) ) - settings: Dict[str, Any] = { + settings: dict[str, Any] = { "title": f"{cmfs.display_name} - Colour Matching Functions" } settings.update(kwargs) @@ -504,7 +498,7 @@ def plot_multi_cmfs( Sequence[Union[MultiSpectralDistributions, str]], ], **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> tuple[plt.Figure, plt.Axes]: """ Plot given colour matching functions. @@ -541,8 +535,8 @@ def plot_multi_cmfs( """ cmfs = cast( - List[MultiSpectralDistributions], list(filter_cmfs(cmfs).values()) - ) + list[MultiSpectralDistributions], list(filter_cmfs(cmfs).values()) + ) # pyright: ignore _figure, axes = artist(**kwargs) @@ -583,7 +577,7 @@ def plot_multi_cmfs( cmfs_display_names = ", ".join([cmfs_i.display_name for cmfs_i in cmfs]) title = f"{cmfs_display_names} - Colour Matching Functions" - settings: Dict[str, Any] = { + settings: dict[str, Any] = { "axes": axes, "bounding_box": bounding_box, "legend": True, @@ -605,7 +599,7 @@ def plot_single_illuminant_sd( Sequence[Union[MultiSpectralDistributions, str]], ] = "CIE 1931 2 Degree Standard Observer", **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> tuple[plt.Figure, plt.Axes]: """ Plot given single illuminant spectral distribution. @@ -652,9 +646,12 @@ def plot_single_illuminant_sd( title = f"Illuminant {illuminant} - {cmfs.display_name}" - illuminant = first_item(filter_illuminants(illuminant).values()) + illuminant = cast( + SpectralDistribution, + first_item(filter_illuminants(illuminant).values()), + ) - settings: Dict[str, Any] = {"title": title, "y_label": "Relative Power"} + settings: dict[str, Any] = {"title": title, "y_label": "Relative Power"} settings.update(kwargs) return plot_single_sd(illuminant, **settings) @@ -666,7 +663,7 @@ def plot_multi_illuminant_sds( SpectralDistribution, str, Sequence[Union[SpectralDistribution, str]] ], **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> tuple[plt.Figure, plt.Axes]: """ Plot given illuminants spectral distributions. @@ -711,16 +708,16 @@ def plot_multi_illuminant_sds( kwargs["plot_kwargs"][i]["illuminant"] = SD_E illuminants = cast( - List[SpectralDistribution], + list[SpectralDistribution], list(filter_illuminants(illuminants).values()), - ) + ) # pyright: ignore illuminant_display_names = ", ".join( [illuminant.display_name for illuminant in illuminants] ) title = f"{illuminant_display_names} - Illuminants Spectral Distributions" - settings: Dict[str, Any] = {"title": title, "y_label": "Relative Power"} + settings: dict[str, Any] = {"title": title, "y_label": "Relative Power"} settings.update(kwargs) return plot_multi_sds(illuminants, **settings) @@ -738,9 +735,9 @@ def plot_visible_spectrum( str, Sequence[Union[MultiSpectralDistributions, str]], ] = "CIE 1931 2 Degree Standard Observer", - out_of_gamut_clipping: Boolean = True, + out_of_gamut_clipping: bool = True, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> tuple[plt.Figure, plt.Axes]: """ Plot the visible colours spectrum using given standard observer *CIE XYZ* colour matching functions. @@ -789,7 +786,7 @@ def plot_visible_spectrum( bounding_box = (min(cmfs.wavelengths), max(cmfs.wavelengths), 0, 1) - settings: Dict[str, Any] = {"bounding_box": bounding_box, "y_label": None} + settings: dict[str, Any] = {"bounding_box": bounding_box, "y_label": None} settings.update(kwargs) settings["standalone"] = False @@ -817,7 +814,7 @@ def plot_visible_spectrum( @override_style() def plot_single_lightness_function( function: Union[Callable, str], **kwargs: Any -) -> Tuple[plt.Figure, plt.Axes]: +) -> tuple[plt.Figure, plt.Axes]: """ Plot given *Lightness* function. @@ -850,7 +847,7 @@ def plot_single_lightness_function( :alt: plot_single_lightness_function """ - settings: Dict[str, Any] = {"title": f"{function} - Lightness Function"} + settings: dict[str, Any] = {"title": f"{function} - Lightness Function"} settings.update(kwargs) return plot_multi_lightness_functions((function,), **settings) @@ -860,7 +857,7 @@ def plot_single_lightness_function( def plot_multi_lightness_functions( functions: Union[Callable, str, Sequence[Union[Callable, str]]], **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> tuple[plt.Figure, plt.Axes]: """ Plot given *Lightness* functions. @@ -897,7 +894,7 @@ def plot_multi_lightness_functions( functions_filtered = filter_passthrough(LIGHTNESS_METHODS, functions) - settings: Dict[str, Any] = { + settings: dict[str, Any] = { "bounding_box": (0, 1, 0, 1), "legend": True, "title": f"{', '.join(functions_filtered)} - Lightness Functions", @@ -913,7 +910,7 @@ def plot_multi_lightness_functions( @override_style() def plot_single_luminance_function( function: Union[Callable, str], **kwargs: Any -) -> Tuple[plt.Figure, plt.Axes]: +) -> tuple[plt.Figure, plt.Axes]: """ Plot given *Luminance* function. @@ -945,7 +942,7 @@ def plot_single_luminance_function( :alt: plot_single_luminance_function """ - settings: Dict[str, Any] = {"title": f"{function} - Luminance Function"} + settings: dict[str, Any] = {"title": f"{function} - Luminance Function"} settings.update(kwargs) return plot_multi_luminance_functions((function,), **settings) @@ -955,7 +952,7 @@ def plot_single_luminance_function( def plot_multi_luminance_functions( functions: Union[Callable, str, Sequence[Union[Callable, str]]], **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> tuple[plt.Figure, plt.Axes]: """ Plot given *Luminance* functions. @@ -992,7 +989,7 @@ def plot_multi_luminance_functions( functions_filtered = filter_passthrough(LUMINANCE_METHODS, functions) - settings: Dict[str, Any] = { + settings: dict[str, Any] = { "bounding_box": (0, 1, 0, 1), "legend": True, "title": f"{', '.join(functions_filtered)} - Luminance Functions", @@ -1007,7 +1004,7 @@ def plot_multi_luminance_functions( @override_style() def plot_blackbody_spectral_radiance( - temperature: Floating = 3500, + temperature: float = 3500, cmfs: Union[ MultiSpectralDistributions, str, @@ -1015,7 +1012,7 @@ def plot_blackbody_spectral_radiance( ] = "CIE 1931 2 Degree Standard Observer", blackbody: str = "VY Canis Major", **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> tuple[plt.Figure, plt.Axes]: """ Plot given blackbody spectral radiance. @@ -1065,7 +1062,7 @@ def plot_blackbody_spectral_radiance( sd = sd_blackbody(temperature, cmfs.shape) axes = figure.add_subplot(211) - settings: Dict[str, Any] = { + settings: dict[str, Any] = { "axes": axes, "title": f"{blackbody} - Spectral Radiance", "y_label": "W / (sr m$^2$) / m", @@ -1116,7 +1113,7 @@ def plot_blackbody_colours( Sequence[Union[MultiSpectralDistributions, str]], ] = "CIE 1931 2 Degree Standard Observer", **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> tuple[plt.Figure, plt.Axes]: """ Plot blackbody colours. @@ -1182,7 +1179,7 @@ def plot_blackbody_colours( zorder=CONSTANTS_COLOUR_STYLE.zorder.background_polygon, ) - settings: Dict[str, Any] = { + settings: dict[str, Any] = { "axes": axes, "bounding_box": (x_min, x_max, y_min, y_max), "title": "Blackbody Colours", diff --git a/colour/plotting/common.py b/colour/plotting/common.py index a5adc5a0f7..f3aef75a78 100644 --- a/colour/plotting/common.py +++ b/colour/plotting/common.py @@ -47,18 +47,12 @@ from colour.hints import ( Any, ArrayLike, - Boolean, Callable, - Dict, - Floating, - Integer, - List, Literal, Mapping, - NDArray, + NDArrayFloat, Optional, Sequence, - Tuple, TypedDict, Union, cast, @@ -207,7 +201,7 @@ """Annotation arrow settings used across the plotting sub-package.""" -def colour_style(use_style: Boolean = True) -> Dict: +def colour_style(use_style: bool = True) -> dict: """ Return *Colour* plotting style. @@ -360,8 +354,8 @@ def XYZ_to_plotting_colourspace( str, ] ] = "CAT02", - apply_cctf_encoding: Boolean = True, -) -> NDArray: + apply_cctf_encoding: bool = True, +) -> NDArrayFloat: """ Convert from *CIE XYZ* tristimulus values to the default plotting colourspace. @@ -468,10 +462,10 @@ class KwargsArtist(TypedDict): """ axes: plt.Axes - uniform: Boolean + uniform: bool -def artist(**kwargs: Union[KwargsArtist, Any]) -> Tuple[plt.Figure, plt.Axes]: +def artist(**kwargs: Union[KwargsArtist, Any]) -> tuple[plt.Figure, plt.Axes]: """ Return the current figure and its axes or creates a new one. @@ -521,12 +515,12 @@ class KwargsCamera(TypedDict): figure: plt.Figure axes: plt.Axes - azimuth: Optional[Floating] - elevation: Optional[Floating] + azimuth: Optional[float] + elevation: Optional[float] camera_aspect: Union[Literal["equal"], str] -def camera(**kwargs: Union[KwargsCamera, Any]) -> Tuple[plt.Figure, plt.Axes]: +def camera(**kwargs: Union[KwargsCamera, Any]) -> tuple[plt.Figure, plt.Axes]: """ Set the camera settings. @@ -607,23 +601,23 @@ class KwargsRender(TypedDict): figure: plt.Figure axes: plt.Axes filename: str - standalone: Boolean - aspect: Union[Literal["auto", "equal"], Floating] - axes_visible: Boolean + standalone: bool + aspect: Union[Literal["auto", "equal"], float] + axes_visible: bool bounding_box: ArrayLike - tight_layout: Boolean - legend: Boolean - legend_columns: Integer - transparent_background: Boolean + tight_layout: bool + legend: bool + legend_columns: int + transparent_background: bool title: str - wrap_title: Boolean + wrap_title: bool x_label: str y_label: str - x_ticker: Boolean - y_ticker: Boolean + x_ticker: bool + y_ticker: bool -def render(**kwargs: Union[KwargsRender, Any]) -> Tuple[plt.Figure, plt.Axes]: +def render(**kwargs: Union[KwargsRender, Any]) -> tuple[plt.Figure, plt.Axes]: """ Render the current figure while adjusting various settings such as the bounding box, the title or background transparency. @@ -703,10 +697,10 @@ def label_rectangles( labels: Sequence[str], rectangles: Sequence[Patch], rotation: Union[Literal["horizontal", "vertical"], str] = "vertical", - text_size: Floating = 10, + text_size: float = 10, offset: Optional[ArrayLike] = None, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> tuple[plt.Figure, plt.Axes]: """ Add labels above given rectangles. @@ -773,7 +767,7 @@ def label_rectangles( return figure, axes -def uniform_axes3d(**kwargs: Any) -> Tuple[plt.Figure, plt.Axes]: +def uniform_axes3d(**kwargs: Any) -> tuple[plt.Figure, plt.Axes]: """ Set equal aspect ratio to given 3d axes. @@ -816,8 +810,8 @@ def uniform_axes3d(**kwargs: Any) -> Tuple[plt.Figure, plt.Axes]: def filter_passthrough( mapping: Mapping, filterers: Union[Any, str, Sequence[Union[Any, str]]], - allow_non_siblings: Boolean = True, -) -> Dict: + allow_non_siblings: bool = True, +) -> dict: """ Return mapping objects matching given filterers while passing through class instances whose type is one of the mapping element types. @@ -891,11 +885,11 @@ class instance, then the lower, slugified and canonical keys are also elif not isinstance(filterers, (list, tuple)): filterers = [filterers] - string_filterers: List[str] = [ + string_filterers: list[str] = [ cast(str, filterer) for filterer in filterers if is_string(filterer) ] - object_filterers: List[Any] = [ + object_filterers: list[Any] = [ filterer for filterer in filterers if is_sibling(filterer, mapping) ] @@ -939,8 +933,8 @@ def filter_RGB_colourspaces( filterers: Union[ RGB_Colourspace, str, Sequence[Union[RGB_Colourspace, str]] ], - allow_non_siblings: Boolean = True, -) -> Dict[str, RGB_Colourspace]: + allow_non_siblings: bool = True, +) -> dict[str, RGB_Colourspace]: """ Return the *RGB* colourspaces matching given filterers. @@ -970,8 +964,8 @@ def filter_cmfs( str, Sequence[Union[MultiSpectralDistributions, str]], ], - allow_non_siblings: Boolean = True, -) -> Dict[str, MultiSpectralDistributions]: + allow_non_siblings: bool = True, +) -> dict[str, MultiSpectralDistributions]: """ Return the colour matching functions matching given filterers. @@ -1001,8 +995,8 @@ def filter_illuminants( filterers: Union[ SpectralDistribution, str, Sequence[Union[SpectralDistribution, str]] ], - allow_non_siblings: Boolean = True, -) -> Dict[str, SpectralDistribution]: + allow_non_siblings: bool = True, +) -> dict[str, SpectralDistribution]: """ Return the illuminants matching given filterers. @@ -1038,8 +1032,8 @@ def filter_illuminants( def filter_colour_checkers( filterers: Union[ColourChecker, str, Sequence[Union[ColourChecker, str]]], - allow_non_siblings: Boolean = True, -) -> Dict[str, ColourChecker]: + allow_non_siblings: bool = True, +) -> dict[str, ColourChecker]: """ Return the colour checkers matching given filterers. @@ -1066,9 +1060,9 @@ def filter_colour_checkers( def update_settings_collection( - settings_collection: Union[Dict, List[Dict]], - keyword_arguments: Union[Dict, List[Dict]], - expected_count: Integer, + settings_collection: Union[dict, list[dict]], + keyword_arguments: Union[dict, list[dict]], + expected_count: int, ): """ Update given settings collection, *in-place*, with given keyword arguments @@ -1122,7 +1116,7 @@ def update_settings_collection( ) def plot_single_colour_swatch( colour_swatch: Union[ArrayLike, ColourSwatch], **kwargs: Any -) -> Tuple[plt.Figure, plt.Axes]: +) -> tuple[plt.Figure, plt.Axes]: """ Plot given colour swatch. @@ -1170,18 +1164,18 @@ def plot_single_colour_swatch( ) def plot_multi_colour_swatches( colour_swatches: Sequence[Union[ArrayLike, ColourSwatch]], - width: Floating = 1, - height: Floating = 1, - spacing: Floating = 0, - columns: Optional[Integer] = None, + width: float = 1, + height: float = 1, + spacing: float = 0, + columns: Optional[int] = None, direction: Union[Literal["+y", "-y"], str] = "+y", - text_kwargs: Optional[Dict] = None, + text_kwargs: Optional[dict] = None, background_colour: ArrayLike = (1.0, 1.0, 1.0), compare_swatches: Optional[ Union[Literal["Diagonal", "Stacked"], str] ] = None, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> tuple[plt.Figure, plt.Axes]: """ Plot given colours swatches. @@ -1264,7 +1258,7 @@ def plot_multi_colour_swatches( ): colour_swatches_converted.append(ColourSwatch(colour_swatch)) else: - colour_swatches_converted = cast(List[ColourSwatch], colour_swatches) + colour_swatches_converted = cast(list[ColourSwatch], colour_swatches) colour_swatches = colour_swatches_converted @@ -1290,8 +1284,8 @@ def plot_multi_colour_swatches( text_settings.update(text_kwargs) text_offset = text_settings.pop("offset") - offset_X: Floating = 0 - offset_Y: Floating = 0 + offset_X: float = 0 + offset_Y: float = 0 x_min, x_max, y_min, y_max = 0, width, 0, height y = 1 if direction == "+y" else -1 for i, colour_swatch in enumerate(colour_swatches_reference): @@ -1369,7 +1363,7 @@ def plot_multi_colour_swatches( y_min + spacing, ] - settings: Dict[str, Any] = { + settings: dict[str, Any] = { "axes": axes, "bounding_box": bounding_box, "aspect": "equal", @@ -1383,11 +1377,11 @@ def plot_multi_colour_swatches( def plot_single_function( function: Callable, samples: Optional[ArrayLike] = None, - log_x: Optional[Integer] = None, - log_y: Optional[Integer] = None, - plot_kwargs: Optional[Union[Dict, List[Dict]]] = None, + log_x: Optional[int] = None, + log_y: Optional[int] = None, + plot_kwargs: Optional[Union[dict, list[dict]]] = None, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> tuple[plt.Figure, plt.Axes]: """ Plot given function. @@ -1437,7 +1431,7 @@ def plot_single_function( except AttributeError: name = "Unnamed" - settings: Dict[str, Any] = { + settings: dict[str, Any] = { "title": f"{name} - Function", "legend": False, } @@ -1450,13 +1444,13 @@ def plot_single_function( @override_style() def plot_multi_functions( - functions: Dict[str, Callable], + functions: dict[str, Callable], samples: Optional[ArrayLike] = None, - log_x: Optional[Integer] = None, - log_y: Optional[Integer] = None, - plot_kwargs: Optional[Union[Dict, List[Dict]]] = None, + log_x: Optional[int] = None, + log_y: Optional[int] = None, + plot_kwargs: Optional[Union[dict, list[dict]]] = None, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> tuple[plt.Figure, plt.Axes]: """ Plot given functions. @@ -1506,7 +1500,7 @@ def plot_multi_functions( :alt: plot_multi_functions """ - settings: Dict[str, Any] = dict(kwargs) + settings: dict[str, Any] = dict(kwargs) _figure, axes = artist(**settings) @@ -1587,10 +1581,10 @@ def plot_multi_functions( @override_style() def plot_image( image: ArrayLike, - imshow_kwargs: Optional[Dict] = None, - text_kwargs: Optional[Dict] = None, + imshow_kwargs: Optional[dict] = None, + text_kwargs: Optional[dict] = None, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> tuple[plt.Figure, plt.Axes]: """ Plot given image. @@ -1675,7 +1669,7 @@ def plot_image( **text_settings, ) - settings: Dict[str, Any] = { + settings: dict[str, Any] = { "axes": axes, "axes_visible": False, } diff --git a/colour/plotting/corresponding.py b/colour/plotting/corresponding.py index ba2485eb85..f6355ca790 100644 --- a/colour/plotting/corresponding.py +++ b/colour/plotting/corresponding.py @@ -15,7 +15,7 @@ CorrespondingColourDataset, corresponding_chromaticities_prediction, ) -from colour.hints import Any, Dict, Literal, Optional, Tuple, Union +from colour.hints import Any, Literal, Optional, Union, cast from colour.plotting import ( CONSTANTS_COLOUR_STYLE, artist, @@ -52,9 +52,9 @@ def plot_corresponding_chromaticities_prediction( ], str, ] = "Von Kries", - corresponding_chromaticities_prediction_kwargs: Optional[Dict] = None, + corresponding_chromaticities_prediction_kwargs: Optional[dict] = None, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> tuple[plt.Figure, plt.Axes]: """ Plot given chromatic adaptation model corresponding chromaticities prediction. @@ -98,7 +98,7 @@ def plot_corresponding_chromaticities_prediction( if corresponding_chromaticities_prediction_kwargs is None: corresponding_chromaticities_prediction_kwargs = {} - settings: Dict[str, Any] = {"uniform": True} + settings: dict[str, Any] = {"uniform": True} settings.update(kwargs) _figure, axes = artist(**settings) @@ -106,7 +106,7 @@ def plot_corresponding_chromaticities_prediction( name = ( f"Experiment {experiment}" if is_numeric(experiment) - else experiment.name # type: ignore[union-attr] + else cast(CorrespondingColourDataset, experiment).name ) title = ( f"Corresponding Chromaticities Prediction - {model} - {name} - " diff --git a/colour/plotting/datasets/astm_g_173.py b/colour/plotting/datasets/astm_g_173.py index 96c91ab9e7..51179962cf 100644 --- a/colour/plotting/datasets/astm_g_173.py +++ b/colour/plotting/datasets/astm_g_173.py @@ -17,7 +17,6 @@ from colour.algebra import LinearInterpolator from colour.colorimetry import SpectralDistribution -from colour.hints import Dict __author__ = "Colour Developers" __copyright__ = "Copyright 2013 Colour Developers" @@ -36,7 +35,7 @@ ] -DATA_ASTMG173_ETR: Dict = { +DATA_ASTMG173_ETR: dict = { 280.0: 8.2000e-02, 280.5: 9.9000e-02, 281.0: 1.5000e-01, @@ -2041,7 +2040,7 @@ 4000.0: 8.6800e-03, } -DATA_ASTMG173_GLOBAL_TILT: Dict = { +DATA_ASTMG173_GLOBAL_TILT: dict = { 280.0: 4.7309e-23, 280.5: 1.2307e-21, 281.0: 5.6895e-21, @@ -4046,7 +4045,7 @@ 4000.0: 7.1043e-03, } -DATA_ASTMG173_DIRECT_CIRCUMSOLAR: Dict = { +DATA_ASTMG173_DIRECT_CIRCUMSOLAR: dict = { 280.0: 2.5361e-26, 280.5: 1.0917e-24, 281.0: 6.1253e-24, diff --git a/colour/plotting/diagrams.py b/colour/plotting/diagrams.py index 698514e236..11b3f7eb98 100644 --- a/colour/plotting/diagrams.py +++ b/colour/plotting/diagrams.py @@ -31,17 +31,11 @@ from colour.hints import ( Any, ArrayLike, - Boolean, Callable, - Dict, - Floating, - Integer, - List, Literal, - NDArray, + NDArrayFloat, Optional, Sequence, - Tuple, Union, cast, ) @@ -107,13 +101,13 @@ def plot_spectral_locus( Sequence[Union[MultiSpectralDistributions, str]], ] = "CIE 1931 2 Degree Standard Observer", spectral_locus_colours: Optional[Union[ArrayLike, str]] = None, - spectral_locus_opacity: Floating = 1, + spectral_locus_opacity: float = 1, spectral_locus_labels: Optional[Sequence] = None, method: Union[ Literal["CIE 1931", "CIE 1960 UCS", "CIE 1976 UCS"], str ] = "CIE 1931", **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> tuple[plt.Figure, plt.Axes]: """ Plot the *Spectral Locus* according to given method. @@ -165,7 +159,7 @@ def plot_spectral_locus( spectral_locus_colours, CONSTANTS_COLOUR_STYLE.colour.dark ) - settings: Dict[str, Any] = {"uniform": True} + settings: dict[str, Any] = {"uniform": True} settings.update(kwargs) _figure, axes = artist(**settings) @@ -179,94 +173,86 @@ def plot_spectral_locus( wavelengths = list(cmfs.wavelengths) equal_energy = np.array([1 / 3] * 2) + labels = tuple() if method == "cie 1931": ij = XYZ_to_xy(cmfs.values, illuminant) - labels = cast( - Tuple, - optional( - spectral_locus_labels, - ( - 390, - 460, - 470, - 480, - 490, - 500, - 510, - 520, - 540, - 560, - 580, - 600, - 620, - 700, - ), + labels = optional( + spectral_locus_labels, + ( + 390, + 460, + 470, + 480, + 490, + 500, + 510, + 520, + 540, + 560, + 580, + 600, + 620, + 700, ), ) elif method == "cie 1960 ucs": ij = UCS_to_uv(XYZ_to_UCS(cmfs.values)) - labels = cast( - Tuple, - optional( - spectral_locus_labels, - ( - 420, - 440, - 450, - 460, - 470, - 480, - 490, - 500, - 510, - 520, - 530, - 540, - 550, - 560, - 570, - 580, - 590, - 600, - 610, - 620, - 630, - 645, - 680, - ), + labels = optional( + spectral_locus_labels, + ( + 420, + 440, + 450, + 460, + 470, + 480, + 490, + 500, + 510, + 520, + 530, + 540, + 550, + 560, + 570, + 580, + 590, + 600, + 610, + 620, + 630, + 645, + 680, ), ) elif method == "cie 1976 ucs": ij = Luv_to_uv(XYZ_to_Luv(cmfs.values, illuminant), illuminant) - labels = cast( - Tuple, - optional( - spectral_locus_labels, - ( - 420, - 440, - 450, - 460, - 470, - 480, - 490, - 500, - 510, - 520, - 530, - 540, - 550, - 560, - 570, - 580, - 590, - 600, - 610, - 620, - 630, - 645, - 680, - ), + labels = optional( + spectral_locus_labels, + ( + 420, + 440, + 450, + 460, + 470, + 480, + 490, + 500, + 510, + 520, + 530, + 540, + 550, + 560, + 570, + 580, + 590, + 600, + 610, + 620, + 630, + 645, + 680, ), ) @@ -347,7 +333,7 @@ def plot_spectral_locus( label_colour = ( spectral_locus_colours if is_string(spectral_locus_colours) - else spectral_locus_colours[index] # type: ignore[index] + else cast(NDArrayFloat, spectral_locus_colours)[index] ) axes.plot( (i, i + normal[0] * 0.75), @@ -385,9 +371,9 @@ def plot_spectral_locus( @override_style() def plot_chromaticity_diagram_colours( - samples: Integer = 256, + samples: int = 256, diagram_colours: Optional[Union[ArrayLike, str]] = None, - diagram_opacity: Floating = 1, + diagram_opacity: float = 1, diagram_clipping_path: Optional[ArrayLike] = None, cmfs: Union[ MultiSpectralDistributions, @@ -398,7 +384,7 @@ def plot_chromaticity_diagram_colours( Literal["CIE 1931", "CIE 1960 UCS", "CIE 1976 UCS"], str ] = "CIE 1931", **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> tuple[plt.Figure, plt.Axes]: """ Plot the *Chromaticity Diagram* colours according to given method. @@ -448,7 +434,7 @@ def plot_chromaticity_diagram_colours( method, ["CIE 1931", "CIE 1960 UCS", "CIE 1976 UCS"] ) - settings: Dict[str, Any] = {"uniform": True} + settings: dict[str, Any] = {"uniform": True} settings.update(kwargs) _figure, axes = artist(**settings) @@ -533,13 +519,13 @@ def plot_chromaticity_diagram( str, Sequence[Union[MultiSpectralDistributions, str]], ] = "CIE 1931 2 Degree Standard Observer", - show_diagram_colours: Boolean = True, - show_spectral_locus: Boolean = True, + show_diagram_colours: bool = True, + show_spectral_locus: bool = True, method: Union[ Literal["CIE 1931", "CIE 1960 UCS", "CIE 1976 UCS"], str ] = "CIE 1931", **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> tuple[plt.Figure, plt.Axes]: """ Plot the *Chromaticity Diagram* according to given method. @@ -584,7 +570,7 @@ def plot_chromaticity_diagram( method, ["CIE 1931", "CIE 1960 UCS", "CIE 1976 UCS"] ) - settings: Dict[str, Any] = {"uniform": True} + settings: dict[str, Any] = {"uniform": True} settings.update(kwargs) _figure, axes = artist(**settings) @@ -643,10 +629,10 @@ def plot_chromaticity_diagram_CIE1931( str, Sequence[Union[MultiSpectralDistributions, str]], ] = "CIE 1931 2 Degree Standard Observer", - show_diagram_colours: Boolean = True, - show_spectral_locus: Boolean = True, + show_diagram_colours: bool = True, + show_spectral_locus: bool = True, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> tuple[plt.Figure, plt.Axes]: """ Plot the *CIE 1931 Chromaticity Diagram*. @@ -699,10 +685,10 @@ def plot_chromaticity_diagram_CIE1960UCS( str, Sequence[Union[MultiSpectralDistributions, str]], ] = "CIE 1931 2 Degree Standard Observer", - show_diagram_colours: Boolean = True, - show_spectral_locus: Boolean = True, + show_diagram_colours: bool = True, + show_spectral_locus: bool = True, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> tuple[plt.Figure, plt.Axes]: """ Plot the *CIE 1960 UCS Chromaticity Diagram*. @@ -755,10 +741,10 @@ def plot_chromaticity_diagram_CIE1976UCS( str, Sequence[Union[MultiSpectralDistributions, str]], ] = "CIE 1931 2 Degree Standard Observer", - show_diagram_colours: Boolean = True, - show_spectral_locus: Boolean = True, + show_diagram_colours: bool = True, + show_spectral_locus: bool = True, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> tuple[plt.Figure, plt.Axes]: """ Plot the *CIE 1976 UCS Chromaticity Diagram*. @@ -819,10 +805,10 @@ def plot_sds_in_chromaticity_diagram( method: Union[ Literal["CIE 1931", "CIE 1960 UCS", "CIE 1976 UCS"], str ] = "CIE 1931", - annotate_kwargs: Optional[Union[Dict, List[Dict]]] = None, - plot_kwargs: Optional[Union[Dict, List[Dict]]] = None, + annotate_kwargs: Optional[Union[dict, list[dict]]] = None, + plot_kwargs: Optional[Union[dict, list[dict]]] = None, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> tuple[plt.Figure, plt.Axes]: """ Plot given spectral distribution chromaticity coordinates into the *Chromaticity Diagram* using given method. @@ -926,7 +912,7 @@ def plot_sds_in_chromaticity_diagram( sds_converted = sds_and_msds_to_sds(sds) - settings: Dict[str, Any] = {"uniform": True} + settings: dict[str, Any] = {"uniform": True} settings.update(kwargs) _figure, axes = artist(**settings) @@ -944,7 +930,7 @@ def plot_sds_in_chromaticity_diagram( if method == "cie 1931": - def XYZ_to_ij(XYZ: NDArray) -> NDArray: + def XYZ_to_ij(XYZ: NDArrayFloat) -> NDArrayFloat: """ Convert given *CIE XYZ* tristimulus values to *ij* chromaticity coordinates. @@ -955,7 +941,7 @@ def XYZ_to_ij(XYZ: NDArray) -> NDArray: bounding_box = (-0.1, 0.9, -0.1, 0.9) elif method == "cie 1960 ucs": - def XYZ_to_ij(XYZ: NDArray) -> NDArray: + def XYZ_to_ij(XYZ: NDArrayFloat) -> NDArrayFloat: """ Convert given *CIE XYZ* tristimulus values to *ij* chromaticity coordinates. @@ -967,7 +953,7 @@ def XYZ_to_ij(XYZ: NDArray) -> NDArray: elif method == "cie 1976 ucs": - def XYZ_to_ij(XYZ: NDArray) -> NDArray: + def XYZ_to_ij(XYZ: NDArrayFloat) -> NDArrayFloat: """ Convert given *CIE XYZ* tristimulus values to *ij* chromaticity coordinates. @@ -1077,10 +1063,10 @@ def plot_sds_in_chromaticity_diagram_CIE1931( chromaticity_diagram_callable_CIE1931: Callable = ( plot_chromaticity_diagram_CIE1931 ), - annotate_kwargs: Optional[Union[Dict, List[Dict]]] = None, - plot_kwargs: Optional[Union[Dict, List[Dict]]] = None, + annotate_kwargs: Optional[Union[dict, list[dict]]] = None, + plot_kwargs: Optional[Union[dict, list[dict]]] = None, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> tuple[plt.Figure, plt.Axes]: """ Plot given spectral distribution chromaticity coordinates into the *CIE 1931 Chromaticity Diagram*. @@ -1189,10 +1175,10 @@ def plot_sds_in_chromaticity_diagram_CIE1960UCS( chromaticity_diagram_callable_CIE1960UCS: Callable = ( plot_chromaticity_diagram_CIE1960UCS ), - annotate_kwargs: Optional[Union[Dict, List[Dict]]] = None, - plot_kwargs: Optional[Union[Dict, List[Dict]]] = None, + annotate_kwargs: Optional[Union[dict, list[dict]]] = None, + plot_kwargs: Optional[Union[dict, list[dict]]] = None, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> tuple[plt.Figure, plt.Axes]: """ Plot given spectral distribution chromaticity coordinates into the *CIE 1960 UCS Chromaticity Diagram*. @@ -1302,10 +1288,10 @@ def plot_sds_in_chromaticity_diagram_CIE1976UCS( chromaticity_diagram_callable_CIE1976UCS: Callable = ( plot_chromaticity_diagram_CIE1976UCS ), - annotate_kwargs: Optional[Union[Dict, List[Dict]]] = None, - plot_kwargs: Optional[Union[Dict, List[Dict]]] = None, + annotate_kwargs: Optional[Union[dict, list[dict]]] = None, + plot_kwargs: Optional[Union[dict, list[dict]]] = None, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> tuple[plt.Figure, plt.Axes]: """ Plot given spectral distribution chromaticity coordinates into the *CIE 1976 UCS Chromaticity Diagram*. diff --git a/colour/plotting/graph.py b/colour/plotting/graph.py index cd80fa2ff9..e90970bf3f 100644 --- a/colour/plotting/graph.py +++ b/colour/plotting/graph.py @@ -37,7 +37,7 @@ def plot_automatic_colour_conversion_graph( Literal["circo", "dot", "fdp", "neato", "nop", "twopi"], str ] = "fdp", args: str = "", -) -> AGraph: # type: ignore[name-defined] # noqa +) -> AGraph: # pyright: ignore # noqa """ Plot *Colour* automatic colour conversion graph using `Graphviz `__ and diff --git a/colour/plotting/models.py b/colour/plotting/models.py index 5c6936ec06..7c3f23343a 100644 --- a/colour/plotting/models.py +++ b/colour/plotting/models.py @@ -59,16 +59,11 @@ from colour.hints import ( Any, ArrayLike, - Boolean, Callable, - Dict, - Floating, - List, Literal, - NDArray, + NDArrayFloat, Optional, Sequence, - Tuple, Union, cast, ) @@ -116,6 +111,7 @@ CanonicalMapping, as_array, as_float_array, + as_float_scalar, as_int_array, domain_range_scale, first_item, @@ -222,7 +218,7 @@ def colourspace_model_axis_reorder( str, ], direction: Union[Literal["Forward", "Inverse"], str] = "Forward", -) -> NDArray: +) -> NDArrayFloat: """ Reorder the axes of given colourspace model :math:`a` array according to the most common volume plotting axes order. @@ -283,12 +279,12 @@ def colourspace_model_axis_reorder( @override_style() def plot_pointer_gamut( pointer_gamut_colours: Optional[Union[ArrayLike, str]] = None, - pointer_gamut_opacity: Floating = 1, + pointer_gamut_opacity: float = 1, method: Union[ Literal["CIE 1931", "CIE 1960 UCS", "CIE 1976 UCS"], str ] = "CIE 1931", **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> tuple[plt.Figure, plt.Axes]: """ Plot *Pointer's Gamut* according to given method. @@ -333,14 +329,14 @@ def plot_pointer_gamut( pointer_gamut_opacity, CONSTANTS_COLOUR_STYLE.opacity.high ) - settings: Dict[str, Any] = {"uniform": True} + settings: dict[str, Any] = {"uniform": True} settings.update(kwargs) _figure, axes = artist(**settings) if method == "cie 1931": - def XYZ_to_ij(XYZ: NDArray, *args: Any) -> NDArray: + def XYZ_to_ij(XYZ: NDArrayFloat, *args: Any) -> NDArrayFloat: """ Convert given *CIE XYZ* tristimulus values to *ij* chromaticity coordinates. @@ -348,7 +344,7 @@ def XYZ_to_ij(XYZ: NDArray, *args: Any) -> NDArray: return XYZ_to_xy(XYZ, *args) - def xy_to_ij(xy: NDArray) -> NDArray: + def xy_to_ij(xy: NDArrayFloat) -> NDArrayFloat: """ Convert given *CIE xy* chromaticity coordinates to *ij* chromaticity coordinates. @@ -358,7 +354,7 @@ def xy_to_ij(xy: NDArray) -> NDArray: elif method == "cie 1960 ucs": - def XYZ_to_ij(XYZ: NDArray, *args: Any) -> NDArray: + def XYZ_to_ij(XYZ: NDArrayFloat, *args: Any) -> NDArrayFloat: """ Convert given *CIE XYZ* tristimulus values to *ij* chromaticity coordinates. @@ -366,7 +362,7 @@ def XYZ_to_ij(XYZ: NDArray, *args: Any) -> NDArray: return UCS_to_uv(XYZ_to_UCS(XYZ)) - def xy_to_ij(xy: NDArray) -> NDArray: + def xy_to_ij(xy: NDArrayFloat) -> NDArrayFloat: """ Convert given *CIE xy* chromaticity coordinates to *ij* chromaticity coordinates. @@ -376,7 +372,7 @@ def xy_to_ij(xy: NDArray) -> NDArray: elif method == "cie 1976 ucs": - def XYZ_to_ij(XYZ: NDArray, *args: Any) -> NDArray: + def XYZ_to_ij(XYZ: NDArrayFloat, *args: Any) -> NDArrayFloat: """ Convert given *CIE XYZ* tristimulus values to *ij* chromaticity coordinates. @@ -384,7 +380,7 @@ def XYZ_to_ij(XYZ: NDArray, *args: Any) -> NDArray: return Luv_to_uv(XYZ_to_Luv(XYZ, *args), *args) - def xy_to_ij(xy: NDArray) -> NDArray: + def xy_to_ij(xy: NDArrayFloat) -> NDArrayFloat: """ Convert given *CIE xy* chromaticity coordinates to *ij* chromaticity coordinates. @@ -438,18 +434,16 @@ def plot_RGB_colourspaces_in_chromaticity_diagram( str, Sequence[Union[MultiSpectralDistributions, str]], ] = "CIE 1931 2 Degree Standard Observer", - chromaticity_diagram_callable: Callable = ( - plot_chromaticity_diagram # type: ignore[has-type] - ), + chromaticity_diagram_callable: Callable = (plot_chromaticity_diagram), method: Union[ Literal["CIE 1931", "CIE 1960 UCS", "CIE 1976 UCS"], str ] = "CIE 1931", - show_whitepoints: Boolean = True, - show_pointer_gamut: Boolean = False, - chromatically_adapt: Boolean = False, - plot_kwargs: Optional[Union[Dict, List[Dict]]] = None, + show_whitepoints: bool = True, + show_pointer_gamut: bool = False, + chromatically_adapt: bool = False, + plot_kwargs: Optional[Union[dict, list[dict]]] = None, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> tuple[plt.Figure, plt.Axes]: """ Plot given *RGB* colourspaces in the *Chromaticity Diagram* according to given method. @@ -521,11 +515,11 @@ def plot_RGB_colourspaces_in_chromaticity_diagram( ) colourspaces = cast( - List[RGB_Colourspace], + list[RGB_Colourspace], list(filter_RGB_colourspaces(colourspaces).values()), - ) + ) # pyright: ignore - settings: Dict[str, Any] = {"uniform": True} + settings: dict[str, Any] = {"uniform": True} settings.update(kwargs) _figure, axes = artist(**settings) @@ -554,7 +548,7 @@ def plot_RGB_colourspaces_in_chromaticity_diagram( if method == "cie 1931": - def xy_to_ij(xy: NDArray) -> NDArray: + def xy_to_ij(xy: NDArrayFloat) -> NDArrayFloat: """ Convert given *CIE xy* chromaticity coordinates to *ij* chromaticity coordinates. @@ -567,7 +561,7 @@ def xy_to_ij(xy: NDArray) -> NDArray: elif method == "cie 1960 ucs": - def xy_to_ij(xy: NDArray) -> NDArray: + def xy_to_ij(xy: NDArrayFloat) -> NDArrayFloat: """ Convert given *CIE xy* chromaticity coordinates to *ij* chromaticity coordinates. @@ -580,7 +574,7 @@ def xy_to_ij(xy: NDArray) -> NDArray: elif method == "cie 1976 ucs": - def xy_to_ij(xy: NDArray) -> NDArray: + def xy_to_ij(xy: NDArrayFloat) -> NDArrayFloat: """ Convert given *CIE xy* chromaticity coordinates to *ij* chromaticity coordinates. @@ -645,10 +639,10 @@ def xy_to_ij(xy: NDArray) -> NDArray: W_p = np.vstack([W, W]) axes.plot(W_p[..., 0], W_p[..., 1], **plot_settings) - x_limit_min.append(np.amin(P[..., 0]) - 0.1) - y_limit_min.append(np.amin(P[..., 1]) - 0.1) - x_limit_max.append(np.amax(P[..., 0]) + 0.1) - y_limit_max.append(np.amax(P[..., 1]) + 0.1) + x_limit_min.append(as_float_scalar(np.amin(P[..., 0]) - 0.1)) + y_limit_min.append(as_float_scalar(np.amin(P[..., 1]) - 0.1)) + x_limit_max.append(as_float_scalar(np.amax(P[..., 0]) + 0.1)) + y_limit_max.append(as_float_scalar(np.amax(P[..., 1]) + 0.1)) bounding_box = ( min(x_limit_min), @@ -680,14 +674,14 @@ def plot_RGB_colourspaces_in_chromaticity_diagram_CIE1931( Sequence[Union[MultiSpectralDistributions, str]], ] = "CIE 1931 2 Degree Standard Observer", chromaticity_diagram_callable_CIE1931: Callable = ( - plot_chromaticity_diagram_CIE1931 # type: ignore[has-type] + plot_chromaticity_diagram_CIE1931 ), - show_whitepoints: Boolean = True, - show_pointer_gamut: Boolean = False, - chromatically_adapt: Boolean = False, - plot_kwargs: Optional[Union[Dict, List[Dict]]] = None, + show_whitepoints: bool = True, + show_pointer_gamut: bool = False, + chromatically_adapt: bool = False, + plot_kwargs: Optional[Union[dict, list[dict]]] = None, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> tuple[plt.Figure, plt.Axes]: """ Plot given *RGB* colourspaces in the *CIE 1931 Chromaticity Diagram*. @@ -774,14 +768,14 @@ def plot_RGB_colourspaces_in_chromaticity_diagram_CIE1960UCS( Sequence[Union[MultiSpectralDistributions, str]], ] = "CIE 1931 2 Degree Standard Observer", chromaticity_diagram_callable_CIE1960UCS: Callable = ( - plot_chromaticity_diagram_CIE1960UCS # type: ignore[has-type] + plot_chromaticity_diagram_CIE1960UCS ), - show_whitepoints: Boolean = True, - show_pointer_gamut: Boolean = False, - chromatically_adapt: Boolean = False, - plot_kwargs: Optional[Union[Dict, List[Dict]]] = None, + show_whitepoints: bool = True, + show_pointer_gamut: bool = False, + chromatically_adapt: bool = False, + plot_kwargs: Optional[Union[dict, list[dict]]] = None, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> tuple[plt.Figure, plt.Axes]: """ Plot given *RGB* colourspaces in the *CIE 1960 UCS Chromaticity Diagram*. @@ -869,14 +863,14 @@ def plot_RGB_colourspaces_in_chromaticity_diagram_CIE1976UCS( Sequence[Union[MultiSpectralDistributions, str]], ] = "CIE 1931 2 Degree Standard Observer", chromaticity_diagram_callable_CIE1976UCS: Callable = ( - plot_chromaticity_diagram_CIE1976UCS # type: ignore[has-type] + plot_chromaticity_diagram_CIE1976UCS ), - show_whitepoints: Boolean = True, - show_pointer_gamut: Boolean = False, - chromatically_adapt: Boolean = False, - plot_kwargs: Optional[Union[Dict, List[Dict]]] = None, + show_whitepoints: bool = True, + show_pointer_gamut: bool = False, + chromatically_adapt: bool = False, + plot_kwargs: Optional[Union[dict, list[dict]]] = None, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> tuple[plt.Figure, plt.Axes]: """ Plot given *RGB* colourspaces in the *CIE 1976 UCS Chromaticity Diagram*. @@ -965,9 +959,9 @@ def plot_RGB_chromaticities_in_chromaticity_diagram( method: Union[ Literal["CIE 1931", "CIE 1960 UCS", "CIE 1976 UCS"], str ] = "CIE 1931", - scatter_kwargs: Optional[Dict] = None, + scatter_kwargs: Optional[dict] = None, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> tuple[plt.Figure, plt.Axes]: """ Plot given *RGB* colourspace array in the *Chromaticity Diagram* according to given method. @@ -1024,7 +1018,7 @@ def plot_RGB_chromaticities_in_chromaticity_diagram( method, ["CIE 1931", "CIE 1960 UCS", "CIE 1976 UCS"] ) - settings: Dict[str, Any] = {"uniform": True} + settings: dict[str, Any] = {"uniform": True} settings.update(kwargs) _figure, axes = artist(**settings) @@ -1103,9 +1097,9 @@ def plot_RGB_chromaticities_in_chromaticity_diagram_CIE1931( chromaticity_diagram_callable_CIE1931: Callable = ( plot_RGB_colourspaces_in_chromaticity_diagram_CIE1931 ), - scatter_kwargs: Optional[Dict] = None, + scatter_kwargs: Optional[dict] = None, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> tuple[plt.Figure, plt.Axes]: """ Plot given *RGB* colourspace array in the *CIE 1931 Chromaticity Diagram*. @@ -1177,9 +1171,9 @@ def plot_RGB_chromaticities_in_chromaticity_diagram_CIE1960UCS( chromaticity_diagram_callable_CIE1960UCS: Callable = ( plot_RGB_colourspaces_in_chromaticity_diagram_CIE1960UCS ), - scatter_kwargs: Optional[Dict] = None, + scatter_kwargs: Optional[dict] = None, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> tuple[plt.Figure, plt.Axes]: """ Plot given *RGB* colourspace array in the *CIE 1960 UCS Chromaticity Diagram*. @@ -1253,9 +1247,9 @@ def plot_RGB_chromaticities_in_chromaticity_diagram_CIE1976UCS( chromaticity_diagram_callable_CIE1976UCS: Callable = ( plot_RGB_colourspaces_in_chromaticity_diagram_CIE1976UCS ), - scatter_kwargs: Optional[Dict] = None, + scatter_kwargs: Optional[dict] = None, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> tuple[plt.Figure, plt.Axes]: """ Plot given *RGB* colourspace array in the *CIE 1976 UCS Chromaticity Diagram*. @@ -1324,7 +1318,7 @@ def ellipses_MacAdam1942( method: Union[ Literal["CIE 1931", "CIE 1960 UCS", "CIE 1976 UCS"], str ] = "CIE 1931" -) -> List[NDArray]: +) -> list[NDArrayFloat]: """ Return *MacAdam (1942) Ellipses (Observer PGN)* coefficients according to given method. @@ -1352,7 +1346,7 @@ def ellipses_MacAdam1942( if method == "cie 1931": - def xy_to_ij(xy: NDArray) -> NDArray: + def xy_to_ij(xy: NDArrayFloat) -> NDArrayFloat: """ Convert given *CIE xy* chromaticity coordinates to *ij* chromaticity coordinates. @@ -1362,7 +1356,7 @@ def xy_to_ij(xy: NDArray) -> NDArray: elif method == "cie 1960 ucs": - def xy_to_ij(xy: NDArray) -> NDArray: + def xy_to_ij(xy: NDArrayFloat) -> NDArrayFloat: """ Convert given *CIE xy* chromaticity coordinates to *ij* chromaticity coordinates. @@ -1372,7 +1366,7 @@ def xy_to_ij(xy: NDArray) -> NDArray: elif method == "cie 1976 ucs": - def xy_to_ij(xy: NDArray) -> NDArray: + def xy_to_ij(xy: NDArrayFloat) -> NDArrayFloat: """ Convert given *CIE xy* chromaticity coordinates to *ij* chromaticity coordinates. @@ -1399,16 +1393,14 @@ def xy_to_ij(xy: NDArray) -> NDArray: @override_style() def plot_ellipses_MacAdam1942_in_chromaticity_diagram( - chromaticity_diagram_callable: Callable = ( - plot_chromaticity_diagram # type: ignore[has-type] - ), + chromaticity_diagram_callable: Callable = (plot_chromaticity_diagram), method: Union[ Literal["CIE 1931", "CIE 1960 UCS", "CIE 1976 UCS"], str ] = "CIE 1931", - chromaticity_diagram_clipping: Boolean = False, - ellipse_kwargs: Optional[Union[Dict, List[Dict]]] = None, + chromaticity_diagram_clipping: bool = False, + ellipse_kwargs: Optional[Union[dict, list[dict]]] = None, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> tuple[plt.Figure, plt.Axes]: """ Plot *MacAdam (1942) Ellipses (Observer PGN)* in the *Chromaticity Diagram* according to given method. @@ -1452,7 +1444,7 @@ def plot_ellipses_MacAdam1942_in_chromaticity_diagram( :alt: plot_ellipses_MacAdam1942_in_chromaticity_diagram """ - settings: Dict[str, Any] = {"uniform": True} + settings: dict[str, Any] = {"uniform": True} settings.update(kwargs) _figure, axes = artist(**settings) @@ -1523,12 +1515,12 @@ def plot_ellipses_MacAdam1942_in_chromaticity_diagram( @override_style() def plot_ellipses_MacAdam1942_in_chromaticity_diagram_CIE1931( chromaticity_diagram_callable_CIE1931: Callable = ( - plot_chromaticity_diagram_CIE1931 # type: ignore[has-type] + plot_chromaticity_diagram_CIE1931 ), - chromaticity_diagram_clipping: Boolean = False, - ellipse_kwargs: Optional[Union[Dict, List[Dict]]] = None, + chromaticity_diagram_clipping: bool = False, + ellipse_kwargs: Optional[Union[dict, list[dict]]] = None, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> tuple[plt.Figure, plt.Axes]: """ Plot *MacAdam (1942) Ellipses (Observer PGN)* in the *CIE 1931 Chromaticity Diagram*. @@ -1587,12 +1579,12 @@ def plot_ellipses_MacAdam1942_in_chromaticity_diagram_CIE1931( @override_style() def plot_ellipses_MacAdam1942_in_chromaticity_diagram_CIE1960UCS( chromaticity_diagram_callable_CIE1960UCS: Callable = ( - plot_chromaticity_diagram_CIE1960UCS # type: ignore[has-type] + plot_chromaticity_diagram_CIE1960UCS ), - chromaticity_diagram_clipping: Boolean = False, - ellipse_kwargs: Optional[Union[Dict, List[Dict]]] = None, + chromaticity_diagram_clipping: bool = False, + ellipse_kwargs: Optional[Union[dict, list[dict]]] = None, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> tuple[plt.Figure, plt.Axes]: """ Plot *MacAdam (1942) Ellipses (Observer PGN)* in the *CIE 1960 UCS Chromaticity Diagram*. @@ -1652,12 +1644,12 @@ def plot_ellipses_MacAdam1942_in_chromaticity_diagram_CIE1960UCS( @override_style() def plot_ellipses_MacAdam1942_in_chromaticity_diagram_CIE1976UCS( chromaticity_diagram_callable_CIE1976UCS: Callable = ( - plot_chromaticity_diagram_CIE1976UCS # type: ignore[has-type] + plot_chromaticity_diagram_CIE1976UCS ), - chromaticity_diagram_clipping: Boolean = False, - ellipse_kwargs: Optional[Union[Dict, List[Dict]]] = None, + chromaticity_diagram_clipping: bool = False, + ellipse_kwargs: Optional[Union[dict, list[dict]]] = None, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> tuple[plt.Figure, plt.Axes]: """ Plot *MacAdam (1942) Ellipses (Observer PGN)* in the *CIE 1976 UCS Chromaticity Diagram*. @@ -1716,8 +1708,8 @@ def plot_ellipses_MacAdam1942_in_chromaticity_diagram_CIE1976UCS( @override_style() def plot_single_cctf( - cctf: Union[Callable, str], cctf_decoding: Boolean = False, **kwargs: Any -) -> Tuple[plt.Figure, plt.Axes]: + cctf: Union[Callable, str], cctf_decoding: bool = False, **kwargs: Any +) -> tuple[plt.Figure, plt.Axes]: """ Plot given colourspace colour component transfer function. @@ -1753,7 +1745,7 @@ def plot_single_cctf( :alt: plot_single_cctf """ - settings: Dict[str, Any] = { + settings: dict[str, Any] = { "title": f"{cctf} - {'Decoding' if cctf_decoding else 'Encoding'} CCTF" } settings.update(kwargs) @@ -1764,9 +1756,9 @@ def plot_single_cctf( @override_style() def plot_multi_cctfs( cctfs: Union[Callable, str, Sequence[Union[Callable, str]]], - cctf_decoding: Boolean = False, + cctf_decoding: bool = False, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> tuple[plt.Figure, plt.Axes]: """ Plot given colour component transfer functions. @@ -1809,7 +1801,7 @@ def plot_multi_cctfs( mode = "Decoding" if cctf_decoding else "Encoding" title = f"{', '.join([cctf for cctf in cctfs_filtered])} - {mode} CCTFs" - settings: Dict[str, Any] = { + settings: dict[str, Any] = { "bounding_box": (0, 1, 0, 1), "legend": True, "title": title, @@ -1855,10 +1847,10 @@ def plot_constant_hue_loci( ], str, ] = "CIE Lab", - scatter_kwargs: Optional[Dict] = None, - convert_kwargs: Optional[Dict] = None, + scatter_kwargs: Optional[dict] = None, + convert_kwargs: Optional[dict] = None, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> tuple[plt.Figure, plt.Axes]: """ Plot given constant hue loci colour matches data such as that from :cite:`Hung1995` or :cite:`Ebner1998` that are easily loaded with @@ -2003,7 +1995,7 @@ def plot_constant_hue_loci( # TODO: Filter appropriate colour models. data = as_array(data) - settings: Dict[str, Any] = {"uniform": True} + settings: dict[str, Any] = {"uniform": True} settings.update(kwargs) _figure, axes = artist(**settings) @@ -2041,7 +2033,9 @@ def plot_constant_hue_loci( ijk_ct *= COLOURSPACE_MODELS_DOMAIN_RANGE_SCALE_1_TO_REFERENCE[model] ijk_cr *= COLOURSPACE_MODELS_DOMAIN_RANGE_SCALE_1_TO_REFERENCE[model] - def _linear_equation(x: NDArray, a: NDArray, b: NDArray) -> NDArray: + def _linear_equation( + x: NDArrayFloat, a: NDArrayFloat, b: NDArrayFloat + ) -> NDArrayFloat: """Define the canonical linear equation for a line.""" return a * x + b @@ -2059,7 +2053,7 @@ def _linear_equation(x: NDArray, a: NDArray, b: NDArray) -> NDArray: if use_RGB_colours: - def _XYZ_to_RGB(XYZ: NDArray) -> NDArray: + def _XYZ_to_RGB(XYZ: NDArrayFloat) -> NDArrayFloat: """ Convert given *CIE XYZ* tristimulus values to ``colour.plotting`` *RGB* colourspace. diff --git a/colour/plotting/notation.py b/colour/plotting/notation.py index e838e4d34d..76d50e1a45 100644 --- a/colour/plotting/notation.py +++ b/colour/plotting/notation.py @@ -13,7 +13,7 @@ import matplotlib.pyplot as plt import numpy as np -from colour.hints import Any, Callable, Dict, Sequence, Tuple, Union +from colour.hints import Any, Callable, Sequence, Union from colour.notation import MUNSELL_VALUE_METHODS from colour.plotting import ( filter_passthrough, @@ -37,7 +37,7 @@ @override_style() def plot_single_munsell_value_function( function: Union[Callable, str], **kwargs: Any -) -> Tuple[plt.Figure, plt.Axes]: +) -> tuple[plt.Figure, plt.Axes]: """ Plot given *Lightness* function. @@ -71,7 +71,7 @@ def plot_single_munsell_value_function( :alt: plot_single_munsell_value_function """ - settings: Dict[str, Any] = { + settings: dict[str, Any] = { "title": f"{function} - Munsell Value Function" } settings.update(kwargs) @@ -83,7 +83,7 @@ def plot_single_munsell_value_function( def plot_multi_munsell_value_functions( functions: Union[Callable, str, Sequence[Union[Callable, str]]], **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> tuple[plt.Figure, plt.Axes]: """ Plot given *Munsell* value functions. @@ -120,7 +120,7 @@ def plot_multi_munsell_value_functions( functions_filtered = filter_passthrough(MUNSELL_VALUE_METHODS, functions) - settings: Dict[str, Any] = { + settings: dict[str, Any] = { "bounding_box": (0, 100, 0, 10), "legend": True, "title": f"{', '.join(functions_filtered)} - Munsell Functions", diff --git a/colour/plotting/phenomena.py b/colour/plotting/phenomena.py index ee38d83eef..4c0b375cee 100644 --- a/colour/plotting/phenomena.py +++ b/colour/plotting/phenomena.py @@ -15,15 +15,12 @@ from colour.algebra import normalise_maximum from colour.colorimetry import ( MultiSpectralDistributions, - SpectralDistribution, sd_to_XYZ, ) from colour.hints import ( Any, - Dict, - FloatingOrArrayLike, + ArrayLike, Sequence, - Tuple, Union, cast, ) @@ -63,18 +60,18 @@ @override_style() def plot_single_sd_rayleigh_scattering( - CO2_concentration: FloatingOrArrayLike = CONSTANT_STANDARD_CO2_CONCENTRATION, - temperature: FloatingOrArrayLike = CONSTANT_STANDARD_AIR_TEMPERATURE, - pressure: FloatingOrArrayLike = CONSTANT_AVERAGE_PRESSURE_MEAN_SEA_LEVEL, - latitude: FloatingOrArrayLike = CONSTANT_DEFAULT_LATITUDE, - altitude: FloatingOrArrayLike = CONSTANT_DEFAULT_ALTITUDE, + CO2_concentration: ArrayLike = CONSTANT_STANDARD_CO2_CONCENTRATION, + temperature: ArrayLike = CONSTANT_STANDARD_AIR_TEMPERATURE, + pressure: ArrayLike = CONSTANT_AVERAGE_PRESSURE_MEAN_SEA_LEVEL, + latitude: ArrayLike = CONSTANT_DEFAULT_LATITUDE, + altitude: ArrayLike = CONSTANT_DEFAULT_ALTITUDE, cmfs: Union[ MultiSpectralDistributions, str, Sequence[Union[MultiSpectralDistributions, str]], ] = "CIE 1931 2 Degree Standard Observer", **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> tuple[plt.Figure, plt.Axes]: """ Plot a single *Rayleigh* scattering spectral distribution. @@ -124,7 +121,7 @@ def plot_single_sd_rayleigh_scattering( MultiSpectralDistributions, first_item(filter_cmfs(cmfs).values()) ) - settings: Dict[str, Any] = {"title": title, "y_label": "Optical Depth"} + settings: dict[str, Any] = {"title": title, "y_label": "Optical Depth"} settings.update(kwargs) sd = sd_rayleigh_scattering( @@ -147,7 +144,7 @@ def plot_the_blue_sky( Sequence[Union[MultiSpectralDistributions, str]], ] = "CIE 1931 2 Degree Standard Observer", **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> tuple[plt.Figure, plt.Axes]: """ Plot the blue sky. @@ -190,7 +187,7 @@ def plot_the_blue_sky( MultiSpectralDistributions, first_item(filter_cmfs(cmfs).values()) ) - ASTMG173_sd = cast(SpectralDistribution, SD_ASTMG173_ETR.copy()) + ASTMG173_sd = SD_ASTMG173_ETR.copy() rayleigh_sd = sd_rayleigh_scattering() ASTMG173_sd.align(rayleigh_sd.shape) @@ -198,7 +195,7 @@ def plot_the_blue_sky( axes = figure.add_subplot(211) - settings: Dict[str, Any] = { + settings: dict[str, Any] = { "axes": axes, "title": "The Blue Sky - Synthetic Spectral Distribution", "y_label": "W / m-2 / nm-1", @@ -230,9 +227,7 @@ def plot_the_blue_sky( settings.update(kwargs) settings["standalone"] = False - blue_sky_color = XYZ_to_plotting_colourspace( - sd_to_XYZ(cast(SpectralDistribution, sd)) - ) + blue_sky_color = XYZ_to_plotting_colourspace(sd_to_XYZ(sd)) figure, axes = plot_single_colour_swatch( ColourSwatch(normalise_maximum(blue_sky_color)), **settings diff --git a/colour/plotting/quality.py b/colour/plotting/quality.py index 2503bc6d32..8057f55e6e 100644 --- a/colour/plotting/quality.py +++ b/colour/plotting/quality.py @@ -24,14 +24,9 @@ ) from colour.hints import ( Any, - Boolean, - Dict, - Integer, - List, Literal, Optional, Sequence, - Tuple, Union, cast, ) @@ -76,11 +71,11 @@ def plot_colour_quality_bars( ColourRendering_Specification_CRI, ] ], - labels: Boolean = True, - hatching: Optional[Boolean] = None, - hatching_repeat: Integer = 2, + labels: bool = True, + hatching: Optional[bool] = None, + hatching_repeat: int = 2, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> tuple[plt.Figure, plt.Axes]: """ Plot the colour quality data of given illuminants or light sources colour quality specifications. @@ -125,7 +120,7 @@ def plot_colour_quality_bars( :alt: plot_colour_quality_bars """ - settings: Dict[str, Any] = {"uniform": True} + settings: dict[str, Any] = {"uniform": True} settings.update(kwargs) _figure, axes = artist(**settings) @@ -164,10 +159,7 @@ def plot_colour_quality_bars( ) y = as_float_array( [Q_a] - + [ - s[1].Q_a # type: ignore[attr-defined] - for s in sorted(Q_as.items(), key=lambda s: s[0]) - ] + + [s[1].Q_a for s in sorted(Q_as.items(), key=lambda s: s[0])] ) bars = axes.bar( @@ -183,9 +175,7 @@ def plot_colour_quality_bars( hatches = ( [next(patterns) * hatching_repeat] * (count_Q_as + 1) if hatching - else list( - np.where(y < 0, next(patterns), None) # type: ignore[call-overload] - ) + else list(np.where(y < 0, next(patterns), None)) # pyright: ignore ) for j, bar in enumerate(bars.patches): @@ -252,7 +242,7 @@ def plot_colour_quality_bars( @override_style() def plot_single_sd_colour_rendering_index_bars( sd: SpectralDistribution, **kwargs: Any -) -> Tuple[plt.Figure, plt.Axes]: +) -> tuple[plt.Figure, plt.Axes]: """ Plot the *Colour Rendering Index* (CRI) of given illuminant or light source spectral distribution. @@ -300,7 +290,7 @@ def plot_multi_sds_colour_rendering_indexes_bars( MultiSpectralDistributions, ], **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> tuple[plt.Figure, plt.Axes]: """ Plot the *Colour Rendering Index* (CRI) of given illuminants or light sources spectral distributions. @@ -345,11 +335,11 @@ def plot_multi_sds_colour_rendering_indexes_bars( sds_converted = sds_and_msds_to_sds(sds) - settings: Dict[str, Any] = dict(kwargs) + settings: dict[str, Any] = dict(kwargs) settings.update({"standalone": False}) specifications = cast( - List[ColourRendering_Specification_CRI], + list[ColourRendering_Specification_CRI], [ colour_rendering_index(sd, additional_data=True) for sd in sds_converted @@ -386,7 +376,7 @@ def plot_single_sd_colour_quality_scale_bars( Literal["NIST CQS 7.4", "NIST CQS 9.0"], str ] = "NIST CQS 9.0", **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> tuple[plt.Figure, plt.Axes]: """ Plot the *Colour Quality Scale* (CQS) of given illuminant or light source spectral distribution. @@ -441,7 +431,7 @@ def plot_multi_sds_colour_quality_scales_bars( Literal["NIST CQS 7.4", "NIST CQS 9.0"], str ] = "NIST CQS 9.0", **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> tuple[plt.Figure, plt.Axes]: """ Plot the *Colour Quality Scale* (CQS) of given illuminants or light sources spectral distributions. @@ -489,11 +479,11 @@ def plot_multi_sds_colour_quality_scales_bars( sds_converted = sds_and_msds_to_sds(sds) - settings: Dict[str, Any] = dict(kwargs) + settings: dict[str, Any] = dict(kwargs) settings.update({"standalone": False}) specifications = cast( - List[ColourRendering_Specification_CQS], + list[ColourRendering_Specification_CQS], [colour_quality_scale(sd, True, method) for sd in sds_converted], ) diff --git a/colour/plotting/section.py b/colour/plotting/section.py index 5616d09c3d..d1de597311 100644 --- a/colour/plotting/section.py +++ b/colour/plotting/section.py @@ -28,14 +28,10 @@ from colour.hints import ( Any, ArrayLike, - Boolean, - Dict, - Floating, - Integer, Literal, + Number, Optional, Sequence, - Tuple, Union, cast, ) @@ -94,7 +90,7 @@ @required("trimesh") @override_style() def plot_hull_section_colours( - hull: trimesh.Trimesh, # type: ignore[name-defined] # noqa + hull: trimesh.Trimesh, # pyright: ignore # noqa model: Union[ Literal[ "CAM02LCD", @@ -125,14 +121,14 @@ def plot_hull_section_colours( str, ] = "CIE xyY", axis: Union[Literal["+z", "+x", "+y"], str] = "+z", - origin: Floating = 0.5, - normalise: Boolean = True, + origin: float = 0.5, + normalise: bool = True, section_colours: Optional[Union[ArrayLike, str]] = None, - section_opacity: Floating = 1, - convert_kwargs: Optional[Dict] = None, - samples: Integer = 256, + section_opacity: float = 1, + convert_kwargs: Optional[dict] = None, + samples: int = 256, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> tuple[plt.Figure, plt.Axes]: """ Plot the section colours of given *trimesh* hull along given axis and origin. @@ -206,7 +202,7 @@ def plot_hull_section_colours( hull = hull.copy() - settings: Dict[str, Any] = {"uniform": True} + settings: dict[str, Any] = {"uniform": True} settings.update(kwargs) _figure, axes = artist(**settings) @@ -259,7 +255,8 @@ def plot_hull_section_colours( ) ij = tstack([ii, jj]) ijk_section = full( - (samples, samples, 3), np.median(section[..., index_origin]) + (samples, samples, 3), + cast(Number, np.median(section[..., index_origin])), ) ijk_section[..., plane] = ij ijk_section /= COLOURSPACE_MODELS_DOMAIN_RANGE_SCALE_1_TO_REFERENCE[ @@ -306,7 +303,7 @@ def plot_hull_section_colours( @required("trimesh") @override_style() def plot_hull_section_contour( - hull: trimesh.Trimesh, # type: ignore[name-defined] # noqa + hull: trimesh.Trimesh, # pyright: ignore # noqa model: Union[ Literal[ "CAM02LCD", @@ -337,13 +334,13 @@ def plot_hull_section_contour( str, ] = "CIE xyY", axis: Union[Literal["+z", "+x", "+y"], str] = "+z", - origin: Floating = 0.5, - normalise: Boolean = True, + origin: float = 0.5, + normalise: bool = True, contour_colours: Optional[Union[ArrayLike, str]] = None, - contour_opacity: Floating = 1, - convert_kwargs: Optional[Dict] = None, + contour_opacity: float = 1, + convert_kwargs: Optional[dict] = None, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> tuple[plt.Figure, plt.Axes]: """ Plot the section contour of given *trimesh* hull along given axis and origin. @@ -414,7 +411,7 @@ def plot_hull_section_contour( optional(contour_colours, CONSTANTS_COLOUR_STYLE.colour.dark), ) - settings: Dict[str, Any] = {"uniform": True} + settings: dict[str, Any] = {"uniform": True} settings.update(kwargs) _figure, axes = artist(**settings) @@ -517,12 +514,12 @@ def plot_visible_spectrum_section( str, ] = "CIE xyY", axis: Union[Literal["+z", "+x", "+y"], str] = "+z", - origin: Floating = 0.5, - normalise: Boolean = True, - show_section_colours: Boolean = True, - show_section_contour: Boolean = True, + origin: float = 0.5, + normalise: bool = True, + show_section_colours: bool = True, + show_section_contour: bool = True, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> tuple[plt.Figure, plt.Axes]: """ Plot the visible spectrum volume, i.e. *Rösch-MacAdam* colour solid, section colours along given axis and origin. @@ -584,14 +581,17 @@ def plot_visible_spectrum_section( import trimesh - settings: Dict[str, Any] = {"uniform": True} + settings: dict[str, Any] = {"uniform": True} settings.update(kwargs) _figure, axes = artist(**settings) # pylint: disable=E1102 - cmfs = reshape_msds( - first_item(filter_cmfs(cmfs).values()), SpectralShape(360, 780, 1) + cmfs = cast( + MultiSpectralDistributions, + reshape_msds( + first_item(filter_cmfs(cmfs).values()), SpectralShape(360, 780, 1) + ), ) illuminant = cast( SpectralDistribution, @@ -689,12 +689,12 @@ def plot_RGB_colourspace_section( str, ] = "CIE xyY", axis: Union[Literal["+z", "+x", "+y"], str] = "+z", - origin: Floating = 0.5, - normalise: Boolean = True, - show_section_colours: Boolean = True, - show_section_contour: Boolean = True, + origin: float = 0.5, + normalise: bool = True, + show_section_colours: bool = True, + show_section_contour: bool = True, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> tuple[plt.Figure, plt.Axes]: """ Plot given *RGB* colourspace section colours along given axis and origin. @@ -750,7 +750,7 @@ def plot_RGB_colourspace_section( import trimesh - settings: Dict[str, Any] = {"uniform": True} + settings: dict[str, Any] = {"uniform": True} settings.update(kwargs) _figure, axes = artist(**settings) diff --git a/colour/plotting/temperature.py b/colour/plotting/temperature.py index f94721cb02..1bc97f78e4 100644 --- a/colour/plotting/temperature.py +++ b/colour/plotting/temperature.py @@ -23,14 +23,10 @@ Any, ArrayLike, Callable, - Dict, - Floating, - List, Literal, - NDArray, + NDArrayFloat, Optional, Sequence, - Tuple, Union, cast, ) @@ -82,13 +78,13 @@ @override_style() def plot_planckian_locus( planckian_locus_colours: Optional[Union[ArrayLike, str]] = None, - planckian_locus_opacity: Floating = 1, + planckian_locus_opacity: float = 1, planckian_locus_labels: Optional[Sequence] = None, method: Union[ Literal["CIE 1931", "CIE 1960 UCS", "CIE 1976 UCS"], str ] = "CIE 1931", **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> tuple[plt.Figure, plt.Axes]: """ Plot the *Planckian Locus* according to given method. @@ -138,7 +134,7 @@ def plot_planckian_locus( ) labels = cast( - Tuple, + tuple, optional( planckian_locus_labels, (10**6 / 600, 2000, 2500, 3000, 4000, 6000, 10**6 / 100), @@ -146,14 +142,14 @@ def plot_planckian_locus( ) D_uv = 0.05 - settings: Dict[str, Any] = {"uniform": True} + settings: dict[str, Any] = {"uniform": True} settings.update(kwargs) _figure, axes = artist(**settings) if method == "cie 1931": - def uv_to_ij(uv: NDArray) -> NDArray: + def uv_to_ij(uv: NDArrayFloat) -> NDArrayFloat: """ Convert given *uv* chromaticity coordinates to *ij* chromaticity coordinates. @@ -163,7 +159,7 @@ def uv_to_ij(uv: NDArray) -> NDArray: elif method == "cie 1960 ucs": - def uv_to_ij(uv: NDArray) -> NDArray: + def uv_to_ij(uv: NDArrayFloat) -> NDArrayFloat: """ Convert given *uv* chromaticity coordinates to *ij* chromaticity coordinates. @@ -173,7 +169,7 @@ def uv_to_ij(uv: NDArray) -> NDArray: elif method == "cie 1976 ucs": - def uv_to_ij(uv: NDArray) -> NDArray: + def uv_to_ij(uv: NDArrayFloat) -> NDArrayFloat: """ Convert given *uv* chromaticity coordinates to *ij* chromaticity coordinates. @@ -252,14 +248,12 @@ def CCT_D_uv_to_plotting_colourspace(CCT_D_uv): @override_style() def plot_planckian_locus_in_chromaticity_diagram( illuminants: Union[str, Sequence[str]], - chromaticity_diagram_callable: Callable = ( - plot_chromaticity_diagram # type: ignore[has-type] - ), + chromaticity_diagram_callable: Callable = (plot_chromaticity_diagram), method: Union[Literal["CIE 1931", "CIE 1960 UCS"], str] = "CIE 1931", - annotate_kwargs: Optional[Union[Dict, List[Dict]]] = None, - plot_kwargs: Optional[Union[Dict, List[Dict]]] = None, + annotate_kwargs: Optional[Union[dict, list[dict]]] = None, + plot_kwargs: Optional[Union[dict, list[dict]]] = None, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> tuple[plt.Figure, plt.Axes]: """ Plot the *Planckian Locus* and given illuminants in the *Chromaticity Diagram* according to given method. @@ -337,10 +331,10 @@ def plot_planckian_locus_in_chromaticity_diagram( cmfs = MSDS_CMFS["CIE 1931 2 Degree Standard Observer"] illuminants_filtered = filter_passthrough( - CCS_ILLUMINANTS.get(cmfs.name), illuminants # type: ignore[arg-type] + CCS_ILLUMINANTS[cmfs.name], illuminants ) - settings: Dict[str, Any] = {"uniform": True} + settings: dict[str, Any] = {"uniform": True} settings.update(kwargs) _figure, axes = artist(**settings) @@ -357,7 +351,7 @@ def plot_planckian_locus_in_chromaticity_diagram( if method == "CIE 1931": - def xy_to_ij(xy: NDArray) -> NDArray: + def xy_to_ij(xy: NDArrayFloat) -> NDArrayFloat: """ Convert given *CIE xy* chromaticity coordinates to *ij* chromaticity coordinates. @@ -368,7 +362,7 @@ def xy_to_ij(xy: NDArray) -> NDArray: bounding_box = (-0.1, 0.9, -0.1, 0.9) elif method == "CIE 1960 UCS": - def xy_to_ij(xy: NDArray) -> NDArray: + def xy_to_ij(xy: NDArrayFloat) -> NDArrayFloat: """ Convert given *CIE xy* chromaticity coordinates to *ij* chromaticity coordinates. @@ -460,12 +454,12 @@ def xy_to_ij(xy: NDArray) -> NDArray: def plot_planckian_locus_in_chromaticity_diagram_CIE1931( illuminants: Union[str, Sequence[str]], chromaticity_diagram_callable_CIE1931: Callable = ( - plot_chromaticity_diagram_CIE1931 # type: ignore[has-type] + plot_chromaticity_diagram_CIE1931 ), - annotate_kwargs: Optional[Union[Dict, List[Dict]]] = None, - plot_kwargs: Optional[Union[Dict, List[Dict]]] = None, + annotate_kwargs: Optional[Union[dict, list[dict]]] = None, + plot_kwargs: Optional[Union[dict, list[dict]]] = None, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> tuple[plt.Figure, plt.Axes]: """ Plot the *Planckian Locus* and given illuminants in *CIE 1931 Chromaticity Diagram*. @@ -539,12 +533,12 @@ def plot_planckian_locus_in_chromaticity_diagram_CIE1931( def plot_planckian_locus_in_chromaticity_diagram_CIE1960UCS( illuminants: Union[str, Sequence[str]], chromaticity_diagram_callable_CIE1960UCS: Callable = ( - plot_chromaticity_diagram_CIE1960UCS # type: ignore[has-type] + plot_chromaticity_diagram_CIE1960UCS ), - annotate_kwargs: Optional[Union[Dict, List[Dict]]] = None, - plot_kwargs: Optional[Union[Dict, List[Dict]]] = None, + annotate_kwargs: Optional[Union[dict, list[dict]]] = None, + plot_kwargs: Optional[Union[dict, list[dict]]] = None, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> tuple[plt.Figure, plt.Axes]: """ Plot the *Planckian Locus* and given illuminants in *CIE 1960 UCS Chromaticity Diagram*. diff --git a/colour/plotting/tm3018/components.py b/colour/plotting/tm3018/components.py index 8fbe8a556e..ad25e69e75 100644 --- a/colour/plotting/tm3018/components.py +++ b/colour/plotting/tm3018/components.py @@ -25,12 +25,7 @@ from colour.hints import ( Any, ArrayLike, - Boolean, - Dict, - Floating, - List, Literal, - Tuple, Union, cast, ) @@ -68,7 +63,7 @@ ) """Resources directory.""" -_COLOURS_BIN_BAR: List = [ +_COLOURS_BIN_BAR: list = [ "#A35C60", "#CC765E", "#CC8145", @@ -87,7 +82,7 @@ "#BA7A8E", ] -_COLOURS_BIN_ARROW: List = [ +_COLOURS_BIN_ARROW: list = [ "#E62828", "#E74B4B", "#FB812E", @@ -106,7 +101,7 @@ "#A74F81", ] -_COLOURS_TCS_BAR: List = [ +_COLOURS_TCS_BAR: list = [ "#F1BDCD", "#CA6183", "#573A40", @@ -212,7 +207,7 @@ @override_style() def plot_spectra_ANSIIESTM3018( specification: ColourQuality_Specification_ANSIIESTM3018, **kwargs: Any -) -> Tuple[plt.Figure, plt.Axes]: +) -> tuple[plt.Figure, plt.Axes]: """ Plot a comparison of the spectral distributions of a test emission source and a reference illuminant for *ANSI/IES TM-30-18 Colour Rendition Report*. @@ -244,7 +239,7 @@ def plot_spectra_ANSIIESTM3018( (
, <...AxesSubplot...>) """ - settings: Dict[str, Any] = dict(kwargs) + settings: dict[str, Any] = dict(kwargs) _figure, axes = artist(**settings) @@ -286,7 +281,7 @@ def plot_spectra_ANSIIESTM3018( def plot_colour_vector_graphic( specification: ColourQuality_Specification_ANSIIESTM3018, **kwargs: Any -) -> Tuple[plt.Figure, plt.Axes]: +) -> tuple[plt.Figure, plt.Axes]: """ Plot *Color Vector Graphic* according to *ANSI/IES TM-30-18 Colour Rendition Report*. @@ -318,7 +313,7 @@ def plot_colour_vector_graphic( (
, <...AxesSubplot...>) """ - settings: Dict[str, Any] = dict(kwargs) + settings: dict[str, Any] = dict(kwargs) settings["standalone"] = False # Background @@ -403,7 +398,7 @@ def plot_colour_vector_graphic( as_float_array( [ cast( - Floating, + float, specification.colorimetry_data[1][i].CAM.h, ) for i in specification.bins[j] @@ -496,12 +491,12 @@ def corner_label_and_text(label: str, text: str, ha: str, va: str): def plot_16_bin_bars( values: ArrayLike, label_template: str, - x_ticker: Boolean = False, + x_ticker: bool = False, label_orientation: Union[ Literal["Horizontal", "Vertical"], str ] = "Vertical", **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> tuple[plt.Figure, plt.Axes]: """ Plot the 16 bin bars for given values according to *ANSI/IES TM-30-18 Colour Rendition Report*. @@ -598,9 +593,9 @@ def plot_16_bin_bars( def plot_local_chroma_shifts( specification: ColourQuality_Specification_ANSIIESTM3018, - x_ticker: Boolean = False, + x_ticker: bool = False, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> tuple[plt.Figure, plt.Axes]: """ Plot the local chroma shifts according to *ANSI/IES TM-30-18 Colour Rendition Report*. @@ -634,7 +629,7 @@ def plot_local_chroma_shifts( (
, <...AxesSubplot...>) """ - settings: Dict[str, Any] = dict(kwargs) + settings: dict[str, Any] = dict(kwargs) settings["standalone"] = False _figure, axes = plot_16_bin_bars( @@ -656,9 +651,9 @@ def plot_local_chroma_shifts( def plot_local_hue_shifts( specification: ColourQuality_Specification_ANSIIESTM3018, - x_ticker: Boolean = False, + x_ticker: bool = False, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> tuple[plt.Figure, plt.Axes]: """ Plot the local hue shifts according to *ANSI/IES TM-30-18 Colour Rendition Report*. @@ -692,7 +687,7 @@ def plot_local_hue_shifts( (
, <...AxesSubplot...>) """ - settings: Dict[str, Any] = dict(kwargs) + settings: dict[str, Any] = dict(kwargs) settings["standalone"] = False _figure, axes = plot_16_bin_bars( @@ -710,9 +705,9 @@ def plot_local_hue_shifts( def plot_local_colour_fidelities( specification: ColourQuality_Specification_ANSIIESTM3018, - x_ticker: Boolean = False, + x_ticker: bool = False, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> tuple[plt.Figure, plt.Axes]: """ Plot the local colour fidelities according to *ANSI/IES TM-30-18 Colour Rendition Report*. @@ -746,7 +741,7 @@ def plot_local_colour_fidelities( (
, <...AxesSubplot...>) """ - settings: Dict[str, Any] = dict(kwargs) + settings: dict[str, Any] = dict(kwargs) settings["standalone"] = False _figure, axes = plot_16_bin_bars( @@ -764,7 +759,7 @@ def plot_local_colour_fidelities( def plot_colour_fidelity_indexes( specification: ColourQuality_Specification_ANSIIESTM3018, **kwargs: Any -) -> Tuple[plt.Figure, plt.Axes]: +) -> tuple[plt.Figure, plt.Axes]: """ Plot the local chroma shifts according to *ANSI/IES TM-30-18 Colour Rendition Report*. diff --git a/colour/plotting/tm3018/report.py b/colour/plotting/tm3018/report.py index e745bd3b4b..cdf3dc9c67 100644 --- a/colour/plotting/tm3018/report.py +++ b/colour/plotting/tm3018/report.py @@ -17,7 +17,7 @@ import matplotlib.pyplot as plt from colour.colorimetry import SpectralDistribution, sd_to_XYZ -from colour.hints import Any, Dict, Literal, Optional, Tuple, Union, cast +from colour.hints import Any, Literal, Optional, Union, cast from colour.io import SpectralDistribution_IESTM2714 from colour.models import XYZ_to_xy, XYZ_to_Luv, Luv_to_uv from colour.plotting.tm3018.components import ( @@ -64,13 +64,13 @@ ] # Full Report Size Constants -CONSTANT_REPORT_SIZE_FULL: Tuple = (8.27, 11.69) +CONSTANT_REPORT_SIZE_FULL: tuple = (8.27, 11.69) """Full report size, default to A4 paper size in inches.""" -CONSTANT_REPORT_ROW_HEIGHT_RATIOS_FULL: Tuple = (1, 2, 24, 3, 1) +CONSTANT_REPORT_ROW_HEIGHT_RATIOS_FULL: tuple = (1, 2, 24, 3, 1) """Full report size row height ratios.""" -CONSTANT_REPORT_PADDING_FULL: Dict = { +CONSTANT_REPORT_PADDING_FULL: dict = { "w_pad": 20 / 100, "h_pad": 10 / 100, "hspace": 0, @@ -82,13 +82,13 @@ """ # Intermediate Report Size Constants -CONSTANT_REPORT_SIZE_INTERMEDIATE: Tuple = (8.27, 11.69 / 2.35) +CONSTANT_REPORT_SIZE_INTERMEDIATE: tuple = (8.27, 11.69 / 2.35) """Intermediate report size, a window into A4 paper size in inches.""" -CONSTANT_REPORT_ROW_HEIGHT_RATIOS_INTERMEDIATE: Tuple = (1, 8, 1) +CONSTANT_REPORT_ROW_HEIGHT_RATIOS_INTERMEDIATE: tuple = (1, 8, 1) """Intermediate report size row height ratios.""" -CONSTANT_REPORT_PADDING_INTERMEDIATE: Dict = { +CONSTANT_REPORT_PADDING_INTERMEDIATE: dict = { "w_pad": 20 / 100, "h_pad": 10 / 100, "hspace": 0, @@ -100,13 +100,13 @@ """ # Simple Report Size Constants -CONSTANT_REPORT_SIZE_SIMPLE: Tuple = (8.27, 8.27) +CONSTANT_REPORT_SIZE_SIMPLE: tuple = (8.27, 8.27) """Simple report size, a window into A4 paper size in inches.""" -CONSTANT_REPORT_ROW_HEIGHT_RATIOS_SIMPLE: Tuple = (1, 8, 1) +CONSTANT_REPORT_ROW_HEIGHT_RATIOS_SIMPLE: tuple = (1, 8, 1) """Simple report size row height ratios.""" -CONSTANT_REPORT_PADDING_SIMPLE: Dict = { +CONSTANT_REPORT_PADDING_SIMPLE: dict = { "w_pad": 20 / 100, "h_pad": 10 / 100, "hspace": 0, @@ -117,7 +117,7 @@ and in-between the axes. """ -CONSTANTS_REPORT_STYLE: Dict = { +CONSTANTS_REPORT_STYLE: dict = { "axes.grid": False, "axes.labelpad": CONSTANTS_COLOUR_STYLE.geometry.short * 3, "axes.labelsize": "x-small", @@ -221,11 +221,11 @@ def plot_single_sd_colour_rendition_report_full( manufacturer: Optional[str] = None, model: Optional[str] = None, notes: Optional[str] = None, - report_size: Tuple = CONSTANT_REPORT_SIZE_FULL, - report_row_height_ratios: Tuple = CONSTANT_REPORT_ROW_HEIGHT_RATIOS_FULL, - report_box_padding: Optional[Dict] = None, + report_size: tuple = CONSTANT_REPORT_SIZE_FULL, + report_row_height_ratios: tuple = CONSTANT_REPORT_ROW_HEIGHT_RATIOS_FULL, + report_box_padding: Optional[dict] = None, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: # noqa: D405,D407,D410,D411 +) -> tuple[plt.Figure, plt.Axes]: # noqa: D405,D407,D410,D411 """ Generate the full *ANSI/IES TM-30-18 Colour Rendition Report* for given spectral distribution. @@ -313,7 +313,7 @@ def plot_single_sd_colour_rendition_report_full( figure = plt.figure(figsize=report_size, constrained_layout=True) - settings: Dict[str, Any] = dict(kwargs) + settings: dict[str, Any] = dict(kwargs) settings["standalone"] = False settings["tight_layout"] = False @@ -544,13 +544,13 @@ def plot_single_sd_colour_rendition_report_full( @override_style(**CONSTANTS_REPORT_STYLE) def plot_single_sd_colour_rendition_report_intermediate( sd: SpectralDistribution, - report_size: Tuple = CONSTANT_REPORT_SIZE_INTERMEDIATE, - report_row_height_ratios: Tuple = ( + report_size: tuple = CONSTANT_REPORT_SIZE_INTERMEDIATE, + report_row_height_ratios: tuple = ( CONSTANT_REPORT_ROW_HEIGHT_RATIOS_INTERMEDIATE ), - report_box_padding: Optional[Dict] = None, + report_box_padding: Optional[dict] = None, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> tuple[plt.Figure, plt.Axes]: """ Generate the intermediate *ANSI/IES TM-30-18 Colour Rendition Report* for given spectral distribution. @@ -604,7 +604,7 @@ def plot_single_sd_colour_rendition_report_intermediate( figure = plt.figure(figsize=report_size, constrained_layout=True) - settings: Dict[str, Any] = dict(kwargs) + settings: dict[str, Any] = dict(kwargs) settings["standalone"] = False settings["tight_layout"] = False @@ -649,11 +649,11 @@ def plot_single_sd_colour_rendition_report_intermediate( def plot_single_sd_colour_rendition_report_simple( sd: SpectralDistribution, - report_size: Tuple = CONSTANT_REPORT_SIZE_SIMPLE, - report_row_height_ratios: Tuple = CONSTANT_REPORT_ROW_HEIGHT_RATIOS_SIMPLE, - report_box_padding: Optional[Dict] = None, + report_size: tuple = CONSTANT_REPORT_SIZE_SIMPLE, + report_row_height_ratios: tuple = CONSTANT_REPORT_ROW_HEIGHT_RATIOS_SIMPLE, + report_box_padding: Optional[dict] = None, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> tuple[plt.Figure, plt.Axes]: """ Generate the simple *ANSI/IES TM-30-18 Colour Rendition Report* for given spectral distribution. @@ -707,7 +707,7 @@ def plot_single_sd_colour_rendition_report_simple( figure = plt.figure(figsize=report_size, constrained_layout=True) - settings: Dict[str, Any] = dict(kwargs) + settings: dict[str, Any] = dict(kwargs) settings["standalone"] = False settings["tight_layout"] = False @@ -744,7 +744,7 @@ def plot_single_sd_colour_rendition_report( sd: SpectralDistribution, method: Union[Literal["Full", "Intermediate", "Simple"], str] = "Full", **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> tuple[plt.Figure, plt.Axes]: """ Generate the *ANSI/IES TM-30-18 Colour Rendition Report* for given spectral distribution according to given method. diff --git a/colour/plotting/volume.py b/colour/plotting/volume.py index adc76ba3bc..ea2a67214a 100644 --- a/colour/plotting/volume.py +++ b/colour/plotting/volume.py @@ -23,16 +23,10 @@ from colour.hints import ( Any, ArrayLike, - Boolean, - Dict, - Floating, - Integer, - List, Literal, - NDArray, + NDArrayFloat, Optional, Sequence, - Tuple, Union, cast, ) @@ -77,11 +71,11 @@ def nadir_grid( limits: Optional[ArrayLike] = None, - segments: Integer = 10, + segments: int = 10, labels: Optional[Sequence[str]] = None, axes: Optional[plt.Axes] = None, **kwargs: Any, -) -> Tuple[NDArray, NDArray, NDArray]: +) -> tuple[NDArrayFloat, NDArrayFloat, NDArrayFloat]: """ Return a grid on *CIE xy* plane made of quad geometric elements and its associated faces and edges colours. Ticks and labels are added to the @@ -336,9 +330,9 @@ def nadir_grid( def RGB_identity_cube( - width_segments: Integer = 16, - height_segments: Integer = 16, - depth_segments: Integer = 16, + width_segments: int = 16, + height_segments: int = 16, + depth_segments: int = 16, planes: Optional[ Literal[ "-x", @@ -355,7 +349,7 @@ def RGB_identity_cube( "zy", ] ] = None, -) -> Tuple[NDArray, NDArray]: +) -> tuple[NDArrayFloat, NDArrayFloat]: """ Return an *RGB* identity cube made of quad geometric elements and its associated *RGB* colours. @@ -466,20 +460,20 @@ def plot_RGB_colourspaces_gamuts( ], str, ] = "CIE xyY", - segments: Integer = 8, - show_grid: Boolean = True, - grid_segments: Integer = 10, - show_spectral_locus: Boolean = False, + segments: int = 8, + show_grid: bool = True, + grid_segments: int = 10, + show_spectral_locus: bool = False, spectral_locus_colour: Optional[Union[ArrayLike, str]] = None, cmfs: Union[ MultiSpectralDistributions, str, Sequence[Union[MultiSpectralDistributions, str]], ] = "CIE 1931 2 Degree Standard Observer", - chromatically_adapt: Boolean = False, - convert_kwargs: Optional[Dict] = None, + chromatically_adapt: bool = False, + convert_kwargs: Optional[dict] = None, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> tuple[plt.Figure, plt.Axes]: """ Plot given *RGB* colourspaces gamuts in given reference colourspace. @@ -551,9 +545,9 @@ def plot_RGB_colourspaces_gamuts( ).get("model", model) colourspaces = cast( - List[RGB_Colourspace], + list[RGB_Colourspace], list(filter_RGB_colourspaces(colourspaces).values()), - ) + ) # pyright: ignore convert_kwargs = optional(convert_kwargs, {}) @@ -620,9 +614,9 @@ def plot_RGB_colourspaces_gamuts( plotting_colourspace = CONSTANTS_COLOUR_STYLE.colour.colourspace - quads_c: List = [] - RGB_cf: List = [] - RGB_ce: List = [] + quads_c: list = [] + RGB_cf: list = [] + RGB_ce: list = [] for i, colourspace in enumerate(colourspaces): if chromatically_adapt and not np.array_equal( @@ -750,21 +744,21 @@ def plot_RGB_scatter( colourspaces: Optional[ Union[RGB_Colourspace, str, Sequence[Union[RGB_Colourspace, str]]] ] = None, - segments: Integer = 8, - show_grid: Boolean = True, - grid_segments: Integer = 10, - show_spectral_locus: Boolean = False, + segments: int = 8, + show_grid: bool = True, + grid_segments: int = 10, + show_spectral_locus: bool = False, spectral_locus_colour: Optional[Union[ArrayLike, str]] = None, - points_size: Floating = 12, + points_size: float = 12, cmfs: Union[ MultiSpectralDistributions, str, Sequence[Union[MultiSpectralDistributions, str]], ] = "CIE 1931 2 Degree Standard Observer", - chromatically_adapt: Boolean = False, - convert_kwargs: Optional[Dict] = None, + chromatically_adapt: bool = False, + convert_kwargs: Optional[dict] = None, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> tuple[plt.Figure, plt.Axes]: """ Plot given *RGB* colourspace array in a scatter plot. @@ -832,7 +826,7 @@ def plot_RGB_scatter( RGB_Colourspace, first_item(filter_RGB_colourspaces(colourspace).values()), ) - colourspaces = cast(List[str], optional(colourspaces, [colourspace.name])) + colourspaces = cast(list[str], optional(colourspaces, [colourspace.name])) convert_kwargs = optional(convert_kwargs, {}) diff --git a/colour/quality/__init__.py b/colour/quality/__init__.py index f3c7c5b458..1d8f106d1b 100644 --- a/colour/quality/__init__.py +++ b/colour/quality/__init__.py @@ -1,7 +1,7 @@ from __future__ import annotations from colour.colorimetry import SpectralDistribution -from colour.hints import Floating, Literal, Union +from colour.hints import Literal, Union from .datasets import * # noqa from . import datasets @@ -65,7 +65,7 @@ def colour_fidelity_index( additional_data=False, method: Union[Literal["CIE 2017", "ANSI/IES TM-30-18"], str] = "CIE 2017", ) -> Union[ - Floating, + float, ColourRendering_Specification_CIE2017, ColourQuality_Specification_ANSIIESTM3018, ]: @@ -84,7 +84,7 @@ def colour_fidelity_index( Returns ------- - :class:`numpy.floating` or \ + :class:`float` or \ :class:`colour.quality.ColourRendering_Specification_CIE2017` or \ :class:`colour.quality.ColourQuality_Specification_ANSIIESTM3018` *Colour Fidelity Index* (CFI) :math:`R_f`. diff --git a/colour/quality/cfi2017.py b/colour/quality/cfi2017.py index b1c1a8bde5..da84c71f89 100644 --- a/colour/quality/cfi2017.py +++ b/colour/quality/cfi2017.py @@ -37,13 +37,8 @@ sd_CIE_illuminant_D_series, ) from colour.hints import ( - Boolean, - Dict, - Floating, - FloatingOrArrayLike, - FloatingOrNDArray, - NDArray, - Tuple, + ArrayLike, + NDArrayFloat, Union, cast, ) @@ -92,7 +87,7 @@ ) """*CIE 2017 Colour Fidelity Index* resources directory.""" -_CACHE_TCS_CIE2017: Dict = CACHE_REGISTRY.register_cache( +_CACHE_TCS_CIE2017: dict = CACHE_REGISTRY.register_cache( f"{__name__}._CACHE_TCS_CIE2017" ) @@ -102,10 +97,10 @@ class DataColorimetry_TCS_CIE2017: """Define the class storing *test colour samples* colorimetry data.""" name: str - XYZ: NDArray + XYZ: NDArrayFloat CAM: CAM_Specification_CIECAM02 - JMh: NDArray - Jpapbp: NDArray + JMh: NDArrayFloat + Jpapbp: NDArrayFloat @dataclass @@ -136,20 +131,20 @@ class ColourRendering_Specification_CIE2017: name: str sd_reference: SpectralDistribution - R_f: Floating - R_s: NDArray - CCT: Floating - D_uv: Floating - colorimetry_data: Tuple[ - Tuple[DataColorimetry_TCS_CIE2017, ...], - Tuple[DataColorimetry_TCS_CIE2017, ...], + R_f: float + R_s: NDArrayFloat + CCT: float + D_uv: float + colorimetry_data: tuple[ + tuple[DataColorimetry_TCS_CIE2017, ...], + tuple[DataColorimetry_TCS_CIE2017, ...], ] - delta_E_s: NDArray + delta_E_s: NDArrayFloat def colour_fidelity_index_CIE2017( - sd_test: SpectralDistribution, additional_data: Boolean = False -) -> Union[Floating, ColourRendering_Specification_CIE2017]: + sd_test: SpectralDistribution, additional_data: bool = False +) -> Union[float, ColourRendering_Specification_CIE2017]: """ Return the *CIE 2017 Colour Fidelity Index* (CFI) :math:`R_f` of given spectral distribution. @@ -163,7 +158,7 @@ def colour_fidelity_index_CIE2017( Returns ------- - :class:`numpy.floating` or \ + :class:`float` or \ :class:`colour.quality.ColourRendering_Specification_CIE2017` *CIE 2017 Colour Fidelity Index* (CFI) :math:`R_f`. @@ -188,7 +183,7 @@ def colour_fidelity_index_CIE2017( # NOTE: "CIE 2017 Colour Fidelity Index" standard recommends filling # missing values with zeros. - sd_test = cast(SpectralDistribution, sd_test.copy()) + sd_test = sd_test.copy() sd_test.extrapolator = Extrapolator sd_test.extrapolator_kwargs = { "method": "constant", @@ -303,7 +298,7 @@ def load_TCS_CIE2017(shape: SpectralShape) -> MultiSpectralDistributions: return tcs -def CCT_reference_illuminant(sd: SpectralDistribution) -> NDArray: +def CCT_reference_illuminant(sd: SpectralDistribution) -> NDArrayFloat: """ Compute the reference illuminant correlated colour temperature :math:`T_{cp}` and :math:`\\Delta_{uv}` for given test spectral @@ -333,7 +328,7 @@ def CCT_reference_illuminant(sd: SpectralDistribution) -> NDArray: def sd_reference_illuminant( - CCT: Floating, shape: SpectralShape + CCT: float, shape: SpectralShape ) -> SpectralDistribution: """ Compute the reference illuminant for a given correlated colour temperature @@ -400,8 +395,8 @@ def sd_reference_illuminant( elif 4000 <= CCT <= 5000: # Planckian and daylight illuminant must be normalised so that the # mixture isn't biased. - sd_planckian /= sd_to_XYZ(sd_planckian)[1] # type: ignore[misc] - sd_daylight /= sd_to_XYZ(sd_daylight)[1] # type: ignore[misc] + sd_planckian /= sd_to_XYZ(sd_planckian)[1] + sd_daylight /= sd_to_XYZ(sd_daylight)[1] # Mixture: 4200K should be 80% Planckian, 20% CIE Illuminant D Series. m = (CCT - 4000) / 1000 @@ -424,7 +419,7 @@ def tcs_colorimetry_data( sd_irradiance: SpectralDistribution, sds_tcs: MultiSpectralDistributions, cmfs: MultiSpectralDistributions, -) -> Tuple[DataColorimetry_TCS_CIE2017, ...]: +) -> tuple[DataColorimetry_TCS_CIE2017, ...]: """ Return the *test colour samples* colorimetry data under given test light source or reference illuminant spectral distribution for the @@ -463,9 +458,9 @@ def tcs_colorimetry_data( specification = XYZ_to_CIECAM02(XYZ, XYZ_w, L_A, Y_b, surround, True) JMh = tstack( [ - cast(FloatingOrNDArray, specification.J), - cast(FloatingOrNDArray, specification.M), - cast(FloatingOrNDArray, specification.h), + cast(NDArrayFloat, specification.J), + cast(NDArrayFloat, specification.M), + cast(NDArrayFloat, specification.h), ] ) Jpapbp = JMh_CIECAM02_to_CAM02UCS(JMh) @@ -479,7 +474,7 @@ def tcs_colorimetry_data( return tuple(tcs_data) -def delta_E_to_R_f(delta_E: FloatingOrArrayLike) -> FloatingOrNDArray: +def delta_E_to_R_f(delta_E: ArrayLike) -> NDArrayFloat: """ Convert from colour-appearance difference to *CIE 2017 Colour Fidelity Index* (CFI) :math:`R_f` value. @@ -491,7 +486,7 @@ def delta_E_to_R_f(delta_E: FloatingOrArrayLike) -> FloatingOrNDArray: Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Corresponding *CIE 2017 Colour Fidelity Index* (CFI) :math:`R_f` value. """ diff --git a/colour/quality/cqs.py b/colour/quality/cqs.py index 017d62d541..8c24741ea4 100644 --- a/colour/quality/cqs.py +++ b/colour/quality/cqs.py @@ -39,19 +39,7 @@ sd_blackbody, sd_to_XYZ, ) -from colour.hints import ( - ArrayLike, - Boolean, - Dict, - Floating, - Integer, - Literal, - NDArray, - Optional, - Tuple, - Union, - cast, -) +from colour.hints import ArrayLike, Literal, NDArrayFloat, Optional, Union from colour.models import ( Lab_to_LCHab, UCS_to_uv, @@ -97,7 +85,7 @@ "colour_quality_scales", ] -GAMUT_AREA_D65: Integer = 8210 +GAMUT_AREA_D65: int = 8210 """Gamut area for *CIE Illuminant D Series D65*.""" @@ -106,9 +94,9 @@ class DataColorimetry_VS: """Define the class storing *VS test colour samples* colorimetry data.""" name: str - XYZ: NDArray - Lab: NDArray - C: NDArray + XYZ: NDArrayFloat + Lab: NDArrayFloat + C: NDArrayFloat @dataclass @@ -119,10 +107,10 @@ class DataColourQualityScale_VS: """ name: str - Q_a: Floating - D_C_ab: Floating - D_E_ab: Floating - D_Ep_ab: Floating + Q_a: float + D_C_ab: float + D_E_ab: float + D_Ep_ab: float @dataclass @@ -166,18 +154,18 @@ class ColourRendering_Specification_CQS: """ name: str - Q_a: Floating - Q_f: Floating - Q_p: Optional[Floating] - Q_g: Floating - Q_d: Optional[Floating] - Q_as: Dict[Integer, DataColourQualityScale_VS] - colorimetry_data: Tuple[ - Tuple[DataColorimetry_VS, ...], Tuple[DataColorimetry_VS, ...] + Q_a: float + Q_f: float + Q_p: Optional[float] + Q_g: float + Q_d: Optional[float] + Q_as: dict[int, DataColourQualityScale_VS] + colorimetry_data: tuple[ + tuple[DataColorimetry_VS, ...], tuple[DataColorimetry_VS, ...] ] -COLOUR_QUALITY_SCALE_METHODS: Tuple = ("NIST CQS 7.4", "NIST CQS 9.0") +COLOUR_QUALITY_SCALE_METHODS: tuple = ("NIST CQS 7.4", "NIST CQS 9.0") if is_documentation_building(): # pragma: no cover COLOUR_QUALITY_SCALE_METHODS = DocstringTuple(COLOUR_QUALITY_SCALE_METHODS) COLOUR_QUALITY_SCALE_METHODS.__doc__ = """ @@ -191,11 +179,11 @@ class ColourRendering_Specification_CQS: def colour_quality_scale( sd_test: SpectralDistribution, - additional_data: Boolean = False, + additional_data: bool = False, method: Union[ Literal["NIST CQS 7.4", "NIST CQS 9.0"], str ] = "NIST CQS 9.0", -) -> Union[Floating, ColourRendering_Specification_CQS]: +) -> Union[float, ColourRendering_Specification_CQS]: """ Return the *Colour Quality Scale* (CQS) of given spectral distribution using given method. @@ -211,7 +199,7 @@ def colour_quality_scale( Returns ------- - :class:`numpy.floating` or \ + :class:`float` or \ :class:`colour.quality.ColourRendering_Specification_CQS` *Colour Quality Scale* (CQS). @@ -260,7 +248,7 @@ def colour_quality_scale( sd_reference, sd_reference, vs_sds, cmfs ) - CCT_f: Floating + CCT_f: float if method == "nist cqs 9.0": CCT_f = 1 scaling_f = 3.2 @@ -325,7 +313,7 @@ def colour_quality_scale( return Q_a -def gamut_area(Lab: ArrayLike) -> Floating: +def gamut_area(Lab: ArrayLike) -> float: """ Return the gamut area :math:`G` covered by given *CIE L\\*a\\*b\\** matrices. @@ -337,7 +325,7 @@ def gamut_area(Lab: ArrayLike) -> Floating: Returns ------- - :class:`numpy.floating` + :class:`float` Gamut area :math:`G`. Examples @@ -381,10 +369,10 @@ def gamut_area(Lab: ArrayLike) -> Floating: def vs_colorimetry_data( sd_test: SpectralDistribution, sd_reference: SpectralDistribution, - sds_vs: Dict[str, SpectralDistribution], + sds_vs: dict[str, SpectralDistribution], cmfs: MultiSpectralDistributions, - chromatic_adaptation: Boolean = False, -) -> Tuple[DataColorimetry_VS, ...]: + chromatic_adaptation: bool = False, +) -> tuple[DataColorimetry_VS, ...]: """ Return the *VS test colour samples* colorimetry data. @@ -410,12 +398,12 @@ def vs_colorimetry_data( XYZ_t = sd_to_XYZ(sd_test, cmfs) with sdiv_mode(): - XYZ_t = cast(NDArray, sdiv(XYZ_t, XYZ_t[1])) + XYZ_t = sdiv(XYZ_t, XYZ_t[1]) XYZ_r = sd_to_XYZ(sd_reference, cmfs) with sdiv_mode(): - XYZ_r = cast(NDArray, sdiv(XYZ_r, XYZ_r[1])) + XYZ_r = sdiv(XYZ_r, XYZ_r[1]) xy_r = XYZ_to_xy(XYZ_r) @@ -440,8 +428,8 @@ def vs_colorimetry_data( def CCT_factor( - reference_data: Tuple[DataColorimetry_VS, ...], XYZ_r: ArrayLike -) -> Floating: + reference_data: tuple[DataColorimetry_VS, ...], XYZ_r: ArrayLike +) -> float: """ Return the correlated colour temperature factor penalizing lamps with extremely low correlated colour temperatures. @@ -455,7 +443,7 @@ def CCT_factor( Returns ------- - :class:`numpy.floating` + :class:`float` Correlated colour temperature factor. """ @@ -478,9 +466,7 @@ def CCT_factor( return CCT_f -def scale_conversion( - D_E_ab: Floating, CCT_f: Floating, scaling_f: Floating -) -> Floating: +def scale_conversion(D_E_ab: float, CCT_f: float, scaling_f: float) -> float: """ Return the *Colour Quality Scale* (CQS) for given :math:`\\Delta E_{ab}` value and given correlated colour temperature penalizing factor. @@ -496,7 +482,7 @@ def scale_conversion( Returns ------- - :class:`numpy.floating` + :class:`float` *Colour Quality Scale* (CQS). """ @@ -506,8 +492,8 @@ def scale_conversion( def delta_E_RMS( - CQS_data: Dict[Integer, DataColourQualityScale_VS], attribute: str -) -> Floating: + CQS_data: dict[int, DataColourQualityScale_VS], attribute: str +) -> float: """ Compute the root-mean-square average for given *Colour Quality Scale* (CQS) data. @@ -522,7 +508,7 @@ def delta_E_RMS( Returns ------- - :class:`numpy.floating` + :class:`float` Root-mean-square average. """ @@ -539,11 +525,11 @@ def delta_E_RMS( def colour_quality_scales( - test_data: Tuple[DataColorimetry_VS, ...], - reference_data: Tuple[DataColorimetry_VS, ...], - scaling_f: Floating, - CCT_f: Floating, -) -> Dict[Integer, DataColourQualityScale_VS]: + test_data: tuple[DataColorimetry_VS, ...], + reference_data: tuple[DataColorimetry_VS, ...], + scaling_f: float, + CCT_f: float, +) -> dict[int, DataColourQualityScale_VS]: """ Return the *VS test colour samples* rendering scales. @@ -567,15 +553,16 @@ def colour_quality_scales( Q_as = {} for i in range(len(test_data)): - D_C_ab = test_data[i].C - reference_data[i].C + D_C_ab = as_float_scalar(test_data[i].C - reference_data[i].C) D_E_ab = as_float_scalar( euclidean_distance(test_data[i].Lab, reference_data[i].Lab) ) - if D_C_ab > 0: - D_Ep_ab = np.sqrt(D_E_ab**2 - D_C_ab**2) - else: - D_Ep_ab = D_E_ab + D_Ep_ab = ( + as_float_scalar(np.sqrt(D_E_ab**2 - D_C_ab**2)) + if D_C_ab > 0 + else D_E_ab + ) Q_a = scale_conversion(D_Ep_ab, CCT_f, scaling_f) diff --git a/colour/quality/cri.py b/colour/quality/cri.py index c1089e3add..e9a6c3826c 100644 --- a/colour/quality/cri.py +++ b/colour/quality/cri.py @@ -33,13 +33,7 @@ sd_to_XYZ, ) from colour.hints import ( - Boolean, - Dict, - Floating, - FloatingOrNDArray, - Integer, - NDArray, - Tuple, + NDArrayFloat, Union, ) from colour.models import UCS_to_uv, XYZ_to_UCS, XYZ_to_xyY @@ -69,9 +63,9 @@ class DataColorimetry_TCS: """Define the class storing *test colour samples* colorimetry data.""" name: str - XYZ: NDArray - uv: NDArray - UVW: NDArray + XYZ: NDArrayFloat + uv: NDArrayFloat + UVW: NDArrayFloat @dataclass @@ -81,7 +75,7 @@ class DataColourQualityScale_TCS: """ name: str - Q_a: Floating + Q_a: float @dataclass() @@ -106,16 +100,16 @@ class ColourRendering_Specification_CRI: """ name: str - Q_a: Floating - Q_as: Dict[Integer, DataColourQualityScale_TCS] - colorimetry_data: Tuple[ - Tuple[DataColorimetry_TCS, ...], Tuple[DataColorimetry_TCS, ...] + Q_a: float + Q_as: dict[int, DataColourQualityScale_TCS] + colorimetry_data: tuple[ + tuple[DataColorimetry_TCS, ...], tuple[DataColorimetry_TCS, ...] ] def colour_rendering_index( - sd_test: SpectralDistribution, additional_data: Boolean = False -) -> Union[Floating, ColourRendering_Specification_CRI]: + sd_test: SpectralDistribution, additional_data: bool = False +) -> Union[float, ColourRendering_Specification_CRI]: """ Return the *Colour Rendering Index* (CRI) :math:`Q_a` of given spectral distribution. @@ -129,7 +123,7 @@ def colour_rendering_index( Returns ------- - :class:`numpy.floating` or \ + :class:`float` or \ :class:`colour.quality.ColourRendering_Specification_CRI` *Colour Rendering Index* (CRI). @@ -200,10 +194,10 @@ def colour_rendering_index( def tcs_colorimetry_data( sd_t: SpectralDistribution, sd_r: SpectralDistribution, - sds_tcs: Dict[str, SpectralDistribution], + sds_tcs: dict[str, SpectralDistribution], cmfs: MultiSpectralDistributions, - chromatic_adaptation: Boolean = False, -) -> Tuple[DataColorimetry_TCS, ...]: + chromatic_adaptation: bool = False, +) -> tuple[DataColorimetry_TCS, ...]: """ Return the *test colour samples* colorimetry data. @@ -244,17 +238,13 @@ def tcs_colorimetry_data( if chromatic_adaptation: - def c( - x: FloatingOrNDArray, y: FloatingOrNDArray - ) -> FloatingOrNDArray: + def c(x: NDArrayFloat, y: NDArrayFloat) -> NDArrayFloat: """Compute the :math:`c` term.""" with sdiv_mode(): return sdiv(4 - x - 10 * y, y) - def d( - x: FloatingOrNDArray, y: FloatingOrNDArray - ) -> FloatingOrNDArray: + def d(x: NDArrayFloat, y: NDArrayFloat) -> NDArrayFloat: """Compute the :math:`d` term.""" with sdiv_mode(): @@ -287,9 +277,9 @@ def d( def colour_rendering_indexes( - test_data: Tuple[DataColorimetry_TCS, ...], - reference_data: Tuple[DataColorimetry_TCS, ...], -) -> Dict[Integer, DataColourQualityScale_TCS]: + test_data: tuple[DataColorimetry_TCS, ...], + reference_data: tuple[DataColorimetry_TCS, ...], +) -> dict[int, DataColourQualityScale_TCS]: """ Return the *test colour samples* rendering indexes :math:`Q_a`. diff --git a/colour/quality/datasets/tcs.py b/colour/quality/datasets/tcs.py index 93063e7a75..c599e33f7c 100644 --- a/colour/quality/datasets/tcs.py +++ b/colour/quality/datasets/tcs.py @@ -20,7 +20,6 @@ from __future__ import annotations from colour.colorimetry import SpectralDistribution -from colour.hints import Dict from colour.utilities import CanonicalMapping __author__ = "Colour Developers" @@ -37,7 +36,7 @@ "SDS_TCS", ] -INDEXES_TO_NAMES_TCS: Dict = { +INDEXES_TO_NAMES_TCS: dict = { 1: "TCS01", 2: "TCS02", 3: "TCS03", @@ -75,7 +74,7 @@ ) """Test colour samples *Munsell* colour approximations.""" -DATA_TCS: Dict = { +DATA_TCS: dict = { "TCS01": { 360: 0.116, 365: 0.136, diff --git a/colour/quality/datasets/vs.py b/colour/quality/datasets/vs.py index b9b88fd5c2..210f38dfd8 100644 --- a/colour/quality/datasets/vs.py +++ b/colour/quality/datasets/vs.py @@ -31,7 +31,6 @@ from __future__ import annotations from colour.colorimetry import SpectralDistribution -from colour.hints import Dict from colour.utilities import CanonicalMapping __author__ = "Colour Developers" @@ -49,7 +48,7 @@ "SDS_VS", ] -INDEXES_TO_NAMES_VS: Dict = { +INDEXES_TO_NAMES_VS: dict = { 1: "VS1", 2: "VS2", 3: "VS3", @@ -114,7 +113,7 @@ ) """*NIST CQS 9.0* test colour samples *Munsell* colour approximations.""" -DATA_VS: Dict = { +DATA_VS: dict = { "NIST CQS 7.4": { "VS1": { 380: 0.1086, diff --git a/colour/quality/ssi.py b/colour/quality/ssi.py index 485154933c..46c3567679 100644 --- a/colour/quality/ssi.py +++ b/colour/quality/ssi.py @@ -20,8 +20,8 @@ from colour.algebra import LinearInterpolator, sdiv, sdiv_mode from colour.colorimetry import SpectralDistribution, SpectralShape, reshape_sd -from colour.hints import NDArray, Optional, cast -from colour.utilities import zeros +from colour.hints import NDArrayFloat, Optional +from colour.utilities import as_float_scalar, zeros __author__ = "Colour Developers" __copyright__ = "Copyright 2013 Colour Developers" @@ -40,12 +40,12 @@ _SPECTRAL_SHAPE_SSI_LARGE: SpectralShape = SpectralShape(380, 670, 10) -_MATRIX_INTEGRATION: Optional[NDArray] = None +_MATRIX_INTEGRATION: Optional[NDArrayFloat] = None def spectral_similarity_index( sd_test: SpectralDistribution, sd_reference: SpectralDistribution -) -> NDArray: +) -> float: """ Return the *Academy Spectral Similarity Index* (SSI) of given test spectral distribution with given reference spectral distribution. @@ -106,10 +106,7 @@ def spectral_similarity_index( with sdiv_mode(): test_i = sdiv(test_i, np.sum(test_i)) reference_i = sdiv(reference_i, np.sum(reference_i)) - dr_i = cast( - NDArray, - sdiv(test_i - reference_i, reference_i + np.mean(reference_i)), - ) + dr_i = sdiv(test_i - reference_i, reference_i + np.mean(reference_i)) wdr_i = dr_i * [ 12 / 45, @@ -148,4 +145,4 @@ def spectral_similarity_index( SSI = np.around(100 - 32 * np.sqrt(m_v)) - return SSI + return as_float_scalar(SSI) diff --git a/colour/quality/tests/test_cfi2017.py b/colour/quality/tests/test_cfi2017.py index cf012d0916..595d28e5c7 100644 --- a/colour/quality/tests/test_cfi2017.py +++ b/colour/quality/tests/test_cfi2017.py @@ -19,7 +19,6 @@ reshape_sd, sd_blackbody, ) -from colour.hints import Dict from colour.quality.cfi2017 import ( CCT_reference_illuminant, sd_reference_illuminant, @@ -44,7 +43,7 @@ "TestSdReferenceIlluminant", ] -DATA_SD_SAMPLE_5NM: Dict = { +DATA_SD_SAMPLE_5NM: dict = { 380: 0.000, 385: 0.000, 390: 0.001, @@ -130,7 +129,7 @@ SD_SAMPLE_5NM: SpectralDistribution = SpectralDistribution(DATA_SD_SAMPLE_5NM) -DATA_SD_SAMPLE_1NM: Dict = { +DATA_SD_SAMPLE_1NM: dict = { 380: 0.000, 381: 0.000, 382: 0.000, diff --git a/colour/quality/tests/test_cri.py b/colour/quality/tests/test_cri.py index 4f468199e8..3a89b1c63f 100644 --- a/colour/quality/tests/test_cri.py +++ b/colour/quality/tests/test_cri.py @@ -7,7 +7,6 @@ import unittest from colour.colorimetry import SDS_ILLUMINANTS, SpectralDistribution -from colour.hints import Dict from colour.quality import ( ColourRendering_Specification_CRI, colour_rendering_index, @@ -25,7 +24,7 @@ "TestColourRenderingIndex", ] -DATA_SAMPLE: Dict = { +DATA_SAMPLE: dict = { 380: 0.00588346, 385: 0.00315377, 390: 0.00242868, diff --git a/colour/quality/tests/test_ssi.py b/colour/quality/tests/test_ssi.py index ce3de492f2..35b01266d0 100644 --- a/colour/quality/tests/test_ssi.py +++ b/colour/quality/tests/test_ssi.py @@ -6,7 +6,6 @@ import unittest from colour.colorimetry import SDS_ILLUMINANTS, SpectralDistribution -from colour.hints import Dict from colour.quality import spectral_similarity_index __author__ = "Colour Developers" @@ -20,7 +19,7 @@ "TestSpectralSimilarityIndex", ] -DATA_HMI: Dict = { +DATA_HMI: dict = { 300: 0.000000000000000, 301: 0.000000000000000, 302: 0.000000000000000, diff --git a/colour/quality/tm3018.py b/colour/quality/tm3018.py index 0a4b1321de..836f33269a 100644 --- a/colour/quality/tm3018.py +++ b/colour/quality/tm3018.py @@ -23,11 +23,7 @@ from colour.colorimetry import SpectralDistribution from colour.hints import ( ArrayLike, - Boolean, - Floating, - List, - NDArray, - Tuple, + NDArrayFloat, Union, cast, ) @@ -67,7 +63,7 @@ class ColourQuality_Specification_ANSIIESTM3018: R_g Gamut index :math:`R_g`. bins - List of 16 lists, each containing the indexes of colour samples that + list of 16 lists, each containing the indexes of colour samples that lie in the respective hue bin. averages_test Averages of *CAM02-UCS* a', b' coordinates for each hue bin for test @@ -87,28 +83,28 @@ class ColourQuality_Specification_ANSIIESTM3018: name: str sd_test: SpectralDistribution sd_reference: SpectralDistribution - R_f: Floating - R_s: NDArray - CCT: Floating - D_uv: Floating - colorimetry_data: Tuple[ - Tuple[DataColorimetry_TCS_CIE2017, ...], - Tuple[DataColorimetry_TCS_CIE2017, ...], + R_f: float + R_s: NDArrayFloat + CCT: float + D_uv: float + colorimetry_data: tuple[ + tuple[DataColorimetry_TCS_CIE2017, ...], + tuple[DataColorimetry_TCS_CIE2017, ...], ] - R_g: Floating - bins: List[List[int]] - averages_test: NDArray - averages_reference: NDArray - average_norms: NDArray - R_fs: NDArray - R_cs: NDArray - R_hs: NDArray + R_g: float + bins: list[list[int]] + averages_test: NDArrayFloat + averages_reference: NDArrayFloat + average_norms: NDArrayFloat + R_fs: NDArrayFloat + R_cs: NDArrayFloat + R_hs: NDArrayFloat def colour_fidelity_index_ANSIIESTM3018( - sd_test: SpectralDistribution, additional_data: Boolean = False + sd_test: SpectralDistribution, additional_data: bool = False ) -> Union[ - Floating, + float, ColourQuality_Specification_ANSIIESTM3018, ColourRendering_Specification_CIE2017, ]: @@ -125,7 +121,7 @@ def colour_fidelity_index_ANSIIESTM3018( Returns ------- - :class:`numpy.floating` or \ + :class:`float` or \ :class:`colour.quality.ColourQuality_Specification_ANSIIESTM3018` *ANSI/IES TM-30-18 Colour Fidelity Index* (CFI). @@ -144,18 +140,15 @@ def colour_fidelity_index_ANSIIESTM3018( if not additional_data: return colour_fidelity_index_CIE2017(sd_test, False) - specification: ( - ColourRendering_Specification_CIE2017 - ) = colour_fidelity_index_CIE2017( - sd_test, True - ) # type: ignore[assignment] + specification = cast( + ColourRendering_Specification_CIE2017, + colour_fidelity_index_CIE2017(sd_test, True), + ) # Setup bins based on where the reference a'b' points are located. - bins: List[List[int]] = [[] for _i in range(16)] + bins: list[list[int]] = [[] for _i in range(16)] for i, sample in enumerate(specification.colorimetry_data[1]): - bin_index = as_int_scalar( - np.floor(cast(Floating, sample.CAM.h) / 22.5) - ) + bin_index = as_int_scalar(np.floor(cast(float, sample.CAM.h) / 22.5)) bins[bin_index].append(i) # Per-bin a'b' averages. @@ -219,7 +212,7 @@ def colour_fidelity_index_ANSIIESTM3018( ) -def averages_area(averages: ArrayLike) -> Floating: +def averages_area(averages: ArrayLike) -> float: """ Compute the area of the polygon formed by the hue bin averages. @@ -230,7 +223,7 @@ def averages_area(averages: ArrayLike) -> Floating: Returns ------- - :class:`numpy.floating` + :class:`float` Area of the polygon. """ diff --git a/colour/recovery/__init__.py b/colour/recovery/__init__.py index b0b78f30b9..6840530c23 100644 --- a/colour/recovery/__init__.py +++ b/colour/recovery/__init__.py @@ -563,7 +563,7 @@ def __getattr__(self, attribute) -> Any: """Defines the *colour.recovery* sub-package API changes.""" if not is_documentation_building(): - sys.modules["colour.recovery"] = recovery( # type: ignore[assignment] + sys.modules["colour.recovery"] = recovery( # pyright: ignore sys.modules["colour.recovery"], build_API_changes(API_CHANGES) ) diff --git a/colour/recovery/datasets/dyer2017.py b/colour/recovery/datasets/dyer2017.py index 38472f91a0..1e4d9ea64f 100644 --- a/colour/recovery/datasets/dyer2017.py +++ b/colour/recovery/datasets/dyer2017.py @@ -16,7 +16,7 @@ import numpy as np from colour.colorimetry import SpectralShape -from colour.hints import NDArray +from colour.hints import NDArrayFloat __author__ = "Colour Developers" __copyright__ = "Copyright 2013 Colour Developers" @@ -38,7 +38,7 @@ Spectral shape of the *Dyer et al. (2017)* basis functions. """ -BASIS_FUNCTIONS_DYER2017: NDArray = np.array( +BASIS_FUNCTIONS_DYER2017: NDArrayFloat = np.array( [ [ [0.007056580228771, 0.004260510453546, 0.012005618620200], diff --git a/colour/recovery/datasets/mallett2019.py b/colour/recovery/datasets/mallett2019.py index db99948d90..0503d8dbf1 100644 --- a/colour/recovery/datasets/mallett2019.py +++ b/colour/recovery/datasets/mallett2019.py @@ -17,7 +17,7 @@ import numpy as np from colour.colorimetry import MultiSpectralDistributions, SpectralShape -from colour.hints import NDArray +from colour.hints import NDArrayFloat __author__ = "Colour Developers" __copyright__ = "Copyright 2013 Colour Developers" @@ -42,7 +42,7 @@ :cite:`Mallett2019` """ -DATA_BASIS_FUNCTIONS_sRGB_MALLETT2019: NDArray = np.array( +DATA_BASIS_FUNCTIONS_sRGB_MALLETT2019: NDArrayFloat = np.array( [ [0.32745741382705500, 0.33186171308587400, 0.34068079154805200], [0.32375057827054100, 0.32968818775939900, 0.34656118662485200], diff --git a/colour/recovery/datasets/otsu2018.py b/colour/recovery/datasets/otsu2018.py index 3eec080745..a105bb3ff5 100644 --- a/colour/recovery/datasets/otsu2018.py +++ b/colour/recovery/datasets/otsu2018.py @@ -17,7 +17,7 @@ import numpy as np from colour.colorimetry import SpectralShape -from colour.hints import NDArray +from colour.hints import NDArrayFloat __author__ = "Colour Developers" __copyright__ = "Copyright 2013 Colour Developers" @@ -42,7 +42,7 @@ :cite:`Otsu2018` """ -BASIS_FUNCTIONS_OTSU2018: NDArray = np.array( +BASIS_FUNCTIONS_OTSU2018: NDArrayFloat = np.array( [ [ [ @@ -985,7 +985,7 @@ :cite:`Otsu2018` """ -CLUSTER_MEANS_OTSU2018: NDArray = np.array( +CLUSTER_MEANS_OTSU2018: NDArrayFloat = np.array( [ [ 0.10085069182389943000, @@ -1304,7 +1304,7 @@ :cite:`Otsu2018` """ -SELECTOR_ARRAY_OTSU2018: NDArray = np.array( +SELECTOR_ARRAY_OTSU2018: NDArrayFloat = np.array( [ [0.333444973048471, 1, -3, -1], [0.428556829741043, 0, 1, -2], @@ -1313,7 +1313,7 @@ [0.464102042665547, 0, 2, 6], [0.288243127874986, 0, 0, -6], [0.247072787814766, 1, 3, 4], - ] + ] # pyright: ignore ) """ Array describing how to select the appropriate cluster for given *CIE xy* diff --git a/colour/recovery/datasets/smits1999.py b/colour/recovery/datasets/smits1999.py index 991d346211..d60e9d059a 100644 --- a/colour/recovery/datasets/smits1999.py +++ b/colour/recovery/datasets/smits1999.py @@ -15,7 +15,6 @@ from colour.algebra import LinearInterpolator from colour.colorimetry.spectrum import SpectralDistribution -from colour.hints import Dict from colour.utilities import CanonicalMapping __author__ = "Colour Developers" @@ -30,7 +29,7 @@ "SDS_SMITS1999", ] -DATA_SMITS1999: Dict = { +DATA_SMITS1999: dict = { "white": { 380.0000: 1.0000, 417.7778: 1.0000, diff --git a/colour/recovery/jakob2019.py b/colour/recovery/jakob2019.py index 1db32fd3d0..de382f5388 100644 --- a/colour/recovery/jakob2019.py +++ b/colour/recovery/jakob2019.py @@ -37,14 +37,9 @@ from colour.difference import JND_CIE1976 from colour.hints import ( ArrayLike, - Boolean, Callable, - Dict, - Floating, - Integer, - NDArray, + NDArrayFloat, Optional, - Tuple, Union, ) from colour.models import RGB_Colourspace, XYZ_to_xy, XYZ_to_Lab, RGB_to_XYZ @@ -104,12 +99,12 @@ class StopMinimizationEarly(Exception): - :attr:`~colour.recovery.jakob2019.StopMinimizationEarly.error` """ - def __init__(self, coefficients: ArrayLike, error: Floating) -> None: + def __init__(self, coefficients: ArrayLike, error: float) -> None: self._coefficients = as_float_array(coefficients) self._error = as_float_scalar(error) @property - def coefficients(self) -> NDArray: + def coefficients(self) -> NDArrayFloat: """ Getter property for the *Jakob and Hanika (2019)* exception coefficients. @@ -123,14 +118,14 @@ def coefficients(self) -> NDArray: return self._coefficients @property - def error(self) -> Floating: + def error(self) -> float: """ Getter property for the *Jakob and Hanika (2019)* exception error value. Returns ------- - :class:`numpy.floating` + :class:`float` *Jakob and Hanika (2019)* exception coefficients. """ @@ -205,11 +200,11 @@ def error_function( target: ArrayLike, cmfs: MultiSpectralDistributions, illuminant: SpectralDistribution, - max_error: Optional[Floating] = None, - additional_data: Boolean = False, + max_error: Optional[float] = None, + additional_data: bool = False, ) -> Union[ - Tuple[Floating, NDArray], - Tuple[Floating, NDArray, NDArray, NDArray, NDArray], + tuple[float, NDArrayFloat], + tuple[float, NDArrayFloat, NDArrayFloat, NDArrayFloat, NDArrayFloat], ]: """ Compute :math:`\\Delta E_{76}` between the target colour and the colour @@ -236,7 +231,7 @@ def error_function( Returns ------- :class:`tuple` or :class:`tuple` - Tuple of computed :math:`\\Delta E_{76}` error and gradient of error, + tuple of computed :math:`\\Delta E_{76}` error and gradient of error, i.e. the first derivatives of error with respect to the input coefficients or tuple of computed :math:`\\Delta E_{76}` error, gradient of error, computed spectral reflectance, *CIE XYZ* tristimulus @@ -280,8 +275,8 @@ def error_function( ) def intermediate_XYZ_to_Lab( - XYZ_i: NDArray, offset: Optional[Floating] = 16 - ) -> NDArray: + XYZ_i: NDArrayFloat, offset: Optional[float] = 16 + ) -> NDArrayFloat: """ Return the final intermediate value for the *CIE Lab* to *CIE XYZ* conversion. @@ -314,7 +309,7 @@ def intermediate_XYZ_to_Lab( def dimensionalise_coefficients( coefficients: ArrayLike, shape: SpectralShape -) -> NDArray: +) -> NDArrayFloat: """ Rescale the dimensionless coefficients to given spectral shape. @@ -351,7 +346,7 @@ def dimensionalise_coefficients( return np.array([c_0, c_1, c_2]) -def lightness_scale(steps: Integer) -> NDArray: +def lightness_scale(steps: int) -> NDArrayFloat: """ Create a non-linear lightness scale, as described in *Jakob and Hanika (2019)*. The spacing between very dark and very bright (and saturated) @@ -385,9 +380,9 @@ def find_coefficients_Jakob2019( cmfs: Optional[MultiSpectralDistributions] = None, illuminant: Optional[SpectralDistribution] = None, coefficients_0: ArrayLike = zeros(3), - max_error: Floating = JND_CIE1976 / 100, - dimensionalise: Boolean = True, -) -> Tuple[NDArray, Floating]: + max_error: float = JND_CIE1976 / 100, + dimensionalise: bool = True, +) -> tuple[NDArrayFloat, float]: """ Compute the coefficients for *Jakob and Hanika (2019)* reflectance spectral model. @@ -415,7 +410,7 @@ def find_coefficients_Jakob2019( Returns ------- :class:`tuple` - Tuple of computed coefficients that best fit the given colour and + tuple of computed coefficients that best fit the given colour and :math:`\\Delta E_{76}` between the target colour and the colour corresponding to the computed coefficients. @@ -431,6 +426,7 @@ def find_coefficients_Jakob2019( 0.0141941...) """ + XYZ = as_float_array(XYZ) coefficients_0 = as_float_array(coefficients_0) cmfs, illuminant = handle_spectral_arguments( @@ -438,8 +434,8 @@ def find_coefficients_Jakob2019( ) def optimize( - target_o: NDArray, coefficients_0_o: NDArray - ) -> Tuple[NDArray, Floating]: + target_o: ArrayLike, coefficients_0_o: ArrayLike + ) -> tuple[NDArrayFloat, float]: """Minimise the error function using *L-BFGS-B* method.""" try: @@ -457,13 +453,13 @@ def optimize( xy_n = XYZ_to_xy(sd_to_XYZ_integration(illuminant, cmfs)) - XYZ_good = full(3, 0.5) - coefficients_good = zeros(3) + XYZ_g = full(3, 0.5) + coefficients_g = zeros(3) divisions = 3 while divisions < 10: - XYZ_r = XYZ_good - coefficient_r = coefficients_good + XYZ_r = XYZ_g + coefficient_r = coefficients_g keep_divisions = False coefficients_0 = coefficient_r @@ -476,8 +472,8 @@ def optimize( if error > max_error: break else: - XYZ_good = XYZ_i - coefficients_good = coefficients_0 + XYZ_g = XYZ_i + coefficients_g = coefficients_0 keep_divisions = True else: break @@ -498,9 +494,9 @@ def XYZ_to_sd_Jakob2019( XYZ: ArrayLike, cmfs: Optional[MultiSpectralDistributions] = None, illuminant: Optional[SpectralDistribution] = None, - optimisation_kwargs: Optional[Dict] = None, - additional_data: Boolean = False, -) -> Union[Tuple[SpectralDistribution, Floating], SpectralDistribution]: + optimisation_kwargs: Optional[dict] = None, + additional_data: bool = False, +) -> Union[tuple[SpectralDistribution, float], SpectralDistribution]: """ Recover the spectral distribution of given RGB colourspace array using *Jakob and Hanika (2019)* method. @@ -525,7 +521,7 @@ def XYZ_to_sd_Jakob2019( Returns ------- :class:`tuple` or :class:`colour.SpectralDistribution` - Tuple of recovered spectral distribution and :math:`\\Delta E_{76}` + tuple of recovered spectral distribution and :math:`\\Delta E_{76}` between the target colour and the colour corresponding to the computed coefficients or recovered spectral distribution. @@ -740,26 +736,26 @@ class LUT3D_Jakob2019: def __init__(self) -> None: self._interpolator: Optional[RegularGridInterpolator] = None - self._size: Integer = 0 - self._lightness_scale: NDArray = np.array([]) - self._coefficients: NDArray = np.array([]) + self._size: int = 0 + self._lightness_scale: NDArrayFloat = np.array([]) + self._coefficients: NDArrayFloat = np.array([]) @property - def size(self) -> Integer: + def size(self) -> int: """ Getter property for the *Jakob and Hanika (2019)* interpolator size, i.e. the samples count on one side of the 3D table. Returns ------- - :class:`numpy.integer` + :class:`int` *Jakob and Hanika (2019)* interpolator size. """ return self._size @property - def lightness_scale(self) -> NDArray: + def lightness_scale(self) -> NDArrayFloat: """ Getter property for the *Jakob and Hanika (2019)* interpolator lightness scale. @@ -773,7 +769,7 @@ def lightness_scale(self) -> NDArray: return self._lightness_scale @property - def coefficients(self) -> NDArray: + def coefficients(self) -> NDArrayFloat: """ Getter property for the *Jakob and Hanika (2019)* interpolator coefficients. @@ -817,7 +813,7 @@ def generate( colourspace: RGB_Colourspace, cmfs: Optional[MultiSpectralDistributions] = None, illuminant: Optional[SpectralDistribution] = None, - size: Integer = 64, + size: int = 64, print_callable: Callable = print, ): """ @@ -916,7 +912,9 @@ def generate( print_callable(f"\nOptimising {total_coefficients} coefficients...\n") - def optimize(ijkL: ArrayLike, coefficients_0: ArrayLike) -> NDArray: + def optimize( + ijkL: ArrayLike, coefficients_0: ArrayLike + ) -> NDArrayFloat: """ Solve for a specific lightness and stores the result in the appropriate cell. @@ -972,7 +970,7 @@ def optimize(ijkL: ArrayLike, coefficients_0: ArrayLike) -> NDArray: self._size = size self._create_interpolator() - def RGB_to_coefficients(self, RGB: ArrayLike) -> NDArray: + def RGB_to_coefficients(self, RGB: ArrayLike) -> NDArrayFloat: """ Look up a given *RGB* colourspace array and return corresponding coefficients. Interpolation is used for colours not on the table grid. @@ -1188,7 +1186,7 @@ def read(self, path: str) -> LUT3D_Jakob2019: return self - def write(self, path: str) -> Boolean: + def write(self, path: str) -> bool: """ Write the lookup table to a *\\*.coeff* file. diff --git a/colour/recovery/jiang2013.py b/colour/recovery/jiang2013.py index 1770042302..42ce1c7ff3 100644 --- a/colour/recovery/jiang2013.py +++ b/colour/recovery/jiang2013.py @@ -32,12 +32,9 @@ ) from colour.hints import ( ArrayLike, - Boolean, - Integer, Mapping, - NDArray, + NDArrayFloat, Optional, - Tuple, Union, cast, ) @@ -61,11 +58,14 @@ def PCA_Jiang2013( msds_camera_sensitivities: Mapping[str, MultiSpectralDistributions], - eigen_w_v_count: Optional[Integer] = None, - additional_data: Boolean = False, + eigen_w_v_count: Optional[int] = None, + additional_data: bool = False, ) -> Union[ - Tuple[Tuple[NDArray, NDArray, NDArray], Tuple[NDArray, NDArray, NDArray]], - Tuple[NDArray, NDArray, NDArray], + tuple[ + tuple[NDArrayFloat, NDArrayFloat, NDArrayFloat], + tuple[NDArrayFloat, NDArrayFloat, NDArrayFloat], + ], + tuple[NDArrayFloat, NDArrayFloat, NDArrayFloat], ]: """ Perform the *Principal Component Analysis* (PCA) on given camera *RGB* @@ -84,7 +84,7 @@ def PCA_Jiang2013( Returns ------- :class:`tuple` - Tuple of camera *RGB* sensitivities eigen-values :math:`w` and + tuple of camera *RGB* sensitivities eigen-values :math:`w` and eigen-vectors :math:`v` or tuple of camera *RGB* sensitivities eigen-vectors :math:`v`. @@ -105,7 +105,7 @@ def PCA_Jiang2013( def normalised_sensitivity( msds: MultiSpectralDistributions, channel: str - ) -> NDArray: + ) -> NDArrayFloat: """Return a normalised camera *RGB* sensitivity.""" sensitivity = cast(SpectralDistribution, msds.signals[channel].copy()) @@ -405,8 +405,6 @@ def RGB_to_msds_camera_sensitivities_Jiang2013( msds_camera_sensitivities = RGB_CameraSensitivities([S_R, S_G, S_B]) - msds_camera_sensitivities /= np.max( # type: ignore[misc] - msds_camera_sensitivities.values - ) + msds_camera_sensitivities /= np.max(msds_camera_sensitivities.values) return msds_camera_sensitivities diff --git a/colour/recovery/mallett2019.py b/colour/recovery/mallett2019.py index ea60b006fe..174c8afe88 100644 --- a/colour/recovery/mallett2019.py +++ b/colour/recovery/mallett2019.py @@ -27,7 +27,7 @@ handle_spectral_arguments, ) from colour.models import RGB_Colourspace -from colour.hints import ArrayLike, Callable, Dict, Optional, Tuple +from colour.hints import ArrayLike, Callable, Optional from colour.recovery import MSDS_BASIS_FUNCTIONS_sRGB_MALLETT2019 from colour.utilities import to_domain_1 @@ -49,8 +49,8 @@ def spectral_primary_decomposition_Mallett2019( cmfs: Optional[MultiSpectralDistributions] = None, illuminant: Optional[SpectralDistribution] = None, metric: Callable = np.linalg.norm, - metric_args: Tuple = tuple(), - optimisation_kwargs: Optional[Dict] = None, + metric_args: tuple = tuple(), + optimisation_kwargs: Optional[dict] = None, ) -> MultiSpectralDistributions: """ Perform the spectral primary decomposition as described in *Mallett and diff --git a/colour/recovery/meng2015.py b/colour/recovery/meng2015.py index 2ab6803f74..12dfc43b0d 100644 --- a/colour/recovery/meng2015.py +++ b/colour/recovery/meng2015.py @@ -27,7 +27,7 @@ sd_ones, sd_to_XYZ_integration, ) -from colour.hints import ArrayLike, Dict, FloatingOrNDArray, NDArray, Optional +from colour.hints import ArrayLike, NDArrayFloat, Optional, cast from colour.utilities import to_domain_1, from_range_100 __author__ = "Colour Developers" @@ -53,7 +53,7 @@ def XYZ_to_sd_Meng2015( XYZ: ArrayLike, cmfs: Optional[MultiSpectralDistributions] = None, illuminant: Optional[SpectralDistribution] = None, - optimisation_kwargs: Optional[Dict] = None, + optimisation_kwargs: Optional[dict] = None, ) -> SpectralDistribution: """ Recover the spectral distribution of given *CIE XYZ* tristimulus values @@ -172,12 +172,12 @@ def XYZ_to_sd_Meng2015( sd = sd_ones(cmfs.shape) - def objective_function(a: ArrayLike) -> FloatingOrNDArray: + def objective_function(a: ArrayLike) -> NDArrayFloat: """Define the objective function.""" - return np.sum(np.diff(a) ** 2) + return cast(NDArrayFloat, np.sum(np.diff(a) ** 2)) - def constraint_function(a: ArrayLike) -> NDArray: + def constraint_function(a: ArrayLike) -> NDArrayFloat: """Define the constraint function.""" sd[:] = a diff --git a/colour/recovery/otsu2018.py b/colour/recovery/otsu2018.py index 68846b7eb9..36ee0e3f26 100644 --- a/colour/recovery/otsu2018.py +++ b/colour/recovery/otsu2018.py @@ -34,15 +34,10 @@ from colour.hints import ( Any, ArrayLike, - Boolean, Callable, - Dict, - Floating, - Integer, - List, - NDArray, + NDArrayFloat, Optional, - Tuple, + Self, cast, ) from colour.models import XYZ_to_xy @@ -157,20 +152,20 @@ class Dataset_Otsu2018: def __init__( self, shape: Optional[SpectralShape] = None, - basis_functions: Optional[NDArray] = None, - means: Optional[NDArray] = None, - selector_array: Optional[NDArray] = None, + basis_functions: Optional[NDArrayFloat] = None, + means: Optional[NDArrayFloat] = None, + selector_array: Optional[NDArrayFloat] = None, ) -> None: self._shape: Optional[SpectralShape] = shape - self._basis_functions: Optional[NDArray] = ( + self._basis_functions: Optional[NDArrayFloat] = ( basis_functions if basis_functions is None else as_float_array(basis_functions) ) - self._means: Optional[NDArray] = ( + self._means: Optional[NDArrayFloat] = ( means if means is None else as_float_array(means) ) - self._selector_array: Optional[NDArray] = ( + self._selector_array: Optional[NDArrayFloat] = ( selector_array if selector_array is None else as_float_array(selector_array) @@ -190,7 +185,7 @@ def shape(self) -> Optional[SpectralShape]: return self._shape @property - def basis_functions(self) -> Optional[NDArray]: + def basis_functions(self) -> Optional[NDArrayFloat]: """ Getter property for the basis functions of the *Otsu et al. (2018)* dataset. @@ -204,7 +199,7 @@ def basis_functions(self) -> Optional[NDArray]: return self._basis_functions @property - def means(self) -> Optional[NDArray]: + def means(self) -> Optional[NDArrayFloat]: """ Getter property for means of the *Otsu et al. (2018)* dataset. @@ -217,7 +212,7 @@ def means(self) -> Optional[NDArray]: return self._means @property - def selector_array(self) -> Optional[NDArray]: + def selector_array(self) -> Optional[NDArrayFloat]: """ Getter property for the selector array of the *Otsu et al. (2018)* dataset. @@ -248,7 +243,7 @@ def __str__(self) -> str: else: return f"{self.__class__.__name__}()" - def select(self, xy: ArrayLike) -> Integer: + def select(self, xy: ArrayLike) -> int: """ Return the cluster index appropriate for the given *CIE xy* coordinates. @@ -260,7 +255,7 @@ def select(self, xy: ArrayLike) -> Integer: Returns ------- - :class:`numpy.integer` + :class:`int` Cluster index. Raises @@ -289,7 +284,7 @@ def select(self, xy: ArrayLike) -> Integer: else: raise ValueError('The "selector array" is undefined!') - def cluster(self, xy: ArrayLike) -> Tuple[NDArray, NDArray]: + def cluster(self, xy: ArrayLike) -> tuple[NDArrayFloat, NDArrayFloat]: """ Return the basis functions and dataset mean for the given *CIE xy* coordinates. @@ -302,7 +297,7 @@ def cluster(self, xy: ArrayLike) -> Tuple[NDArray, NDArray]: Returns ------- :class:`tuple` - Tuple of three basis functions and dataset mean. + tuple of three basis functions and dataset mean. Raises ------ @@ -404,9 +399,9 @@ def write(self, path: str): self._shape.interval, ] ), - basis_functions=cast(NDArray, self._basis_functions), - means=cast(NDArray, self._means), - selector_array=cast(NDArray, self._selector_array), + basis_functions=cast(NDArrayFloat, self._basis_functions), + means=cast(NDArrayFloat, self._means), + selector_array=cast(NDArrayFloat, self._selector_array), ) else: raise ValueError('The "shape" is undefined!') @@ -430,7 +425,7 @@ def XYZ_to_sd_Otsu2018( cmfs: Optional[MultiSpectralDistributions] = None, illuminant: Optional[SpectralDistribution] = None, dataset: Dataset_Otsu2018 = DATASET_REFERENCE_OTSU2018, - clip: Boolean = True, + clip: bool = True, ) -> SpectralDistribution: """ Recover the spectral distribution of given *CIE XYZ* tristimulus values @@ -590,8 +585,8 @@ class PartitionAxis: - :meth:`~colour.recovery.otsu2018.PartitionAxis.__str__` """ - origin: Floating - direction: Integer + origin: float + direction: int def __str__(self) -> str: """ @@ -658,22 +653,21 @@ def __init__( self._cmfs: MultiSpectralDistributions = cmfs self._illuminant: SpectralDistribution = illuminant - self._XYZ: Optional[NDArray] = None - self._xy: Optional[NDArray] = None - # TODO: Remove pragma when https://github.com/python/mypy/issues/3004 - # is resolved. - self._reflectances: NDArray = np.array([]) - self.reflectances = reflectances # type: ignore[assignment] + self._XYZ: Optional[NDArrayFloat] = None + self._xy: Optional[NDArrayFloat] = None - self._basis_functions: Optional[NDArray] = None - self._mean: Optional[NDArray] = None - self._M: Optional[NDArray] = None - self._XYZ_mu: Optional[NDArray] = None + self._reflectances: Optional[NDArrayFloat] = np.array([]) + self.reflectances = reflectances - self._reconstruction_error: Optional[Floating] = None + self._basis_functions: Optional[NDArrayFloat] = None + self._mean: Optional[NDArrayFloat] = None + self._M: Optional[NDArrayFloat] = None + self._XYZ_mu: Optional[NDArrayFloat] = None + + self._reconstruction_error: Optional[float] = None @property - def reflectances(self) -> NDArray: + def reflectances(self) -> Optional[NDArrayFloat]: """ Getter and setter property for the reference reflectances. @@ -691,7 +685,7 @@ def reflectances(self) -> NDArray: return self._reflectances @reflectances.setter - def reflectances(self, value: ArrayLike): + def reflectances(self, value: Optional[ArrayLike]): """Setter for the **self.reflectances** property.""" if value is not None: @@ -736,7 +730,7 @@ def illuminant(self) -> SpectralDistribution: return self._illuminant @property - def basis_functions(self) -> Optional[NDArray]: + def basis_functions(self) -> Optional[NDArrayFloat]: """ Getter property for the basis functions. @@ -749,13 +743,13 @@ def basis_functions(self) -> Optional[NDArray]: return self._basis_functions @property - def mean(self) -> Optional[NDArray]: + def mean(self) -> Optional[NDArrayFloat]: """ Getter property for the mean distribution. Returns ------- - :class:`numpy.floating` + :py:data:`None` or :class:`numpy.ndarray` Mean distribution. """ @@ -773,19 +767,23 @@ def __str__(self) -> str: return f"{self.__class__.__name__}({len(self)} Reflectances)" - def __len__(self) -> Integer: + def __len__(self) -> int: """ Return the number of colours in the data. Returns ------- - :class:`numpy.integer` + :class:`int` Number of colours in the data. """ - return self._reflectances.shape[0] + return ( + self._reflectances.shape[0] + if self._reflectances is not None + else 0 + ) - def origin(self, i: Integer, direction: Integer) -> Floating: + def origin(self, i: int, direction: int) -> float: """ Return the origin *CIE x* or *CIE y* chromaticity coordinate for given index and direction. @@ -799,7 +797,7 @@ def origin(self, i: Integer, direction: Integer) -> Floating: Returns ------- - :class:`numpy.floating` + :class:`float` Origin *CIE x* or *CIE y* chromaticity coordinate. Raises @@ -813,9 +811,7 @@ def origin(self, i: Integer, direction: Integer) -> Floating: else: raise ValueError('The "chromaticity coordinates" are undefined!') - def partition( - self, axis: PartitionAxis - ) -> Tuple[Data_Otsu2018, Data_Otsu2018]: + def partition(self, axis: PartitionAxis) -> tuple[Self, Self]: """ Partition the data using given partition axis. @@ -827,7 +823,7 @@ def partition( Returns ------- :class:`tuple` - Tuple of left or lower part and right or upper part. + tuple of left or lower part and right or upper part. Raises ------ @@ -839,7 +835,11 @@ def partition( lesser = Data_Otsu2018(None, self._cmfs, self._illuminant) greater = Data_Otsu2018(None, self._cmfs, self._illuminant) - if self._XYZ is not None and self._xy is not None: + if ( + self._XYZ is not None + and self._xy is not None + and self._reflectances is not None + ): mask = self._xy[:, axis.direction] <= axis.origin lesser._reflectances = self._reflectances[mask, :] @@ -864,21 +864,23 @@ def PCA(self) -> None: the relevant attributes accordingly. """ - if self._M is None: - settings: Dict[str, Any] = { + if self._M is None and self._reflectances is not None: + settings: dict[str, Any] = { "cmfs": self._cmfs, "illuminant": self._illuminant, "shape": self._cmfs.shape, } - self._mean = np.mean(self.reflectances, axis=0) + self._mean = np.mean(self._reflectances, axis=0) self._XYZ_mu = ( - msds_to_XYZ_integration(cast(NDArray, self._mean), **settings) + msds_to_XYZ_integration( + cast(NDArrayFloat, self._mean), **settings + ) / 100 ) _w, w = eigen_decomposition( - self.reflectances - self._mean, + self._reflectances - self._mean, descending_order=False, covariance_matrix=True, ) @@ -930,7 +932,7 @@ def reconstruct(self, XYZ: ArrayLike) -> SpectralDistribution: '"basis functions" are undefined!' ) - def reconstruction_error(self) -> Floating: + def reconstruction_error(self) -> float: """ Return the reconstruction error of the data. The error is computed by reconstructing the reflectances for the reference *CIE XYZ* tristimulus @@ -939,7 +941,7 @@ def reconstruction_error(self) -> Floating: Returns ------- - :class:`numpy.floating` + :class:`float` The reconstruction error for the data. Raises @@ -956,15 +958,15 @@ def reconstruction_error(self) -> Floating: if self._reconstruction_error is not None: return self._reconstruction_error - if self._XYZ is not None: + if self._XYZ is not None and self._reflectances is not None: self.PCA() - error = 0 + error: float = 0.0 for i in range(len(self)): sd = self._reflectances[i, :] XYZ = self._XYZ[i, :] recovered_sd = self.reconstruct(XYZ) - error += np.sum((sd - recovered_sd.values) ** 2) + error += cast(float, np.sum((sd - recovered_sd.values) ** 2)) self._reconstruction_error = error @@ -1003,15 +1005,15 @@ class Node_Otsu2018(Node): def __init__( self, - parent: Optional[Node_Otsu2018] = None, - children: Optional[List] = None, - data: Optional[Data_Otsu2018] = None, + parent: Optional[Self] = None, + children: Optional[list] = None, + data: Optional[Self] = None, ) -> None: super().__init__(parent=parent, children=children, data=data) self._partition_axis: Optional[PartitionAxis] = None self._best_partition: Optional[ - Tuple[List[Node_Otsu2018], PartitionAxis, Floating] + tuple[list[Node_Otsu2018], PartitionAxis, float] ] = None @property @@ -1028,7 +1030,7 @@ def partition_axis(self) -> Optional[PartitionAxis]: return self._partition_axis @property - def row(self) -> Tuple[Floating, Integer, Node_Otsu2018, Node_Otsu2018]: + def row(self) -> tuple[float, float, Self, Self]: """ Getter property for the node row for the selector array. @@ -1047,13 +1049,13 @@ def row(self) -> Tuple[Floating, Integer, Node_Otsu2018, Node_Otsu2018]: return ( self._partition_axis.origin, self._partition_axis.direction, - cast(Node_Otsu2018, self.children[0]), - cast(Node_Otsu2018, self.children[1]), + self.children[0], + self.children[1], ) else: raise ValueError('The "partition axis" is undefined!') - def split(self, children: List[Node_Otsu2018], axis: PartitionAxis): + def split(self, children: list[Self], axis: PartitionAxis): """ Convert the leaf node into an inner node using given children and partition axis. @@ -1068,14 +1070,14 @@ def split(self, children: List[Node_Otsu2018], axis: PartitionAxis): """ self.data = None - self.children = list(children) + self.children = list(children) # pyright: ignore self._best_partition = None self._partition_axis = axis def minimise( - self, minimum_cluster_size: Integer - ) -> Tuple[List[Node_Otsu2018], PartitionAxis, Floating]: + self, minimum_cluster_size: int + ) -> tuple[list[Self], PartitionAxis, float]: """ Find the best partition for the node that minimises the leaf reconstruction error. @@ -1089,7 +1091,7 @@ def minimise( Returns ------- :class:`tuple` - Tuple of tuple of nodes created by splitting a node with a given + tuple of tuple of nodes created by splitting a node with a given partition, partition axis, i.e. the horizontal or vertical line, partitioning the 2D space in two half-planes and partition error. """ @@ -1149,7 +1151,7 @@ def minimise( return self._best_partition - def leaf_reconstruction_error(self) -> Floating: + def leaf_reconstruction_error(self) -> float: """ Return the reconstruction error of the node data. The error is computed by reconstructing the reflectances for the data reference @@ -1158,13 +1160,13 @@ def leaf_reconstruction_error(self) -> Floating: Returns ------- - :class:`numpy.floating` + :class:`float` The reconstruction errors summation for the node data. """ return self.data.reconstruction_error() - def branch_reconstruction_error(self) -> Floating: + def branch_reconstruction_error(self) -> float: """ Compute the reconstruction error for all the leaves data connected to the node or its children, i.e. the reconstruction errors summation for @@ -1172,7 +1174,7 @@ def branch_reconstruction_error(self) -> Floating: Returns ------- - :class:`numpy.floating` + :class:`float` Reconstruction errors summation for all the leaves' data in the branch. """ @@ -1180,12 +1182,10 @@ def branch_reconstruction_error(self) -> Floating: if self.is_leaf(): return self.leaf_reconstruction_error() else: - return np.sum( - as_float_array( + return float( + np.sum( [ - cast( - Node_Otsu2018, child - ).branch_reconstruction_error() + child.branch_reconstruction_error() for child in self.children ] ) @@ -1329,7 +1329,7 @@ def __init__( self._cmfs: MultiSpectralDistributions = cmfs self._illuminant: SpectralDistribution = illuminant - self._reflectances: NDArray = np.transpose( + self._reflectances: NDArrayFloat = np.transpose( reshape_msds(reflectances, self._cmfs.shape).values ) @@ -1338,7 +1338,7 @@ def __init__( ) @property - def reflectances(self) -> NDArray: + def reflectances(self) -> NDArrayFloat: """ Getter property for the reference reflectances. @@ -1378,8 +1378,8 @@ def illuminant(self) -> SpectralDistribution: def optimise( self, - iterations: Integer = 8, - minimum_cluster_size: Optional[Integer] = None, + iterations: int = 8, + minimum_cluster_size: Optional[int] = None, print_callable: Callable = print, ): """ @@ -1576,7 +1576,7 @@ def add_rows(node, data=None): """Add rows for given node and its children.""" data = cast( - Dict, + dict, optional( data, {"rows": [], "node_to_leaf_id": {}, "leaf_id": 0} ), diff --git a/colour/recovery/smits1999.py b/colour/recovery/smits1999.py index 16bec3dd26..7e8d0da7d5 100644 --- a/colour/recovery/smits1999.py +++ b/colour/recovery/smits1999.py @@ -16,7 +16,7 @@ import numpy as np from colour.colorimetry import CCS_ILLUMINANTS, SpectralDistribution -from colour.hints import ArrayLike, NDArray +from colour.hints import ArrayLike, NDArrayFloat from colour.models import ( XYZ_to_RGB, normalised_primary_matrix, @@ -40,15 +40,15 @@ "RGB_to_sd_Smits1999", ] -PRIMARIES_SMITS1999: NDArray = RGB_COLOURSPACE_sRGB.primaries +PRIMARIES_SMITS1999: NDArrayFloat = RGB_COLOURSPACE_sRGB.primaries """Current *Smits (1999)* method implementation colourspace primaries.""" -CCS_WHITEPOINT_SMITS1999: NDArray = CCS_ILLUMINANTS[ +CCS_WHITEPOINT_SMITS1999: NDArrayFloat = CCS_ILLUMINANTS[ "CIE 1931 2 Degree Standard Observer" ]["E"] """Current *Smits (1999)* method implementation colourspace whitepoint.""" -MATRIX_XYZ_TO_RGB_SMITS1999: NDArray = np.linalg.inv( +MATRIX_XYZ_TO_RGB_SMITS1999: NDArrayFloat = np.linalg.inv( normalised_primary_matrix(PRIMARIES_SMITS1999, CCS_WHITEPOINT_SMITS1999) ) """ @@ -57,7 +57,7 @@ """ -def XYZ_to_RGB_Smits1999(XYZ: ArrayLike) -> NDArray: +def XYZ_to_RGB_Smits1999(XYZ: ArrayLike) -> NDArrayFloat: """ Convert from *CIE XYZ* tristimulus values to *RGB* colourspace with conditions required by the current *Smits (1999)* method implementation. diff --git a/colour/recovery/tests/test_jakob2019.py b/colour/recovery/tests/test_jakob2019.py index ce19757c53..60ae897d1d 100644 --- a/colour/recovery/tests/test_jakob2019.py +++ b/colour/recovery/tests/test_jakob2019.py @@ -204,7 +204,7 @@ class TestLUT3D_Jakob2019(unittest.TestCase): """ @classmethod - def generate_LUT(self): + def generate_LUT(cls): """ Generate the *LUT* used for the unit tests. @@ -215,22 +215,20 @@ def generate_LUT(self): is invoked once per-test. """ - if not hasattr(self, "_LUT"): - self._shape = SPECTRAL_SHAPE_JAKOB2019 - self._cmfs, self._sd_D65 = handle_spectral_arguments( - shape_default=self._shape + if not hasattr(cls, "_LUT"): + cls._shape = SPECTRAL_SHAPE_JAKOB2019 + cls._cmfs, cls._sd_D65 = handle_spectral_arguments( + shape_default=cls._shape ) - self._XYZ_D65 = sd_to_XYZ(self._sd_D65) - self._xy_D65 = XYZ_to_xy(self._XYZ_D65) + cls._XYZ_D65 = sd_to_XYZ(cls._sd_D65) + cls._xy_D65 = XYZ_to_xy(cls._XYZ_D65) - self._RGB_colourspace = RGB_COLOURSPACE_sRGB + cls._RGB_colourspace = RGB_COLOURSPACE_sRGB - self._LUT = LUT3D_Jakob2019() - self._LUT.generate( - self._RGB_colourspace, self._cmfs, self._sd_D65, 5 - ) + cls._LUT = LUT3D_Jakob2019() + cls._LUT.generate(cls._RGB_colourspace, cls._cmfs, cls._sd_D65, 5) - return self._LUT + return cls._LUT def test_required_attributes(self): """Test the presence of required attributes.""" diff --git a/colour/temperature/__init__.py b/colour/temperature/__init__.py index ed52e3e71e..d814fdc849 100644 --- a/colour/temperature/__init__.py +++ b/colour/temperature/__init__.py @@ -44,9 +44,7 @@ from colour.hints import ( Any, ArrayLike, - FloatingOrArrayLike, - FloatingOrNDArray, - NDArray, + NDArrayFloat, Literal, Union, ) @@ -131,7 +129,7 @@ def uv_to_CCT( str, ] = "Ohno 2013", **kwargs: Any, -) -> NDArray: +) -> NDArrayFloat: """ Return the correlated colour temperature :math:`T_{cp}` and :math:`\\Delta_{uv}` from given *CIE UCS* colourspace *uv* chromaticity @@ -225,7 +223,7 @@ def CCT_to_uv( str, ] = "Ohno 2013", **kwargs: Any, -) -> NDArray: +) -> NDArrayFloat: """ Return the *CIE UCS* colourspace *uv* chromaticity coordinates from given correlated colour temperature :math:`T_{cp}` using given method. @@ -320,7 +318,7 @@ def xy_to_CCT( ], str, ] = "CIE Illuminant D Series", -) -> FloatingOrNDArray: +) -> NDArrayFloat: """ Return the correlated colour temperature :math:`T_{cp}` from given *CIE xy* chromaticity coordinates using given method. @@ -341,7 +339,7 @@ def xy_to_CCT( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Correlated colour temperature :math:`T_{cp}`. References @@ -395,7 +393,7 @@ def xy_to_CCT( def CCT_to_xy( - CCT: FloatingOrArrayLike, + CCT: ArrayLike, method: Union[ Literal[ "CIE Illuminant D Series", @@ -405,7 +403,7 @@ def CCT_to_xy( ], str, ] = "CIE Illuminant D Series", -) -> NDArray: +) -> NDArrayFloat: """ Return the *CIE xy* chromaticity coordinates from given correlated colour temperature :math:`T_{cp}` using given method. diff --git a/colour/temperature/cie_d.py b/colour/temperature/cie_d.py index 845a73a858..7eedc3c8d8 100644 --- a/colour/temperature/cie_d.py +++ b/colour/temperature/cie_d.py @@ -28,10 +28,7 @@ from colour.colorimetry import daylight_locus_function from colour.hints import ( ArrayLike, - Dict, - FloatingOrArrayLike, - FloatingOrNDArray, - NDArray, + NDArrayFloat, Optional, ) from colour.utilities import as_float_array, as_float, tstack, usage_warning @@ -50,8 +47,8 @@ def xy_to_CCT_CIE_D( - xy: ArrayLike, optimisation_kwargs: Optional[Dict] = None -) -> FloatingOrNDArray: + xy: ArrayLike, optimisation_kwargs: Optional[dict] = None +) -> NDArrayFloat: """ Return the correlated colour temperature :math:`T_{cp}` of a *CIE Illuminant D Series* from its *CIE xy* chromaticity coordinates. @@ -65,7 +62,7 @@ def xy_to_CCT_CIE_D( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Correlated colour temperature :math:`T_{cp}`. Warnings @@ -91,12 +88,10 @@ def xy_to_CCT_CIE_D( shape = xy.shape xy = np.atleast_1d(xy.reshape([-1, 2])) - def objective_function( - CCT: FloatingOrArrayLike, xy: ArrayLike - ) -> FloatingOrNDArray: + def objective_function(CCT: ArrayLike, xy: ArrayLike) -> NDArrayFloat: """Objective function.""" - objective = np.linalg.norm(CCT_to_xy_CIE_D(CCT) - xy) + objective = np.linalg.norm(CCT_to_xy_CIE_D(CCT) - as_float_array(xy)) return as_float(objective) @@ -124,7 +119,7 @@ def objective_function( return as_float(np.reshape(CCT, shape[:-1])) -def CCT_to_xy_CIE_D(CCT: FloatingOrArrayLike) -> NDArray: +def CCT_to_xy_CIE_D(CCT: ArrayLike) -> NDArrayFloat: """ Return the *CIE xy* chromaticity coordinates of a *CIE Illuminant D Series* from its correlated colour temperature diff --git a/colour/temperature/hernandez1999.py b/colour/temperature/hernandez1999.py index 39620a441d..a8bcde43a4 100644 --- a/colour/temperature/hernandez1999.py +++ b/colour/temperature/hernandez1999.py @@ -29,10 +29,7 @@ from colour.colorimetry import CCS_ILLUMINANTS from colour.hints import ( ArrayLike, - Dict, - FloatingOrArrayLike, - FloatingOrNDArray, - NDArray, + NDArrayFloat, Optional, ) from colour.utilities import as_float_array, as_float, tsplit, usage_warning @@ -50,7 +47,7 @@ ] -def xy_to_CCT_Hernandez1999(xy: ArrayLike) -> FloatingOrNDArray: +def xy_to_CCT_Hernandez1999(xy: ArrayLike) -> NDArrayFloat: """ Return the correlated colour temperature :math:`T_{cp}` from given *CIE xy* chromaticity coordinates using *Hernandez-Andres et al. (1999)* @@ -63,7 +60,7 @@ def xy_to_CCT_Hernandez1999(xy: ArrayLike) -> FloatingOrNDArray: Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Correlated colour temperature :math:`T_{cp}`. References @@ -103,8 +100,8 @@ def xy_to_CCT_Hernandez1999(xy: ArrayLike) -> FloatingOrNDArray: def CCT_to_xy_Hernandez1999( - CCT: FloatingOrArrayLike, optimisation_kwargs: Optional[Dict] = None -) -> NDArray: + CCT: ArrayLike, optimisation_kwargs: Optional[dict] = None +) -> NDArrayFloat: """ Return the *CIE xy* chromaticity coordinates from given correlated colour temperature :math:`T_{cp}` using *Hernandez-Andres et al. (1999)* method. @@ -153,9 +150,7 @@ def CCT_to_xy_Hernandez1999( shape = list(CCT.shape) CCT = np.atleast_1d(CCT.reshape([-1, 1])) - def objective_function( - xy: ArrayLike, CCT: FloatingOrArrayLike - ) -> FloatingOrNDArray: + def objective_function(xy: ArrayLike, CCT: ArrayLike) -> NDArrayFloat: """Objective function.""" objective = np.linalg.norm( diff --git a/colour/temperature/kang2002.py b/colour/temperature/kang2002.py index 4104c08dee..e6a5c46301 100644 --- a/colour/temperature/kang2002.py +++ b/colour/temperature/kang2002.py @@ -26,10 +26,7 @@ from colour.hints import ( ArrayLike, - Dict, - FloatingOrArrayLike, - FloatingOrNDArray, - NDArray, + NDArrayFloat, Optional, ) from colour.utilities import as_float_array, as_float, tstack, usage_warning @@ -48,8 +45,8 @@ def xy_to_CCT_Kang2002( - xy: ArrayLike, optimisation_kwargs: Optional[Dict] = None -) -> FloatingOrNDArray: + xy: ArrayLike, optimisation_kwargs: Optional[dict] = None +) -> NDArrayFloat: """ Return the correlated colour temperature :math:`T_{cp}` from given *CIE xy* chromaticity coordinates using *Kang et al. (2002)* method. @@ -63,7 +60,7 @@ def xy_to_CCT_Kang2002( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Correlated colour temperature :math:`T_{cp}`. Warnings @@ -89,12 +86,12 @@ def xy_to_CCT_Kang2002( shape = xy.shape xy = np.atleast_1d(xy.reshape([-1, 2])) - def objective_function( - CCT: FloatingOrArrayLike, xy: ArrayLike - ) -> FloatingOrNDArray: + def objective_function(CCT: ArrayLike, xy: ArrayLike) -> NDArrayFloat: """Objective function.""" - objective = np.linalg.norm(CCT_to_xy_Kang2002(CCT) - xy) + objective = np.linalg.norm( + CCT_to_xy_Kang2002(CCT) - as_float_array(xy) + ) return as_float(objective) @@ -122,7 +119,7 @@ def objective_function( return as_float(np.reshape(CCT, shape[:-1])) -def CCT_to_xy_Kang2002(CCT: FloatingOrArrayLike) -> NDArray: +def CCT_to_xy_Kang2002(CCT: ArrayLike) -> NDArrayFloat: """ Return the *CIE xy* chromaticity coordinates from given correlated colour temperature :math:`T_{cp}` using *Kang et al. (2002)* method. diff --git a/colour/temperature/krystek1985.py b/colour/temperature/krystek1985.py index 0782eb48ff..3195cd87a2 100644 --- a/colour/temperature/krystek1985.py +++ b/colour/temperature/krystek1985.py @@ -26,10 +26,7 @@ from colour.hints import ( ArrayLike, - Dict, - FloatingOrArrayLike, - FloatingOrNDArray, - NDArray, + NDArrayFloat, Optional, ) from colour.utilities import as_float_array, as_float, tstack @@ -48,8 +45,8 @@ def uv_to_CCT_Krystek1985( - uv: ArrayLike, optimisation_kwargs: Optional[Dict] = None -) -> FloatingOrNDArray: + uv: ArrayLike, optimisation_kwargs: Optional[dict] = None +) -> NDArrayFloat: """ Return the correlated colour temperature :math:`T_{cp}` from given *CIE UCS* colourspace *uv* chromaticity coordinates using *Krystek (1985)* @@ -64,7 +61,7 @@ def uv_to_CCT_Krystek1985( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Correlated colour temperature :math:`T_{cp}`. Warnings @@ -95,12 +92,12 @@ def uv_to_CCT_Krystek1985( shape = uv.shape uv = np.atleast_1d(uv.reshape([-1, 2])) - def objective_function( - CCT: FloatingOrArrayLike, uv: ArrayLike - ) -> FloatingOrNDArray: + def objective_function(CCT: ArrayLike, uv: ArrayLike) -> NDArrayFloat: """Objective function.""" - objective = np.linalg.norm(CCT_to_uv_Krystek1985(CCT) - uv) + objective = np.linalg.norm( + CCT_to_uv_Krystek1985(CCT) - as_float_array(uv) + ) return as_float(objective) @@ -128,7 +125,7 @@ def objective_function( return as_float(np.reshape(CCT, shape[:-1])) -def CCT_to_uv_Krystek1985(CCT: FloatingOrArrayLike) -> NDArray: +def CCT_to_uv_Krystek1985(CCT: ArrayLike) -> NDArrayFloat: """ Return the *CIE UCS* colourspace *uv* chromaticity coordinates from given correlated colour temperature :math:`T_{cp}` using *Krystek (1985)* method. diff --git a/colour/temperature/mccamy1992.py b/colour/temperature/mccamy1992.py index 3c1127030d..230bd064bb 100644 --- a/colour/temperature/mccamy1992.py +++ b/colour/temperature/mccamy1992.py @@ -27,10 +27,7 @@ from colour.colorimetry import CCS_ILLUMINANTS from colour.hints import ( ArrayLike, - Dict, - FloatingOrArrayLike, - FloatingOrNDArray, - NDArray, + NDArrayFloat, Optional, ) from colour.utilities import as_float_array, as_float, tsplit, usage_warning @@ -48,7 +45,7 @@ ] -def xy_to_CCT_McCamy1992(xy: ArrayLike) -> FloatingOrNDArray: +def xy_to_CCT_McCamy1992(xy: ArrayLike) -> NDArrayFloat: """ Return the correlated colour temperature :math:`T_{cp}` from given *CIE xy* chromaticity coordinates using *McCamy (1992)* method. @@ -60,7 +57,7 @@ def xy_to_CCT_McCamy1992(xy: ArrayLike) -> FloatingOrNDArray: Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Correlated colour temperature :math:`T_{cp}`. References @@ -86,8 +83,8 @@ def xy_to_CCT_McCamy1992(xy: ArrayLike) -> FloatingOrNDArray: def CCT_to_xy_McCamy1992( - CCT: FloatingOrArrayLike, optimisation_kwargs: Optional[Dict] = None -) -> NDArray: + CCT: ArrayLike, optimisation_kwargs: Optional[dict] = None +) -> NDArrayFloat: """ Return the *CIE xy* chromaticity coordinates from given correlated colour temperature :math:`T_{cp}` using *McCamy (1992)* method. @@ -136,9 +133,7 @@ def CCT_to_xy_McCamy1992( shape = list(CCT.shape) CCT = np.atleast_1d(CCT.reshape([-1, 1])) - def objective_function( - xy: ArrayLike, CCT: FloatingOrArrayLike - ) -> FloatingOrNDArray: + def objective_function(xy: ArrayLike, CCT: ArrayLike) -> NDArrayFloat: """Objective function.""" objective = np.linalg.norm( diff --git a/colour/temperature/ohno2013.py b/colour/temperature/ohno2013.py index 3c4c252873..8e006cf4bb 100644 --- a/colour/temperature/ohno2013.py +++ b/colour/temperature/ohno2013.py @@ -30,10 +30,7 @@ ) from colour.hints import ( ArrayLike, - Dict, - Floating, - Integer, - NDArray, + NDArrayFloat, Optional, ) from colour.temperature import CCT_to_uv_Planck1900 @@ -64,12 +61,12 @@ ] -CCT_MINIMAL_OHNO2013: Floating = 1000 -CCT_MAXIMAL_OHNO2013: Floating = 100000 -CCT_SAMPLES_OHNO2013: Integer = 10 -CCT_ITERATIONS_OHNO2013: Integer = 6 +CCT_MINIMAL_OHNO2013: float = 1000 +CCT_MAXIMAL_OHNO2013: float = 100000 +CCT_SAMPLES_OHNO2013: int = 10 +CCT_ITERATIONS_OHNO2013: int = 6 -_CACHE_PLANCKIAN_TABLE_ROW: Dict = CACHE_REGISTRY.register_cache( +_CACHE_PLANCKIAN_TABLE_ROW: dict = CACHE_REGISTRY.register_cache( f"{__name__}._CACHE_PLANCKIAN_TABLE_ROW" ) @@ -77,10 +74,10 @@ def planckian_table( uv: ArrayLike, cmfs: MultiSpectralDistributions, - start: Floating, - end: Floating, - count: Integer, -) -> NDArray: + start: float, + end: float, + count: int, +) -> NDArrayFloat: """ Return a planckian table from given *CIE UCS* colourspace *uv* chromaticity coordinates, colour matching functions and temperature range @@ -158,11 +155,11 @@ def planckian_table( def uv_to_CCT_Ohno2013( uv: ArrayLike, cmfs: Optional[MultiSpectralDistributions] = None, - start: Optional[Floating] = None, - end: Optional[Floating] = None, - count: Optional[Integer] = None, - iterations: Optional[Integer] = None, -) -> NDArray: + start: Optional[float] = None, + end: Optional[float] = None, + count: Optional[int] = None, + iterations: Optional[int] = None, +) -> NDArrayFloat: """ Return the correlated colour temperature :math:`T_{cp}` and :math:`\\Delta_{uv}` from given *CIE UCS* colourspace *uv* chromaticity @@ -303,7 +300,7 @@ def uv_to_CCT_Ohno2013( def CCT_to_uv_Ohno2013( CCT_D_uv: ArrayLike, cmfs: Optional[MultiSpectralDistributions] = None -) -> NDArray: +) -> NDArrayFloat: """ Return the *CIE UCS* colourspace *uv* chromaticity coordinates from given correlated colour temperature :math:`T_{cp}`, :math:`\\Delta_{uv}` and diff --git a/colour/temperature/planck1900.py b/colour/temperature/planck1900.py index 30f61f9a7a..8e7dc761d3 100644 --- a/colour/temperature/planck1900.py +++ b/colour/temperature/planck1900.py @@ -28,10 +28,7 @@ ) from colour.hints import ( ArrayLike, - Dict, - FloatingOrArrayLike, - FloatingOrNDArray, - NDArray, + NDArrayFloat, Optional, ) from colour.models import UCS_to_uv, XYZ_to_UCS @@ -53,8 +50,8 @@ def uv_to_CCT_Planck1900( uv: ArrayLike, cmfs: Optional[MultiSpectralDistributions] = None, - optimisation_kwargs: Optional[Dict] = None, -) -> FloatingOrNDArray: + optimisation_kwargs: Optional[dict] = None, +) -> NDArrayFloat: """ Return the correlated colour temperature :math:`T_{cp}` of a blackbody from given *CIE UCS* colourspace *uv* chromaticity coordinates and colour @@ -72,7 +69,7 @@ def uv_to_CCT_Planck1900( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Correlated colour temperature :math:`T_{cp}`. Warnings @@ -98,12 +95,12 @@ def uv_to_CCT_Planck1900( shape = uv.shape uv = np.atleast_1d(uv.reshape([-1, 2])) - def objective_function( - CCT: FloatingOrArrayLike, uv: ArrayLike - ) -> FloatingOrNDArray: + def objective_function(CCT: ArrayLike, uv: ArrayLike) -> NDArrayFloat: """Objective function.""" - objective = np.linalg.norm(CCT_to_uv_Planck1900(CCT, cmfs) - uv) + objective = np.linalg.norm( + CCT_to_uv_Planck1900(CCT, cmfs) - as_float_array(uv) + ) return as_float(objective) @@ -132,8 +129,8 @@ def objective_function( def CCT_to_uv_Planck1900( - CCT: FloatingOrArrayLike, cmfs: Optional[MultiSpectralDistributions] = None -) -> NDArray: + CCT: ArrayLike, cmfs: Optional[MultiSpectralDistributions] = None +) -> NDArrayFloat: """ Return the *CIE UCS* colourspace *uv* chromaticity coordinates from given correlated colour temperature :math:`T_{cp}` and colour matching functions diff --git a/colour/temperature/robertson1968.py b/colour/temperature/robertson1968.py index 86242c8750..6d8006cb53 100644 --- a/colour/temperature/robertson1968.py +++ b/colour/temperature/robertson1968.py @@ -39,7 +39,7 @@ from dataclasses import dataclass from colour.algebra import sdiv, sdiv_mode -from colour.hints import ArrayLike, Floating, List, NDArray, Tuple +from colour.hints import ArrayLike, NDArrayFloat from colour.utilities import as_float_array, tsplit __author__ = "Colour Developers" @@ -57,7 +57,7 @@ "CCT_to_uv_Robertson1968", ] -DATA_ISOTEMPERATURE_LINES_ROBERTSON1968: Tuple = ( +DATA_ISOTEMPERATURE_LINES_ROBERTSON1968: tuple = ( (0, 0.18006, 0.26352, -0.24341), (10, 0.18066, 0.26589, -0.25479), (20, 0.18133, 0.26846, -0.26876), @@ -129,19 +129,19 @@ class ISOTemperatureLine_Specification_Robertson1968: Slope of the *v* chromaticity coordinate. """ - r: Floating - u: Floating - v: Floating - t: Floating + r: float + u: float + v: float + t: float -ISOTEMPERATURE_LINES_ROBERTSON1968: List = [ +ISOTEMPERATURE_LINES_ROBERTSON1968: list = [ ISOTemperatureLine_Specification_Robertson1968(*x) for x in DATA_ISOTEMPERATURE_LINES_ROBERTSON1968 ] -def _uv_to_CCT_Robertson1968(uv: ArrayLike) -> NDArray: +def _uv_to_CCT_Robertson1968(uv: ArrayLike) -> NDArrayFloat: """ Return the correlated colour temperature :math:`T_{cp}` and :math:`\\Delta_{uv}` from given *CIE UCS* colourspace *uv* chromaticity @@ -162,6 +162,7 @@ def _uv_to_CCT_Robertson1968(uv: ArrayLike) -> NDArray: last_dt = last_dv = last_du = 0 + D_uv = 0 for i in range(1, 31): wr_ruvt = ISOTEMPERATURE_LINES_ROBERTSON1968[i] wr_ruvt_previous = ISOTEMPERATURE_LINES_ROBERTSON1968[i - 1] @@ -211,7 +212,7 @@ def _uv_to_CCT_Robertson1968(uv: ArrayLike) -> NDArray: return np.array([T, -D_uv]) -def uv_to_CCT_Robertson1968(uv: ArrayLike) -> NDArray: +def uv_to_CCT_Robertson1968(uv: ArrayLike) -> NDArrayFloat: """ Return the correlated colour temperature :math:`T_{cp}` and :math:`\\Delta_{uv}` from given *CIE UCS* colourspace *uv* chromaticity @@ -245,7 +246,7 @@ def uv_to_CCT_Robertson1968(uv: ArrayLike) -> NDArray: return np.reshape(as_float_array(CCT_D_uv), uv.shape) -def _CCT_to_uv_Robertson1968(CCT_D_uv: ArrayLike) -> NDArray: +def _CCT_to_uv_Robertson1968(CCT_D_uv: ArrayLike) -> NDArrayFloat: """ Return the *CIE UCS* colourspace *uv* chromaticity coordinates from given correlated colour temperature :math:`T_{cp}` and :math:`\\Delta_{uv}` using @@ -306,7 +307,7 @@ def _CCT_to_uv_Robertson1968(CCT_D_uv: ArrayLike) -> NDArray: return np.array([u, v]) -def CCT_to_uv_Robertson1968(CCT_D_uv: ArrayLike) -> NDArray: +def CCT_to_uv_Robertson1968(CCT_D_uv: ArrayLike) -> NDArrayFloat: """ Return the *CIE UCS* colourspace *uv* chromaticity coordinates from given correlated colour temperature :math:`T_{cp}` and :math:`\\Delta_{uv}` using diff --git a/colour/temperature/tests/test_robertson1968.py b/colour/temperature/tests/test_robertson1968.py index 912756bc90..dc30bef10a 100644 --- a/colour/temperature/tests/test_robertson1968.py +++ b/colour/temperature/tests/test_robertson1968.py @@ -7,7 +7,6 @@ import unittest from itertools import product -from colour.hints import Dict from colour.temperature import CCT_to_uv_Robertson1968, uv_to_CCT_Robertson1968 from colour.utilities import ignore_numpy_errors @@ -23,7 +22,7 @@ "TestCCT_to_uv_Robertson1968", ] -TEMPERATURE_DUV_TO_UV: Dict = { +TEMPERATURE_DUV_TO_UV: dict = { (2000, -0.0500): np.array([0.309448284638118, 0.309263824757947]), (2000, -0.0250): np.array([0.307249142319059, 0.334166912378974]), (2000, 0.0000): np.array([0.305050000000000, 0.359070000000000]), diff --git a/colour/utilities/__init__.py b/colour/utilities/__init__.py index 26a0c76115..820f14477c 100644 --- a/colour/utilities/__init__.py +++ b/colour/utilities/__init__.py @@ -2,7 +2,7 @@ import sys -from colour.hints import Any, Dict +from colour.hints import Any from .data_structures import ( Lookup, @@ -249,7 +249,7 @@ def __getattr__(self, attribute) -> Any: # v0.4.0 -API_CHANGES: Dict = { +API_CHANGES: dict = { "ObjectRenamed": [ [ "colour.utilities.set_int_precision", @@ -304,7 +304,7 @@ def __getattr__(self, attribute) -> Any: """ if not is_documentation_building(): - sys.modules["colour.utilities"] = utilities( # type: ignore[assignment] + sys.modules["colour.utilities"] = utilities( # pyright: ignore sys.modules["colour.utilities"], build_API_changes(API_CHANGES) ) diff --git a/colour/utilities/array.py b/colour/utilities/array.py index 59c5b534a7..c54b740cf7 100644 --- a/colour/utilities/array.py +++ b/colour/utilities/array.py @@ -30,28 +30,20 @@ from colour.hints import ( Any, ArrayLike, - Boolean, Callable, Dataclass, DType, DTypeBoolean, - DTypeFloating, - DTypeInteger, + DTypeFloat, + DTypeInt, DTypeNumber, - Floating, - FloatingOrArrayLike, - FloatingOrNDArray, + NDArrayFloat, Generator, - Integer, - IntegerOrArrayLike, - IntegerOrNDArray, + NDArrayInt, Literal, NDArray, - NestedSequence, Number, - NumberOrArrayLike, Optional, - Tuple, Type, Union, cast, @@ -128,14 +120,14 @@ class fields. """ @property - def fields(self) -> Tuple: + def fields(self) -> tuple: """ Getter property for the fields of the :class:`dataclass`-like class. Returns ------- :class:`tuple` - Tuple of :class:`dataclass`-like class fields. + tuple of :class:`dataclass`-like class fields. """ return fields(self) @@ -165,7 +157,7 @@ class fields. """ @property - def keys(self) -> Tuple: + def keys(self) -> tuple: """ Getter property for the :class:`dataclass`-like class keys, i.e. the field names. @@ -179,7 +171,7 @@ def keys(self) -> Tuple: return tuple(field for field, _value in self) @property - def values(self) -> Tuple: + def values(self) -> tuple: """ Getter property for the :class:`dataclass`-like class values, i.e. the field values. @@ -193,7 +185,7 @@ def values(self) -> Tuple: return tuple(value for _field, value in self) @property - def items(self) -> Tuple: + def items(self) -> tuple: """ Getter property for the :class:`dataclass`-like class items, i.e. the field names and values. @@ -260,7 +252,7 @@ def __array__(self, dtype: Optional[Type[DTypeNumber]] = None) -> NDArray: :class:`dataclass`-like class converted to :class:`numpy.ndarray`. """ - dtype = cast(Type[DTypeNumber], optional(dtype, DEFAULT_FLOAT_DTYPE)) + dtype = optional(dtype, DEFAULT_FLOAT_DTYPE) default = None for _field, value in self: @@ -269,7 +261,13 @@ def __array__(self, dtype: Optional[Type[DTypeNumber]] = None) -> NDArray: break return tstack( - [value if value is not None else default for value in self.values], + cast( + ArrayLike, + [ + value if value is not None else default + for value in self.values + ], + ), dtype=dtype, ) @@ -477,7 +475,7 @@ def __ipow__(self, a: Any) -> Dataclass: return self.arithmetical_operation(a, "**", True) def arithmetical_operation( - self, a: Any, operation: str, in_place: Boolean = False + self, a: Any, operation: str, in_place: bool = False ) -> Dataclass: """ Perform given arithmetical operation with :math:`a` operand on the @@ -527,7 +525,7 @@ def arithmetical_operation( def as_array( - a: Union[NumberOrArrayLike, NestedSequence[NumberOrArrayLike]], + a: ArrayLike, dtype: Optional[Type[DType]] = None, ) -> NDArray: """ @@ -564,9 +562,7 @@ def as_array( return np.asarray(a, dtype) -def as_int( - a: NumberOrArrayLike, dtype: Optional[Type[DTypeInteger]] = None -) -> IntegerOrNDArray: +def as_int(a: ArrayLike, dtype: Optional[Type[DTypeInt]] = None) -> NDArrayInt: """ Attempt to convert given variable :math:`a` to :class:`numpy.integer` using given :class:`numpy.dtype`. If variable :math:`a` is not a scalar or @@ -583,7 +579,7 @@ def as_int( Returns ------- - :class:`numpy.integer` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Variable :math:`a` converted to :class:`numpy.integer`. Examples @@ -594,9 +590,9 @@ def as_int( array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]...) """ - dtype = cast(Type[DTypeInteger], optional(dtype, DEFAULT_INT_DTYPE)) + dtype = optional(dtype, DEFAULT_INT_DTYPE) - args = getattr(DTypeInteger, "__args__") + args = getattr(DTypeInt, "__args__") attest( dtype in args, f'"dtype" must be one of the following types: {args}', @@ -604,12 +600,12 @@ def as_int( # TODO: Reassess implementation when and if # https://github.com/numpy/numpy/issues/11956 is addressed. - return dtype(np.squeeze(a)) # type: ignore[return-value] + return dtype(np.squeeze(a)) # pyright: ignore def as_float( - a: NumberOrArrayLike, dtype: Optional[Type[DTypeFloating]] = None -) -> FloatingOrNDArray: + a: ArrayLike, dtype: Optional[Type[DTypeFloat]] = None +) -> NDArrayFloat: """ Attempt to convert given variable :math:`a` to :class:`numpy.floating` using given :class:`numpy.dtype`. If variable :math:`a` is not a scalar or @@ -626,7 +622,7 @@ def as_float( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Variable :math:`a` converted to :class:`numpy.floating`. Examples @@ -637,20 +633,21 @@ def as_float( array([ 0., 1., 2., 3., 4., 5., 6., 7., 8., 9.]) """ - dtype = cast(Type[DTypeFloating], optional(dtype, DEFAULT_FLOAT_DTYPE)) + dtype = optional(dtype, DEFAULT_FLOAT_DTYPE) + + args = getattr(DTypeFloat, "__args__") - args = getattr(DTypeFloating, "__args__") attest( dtype in args, f'"dtype" must be one of the following types: {args}', ) - return dtype(a) # type: ignore[arg-type, return-value] + return dtype(a) # pyright: ignore def as_int_array( - a: NumberOrArrayLike, dtype: Optional[Type[DTypeInteger]] = None -) -> NDArray: + a: ArrayLike, dtype: Optional[Type[DTypeInt]] = None +) -> NDArrayInt: """ Convert given variable :math:`a` to :class:`numpy.ndarray` using given :class:`numpy.dtype`. @@ -675,9 +672,10 @@ def as_int_array( array([1, 2, 3]...) """ - dtype = cast(Type[DTypeInteger], optional(dtype, DEFAULT_INT_DTYPE)) + dtype = optional(dtype, DEFAULT_INT_DTYPE) + + args = getattr(DTypeInt, "__args__") - args = getattr(DTypeInteger, "__args__") attest( dtype in args, f'"dtype" must be one of the following types: {args}', @@ -687,8 +685,8 @@ def as_int_array( def as_float_array( - a: NumberOrArrayLike, dtype: Optional[Type[DTypeFloating]] = None -) -> NDArray: + a: ArrayLike, dtype: Optional[Type[DTypeFloat]] = None +) -> NDArrayFloat: """ Convert given variable :math:`a` to :class:`numpy.ndarray` using given :class:`numpy.dtype`. @@ -713,7 +711,7 @@ def as_float_array( array([ 1., 2., 3.]) """ - dtype = cast(Type[DTypeFloating], optional(dtype, DEFAULT_FLOAT_DTYPE)) + dtype = optional(dtype, DEFAULT_FLOAT_DTYPE) attest( dtype in np.sctypes["float"], @@ -723,9 +721,7 @@ def as_float_array( return as_array(a, dtype) -def as_int_scalar( - a: NumberOrArrayLike, dtype: Optional[Type[DTypeInteger]] = None -) -> Integer: +def as_int_scalar(a: ArrayLike, dtype: Optional[Type[DTypeInt]] = None) -> int: """ Convert given :math:`a` variable to :class:`numpy.integer` using given :class:`numpy.dtype`. @@ -741,9 +737,14 @@ def as_int_scalar( Returns ------- - :class:`numpy.integer` + :class:`int` :math:`a` variable converted to :class:`numpy.integer`. + Warnings + -------- + - The return type is effectively annotated as :class:`int` and not + :class:`numpy.integer`. + Examples -------- >>> as_int_scalar(np.array(1)) @@ -754,12 +755,12 @@ def as_int_scalar( attest(a.ndim == 0, f'"{a}" cannot be converted to "int" scalar!') - return cast(Integer, as_int(a, dtype)) + return cast(int, as_int(a, dtype)) def as_float_scalar( - a: NumberOrArrayLike, dtype: Optional[Type[DTypeFloating]] = None -) -> Floating: + a: ArrayLike, dtype: Optional[Type[DTypeFloat]] = None +) -> float: """ Convert given :math:`a` variable to :class:`numpy.floating` using given :class:`numpy.dtype`. @@ -775,9 +776,14 @@ def as_float_scalar( Returns ------- - :class:`numpy.floating` + :class:`float` :math:`a` variable converted to :class:`numpy.floating`. + Warnings + -------- + - The return type is effectively annotated as :class:`float` and not + :class:`numpy.floating`. + Examples -------- >>> as_float_scalar(np.array(1)) @@ -788,11 +794,11 @@ def as_float_scalar( attest(a.ndim == 0, f'"{a}" cannot be converted to "float" scalar!') - return cast(Floating, as_float(a, dtype)) + return cast(float, as_float(a, dtype)) def set_default_int_dtype( - dtype: Type[DTypeInteger] = DEFAULT_INT_DTYPE, + dtype: Type[DTypeInt] = DEFAULT_INT_DTYPE, ) -> None: """ Set *Colour* default :class:`numpy.integer` precision by setting @@ -815,7 +821,7 @@ def set_default_int_dtype( -------- This definition is mostly given for consistency purposes with :func:`colour.utilities.set_default_float_dtype` definition but contrary to the - latter, changing *integer* precision will almost certainly completely break + latter, changing *int* precision will almost certainly completely break *Colour*. With great power comes great responsibility. Examples @@ -840,7 +846,7 @@ def set_default_int_dtype( def set_default_float_dtype( - dtype: Type[DTypeFloating] = DEFAULT_FLOAT_DTYPE, + dtype: Type[DTypeFloat] = DEFAULT_FLOAT_DTYPE, ) -> None: """ Set *Colour* default :class:`numpy.floating` precision by setting @@ -1059,8 +1065,8 @@ def wrapper(*args: Any, **kwargs: Any) -> Any: def to_domain_1( a: ArrayLike, - scale_factor: FloatingOrArrayLike = 100, - dtype: Optional[Type[DTypeFloating]] = None, + scale_factor: ArrayLike = 100, + dtype: Optional[Type[DTypeFloat]] = None, ) -> NDArray: """ Scale given array :math:`a` to domain **'1'**. The behaviour is as @@ -1112,7 +1118,7 @@ def to_domain_1( array(0.01) """ - dtype = cast(Type[DTypeFloating], optional(dtype, DEFAULT_FLOAT_DTYPE)) + dtype = optional(dtype, DEFAULT_FLOAT_DTYPE) a = as_float_array(a, dtype).copy() @@ -1124,8 +1130,8 @@ def to_domain_1( def to_domain_10( a: ArrayLike, - scale_factor: FloatingOrArrayLike = 10, - dtype: Optional[Type[DTypeFloating]] = None, + scale_factor: ArrayLike = 10, + dtype: Optional[Type[DTypeFloat]] = None, ) -> NDArray: """ Scale given array :math:`a` to domain **'10'**, used by @@ -1179,7 +1185,7 @@ def to_domain_10( array(0.1) """ - dtype = cast(Type[DTypeFloating], optional(dtype, DEFAULT_FLOAT_DTYPE)) + dtype = optional(dtype, DEFAULT_FLOAT_DTYPE) a = as_float_array(a, dtype).copy() @@ -1194,8 +1200,8 @@ def to_domain_10( def to_domain_100( a: ArrayLike, - scale_factor: FloatingOrArrayLike = 100, - dtype: Optional[Type[DTypeFloating]] = None, + scale_factor: ArrayLike = 100, + dtype: Optional[Type[DTypeFloat]] = None, ) -> NDArray: """ Scale given array :math:`a` to domain **'100'**. The behaviour is as @@ -1247,7 +1253,7 @@ def to_domain_100( array(1.0) """ - dtype = cast(Type[DTypeFloating], optional(dtype, DEFAULT_FLOAT_DTYPE)) + dtype = optional(dtype, DEFAULT_FLOAT_DTYPE) a = as_float_array(a, dtype).copy() @@ -1259,8 +1265,8 @@ def to_domain_100( def to_domain_degrees( a: ArrayLike, - scale_factor: FloatingOrArrayLike = 360, - dtype: Optional[Type[DTypeFloating]] = None, + scale_factor: ArrayLike = 360, + dtype: Optional[Type[DTypeFloat]] = None, ) -> NDArray: """ Scale given array :math:`a` to degrees domain. The behaviour is as @@ -1314,7 +1320,7 @@ def to_domain_degrees( array(3.6) """ - dtype = cast(Type[DTypeFloating], optional(dtype, DEFAULT_FLOAT_DTYPE)) + dtype = optional(dtype, DEFAULT_FLOAT_DTYPE) a = as_float_array(a, dtype).copy() @@ -1329,8 +1335,8 @@ def to_domain_degrees( def to_domain_int( a: ArrayLike, - bit_depth: IntegerOrArrayLike = 8, - dtype: Optional[Type[DTypeFloating]] = None, + bit_depth: ArrayLike = 8, + dtype: Optional[Type[DTypeFloat]] = None, ) -> NDArray: """ Scale given array :math:`a` to int domain. The behaviour is as follows: @@ -1349,7 +1355,7 @@ def to_domain_int( a Array :math:`a` to scale to int domain. bit_depth - Bit depth, usually *integer* but can be a :class:`numpy.ndarray` if + Bit depth, usually *int* but can be a :class:`numpy.ndarray` if some axis need different scaling to be brought to int domain. dtype Data type used for the conversion to :class:`np.ndarray`. @@ -1388,7 +1394,7 @@ def to_domain_int( array(2.55) """ - dtype = cast(Type[DTypeFloating], optional(dtype, DEFAULT_FLOAT_DTYPE)) + dtype = optional(dtype, DEFAULT_FLOAT_DTYPE) a = as_float_array(a, dtype).copy() @@ -1404,8 +1410,8 @@ def to_domain_int( def from_range_1( a: ArrayLike, - scale_factor: FloatingOrArrayLike = 100, - dtype: Optional[Type[DTypeFloating]] = None, + scale_factor: ArrayLike = 100, + dtype: Optional[Type[DTypeFloat]] = None, ) -> NDArray: """ Scale given array :math:`a` from range **'1'**. The behaviour is as @@ -1461,7 +1467,7 @@ def from_range_1( array(100.0) """ - dtype = cast(Type[DTypeFloating], optional(dtype, DEFAULT_FLOAT_DTYPE)) + dtype = optional(dtype, DEFAULT_FLOAT_DTYPE) a = as_float_array(a, dtype) @@ -1473,8 +1479,8 @@ def from_range_1( def from_range_10( a: ArrayLike, - scale_factor: FloatingOrArrayLike = 10, - dtype: Optional[Type[DTypeFloating]] = None, + scale_factor: ArrayLike = 10, + dtype: Optional[Type[DTypeFloat]] = None, ) -> NDArray: """ Scale given array :math:`a` from range **'10'**, used by @@ -1532,7 +1538,7 @@ def from_range_10( array(10.0) """ - dtype = cast(Type[DTypeFloating], optional(dtype, DEFAULT_FLOAT_DTYPE)) + dtype = optional(dtype, DEFAULT_FLOAT_DTYPE) a = as_float_array(a, dtype) @@ -1547,8 +1553,8 @@ def from_range_10( def from_range_100( a: ArrayLike, - scale_factor: FloatingOrArrayLike = 100, - dtype: Optional[Type[DTypeFloating]] = None, + scale_factor: ArrayLike = 100, + dtype: Optional[Type[DTypeFloat]] = None, ) -> NDArray: """ Scale given array :math:`a` from range **'100'**. The behaviour is as @@ -1604,7 +1610,7 @@ def from_range_100( array(1.0) """ - dtype = cast(Type[DTypeFloating], optional(dtype, DEFAULT_FLOAT_DTYPE)) + dtype = optional(dtype, DEFAULT_FLOAT_DTYPE) a = as_float_array(a, dtype) @@ -1616,8 +1622,8 @@ def from_range_100( def from_range_degrees( a: ArrayLike, - scale_factor: FloatingOrArrayLike = 360, - dtype: Optional[Type[DTypeFloating]] = None, + scale_factor: ArrayLike = 360, + dtype: Optional[Type[DTypeFloat]] = None, ) -> NDArray: """ Scale given array :math:`a` from degrees range. The behaviour is as @@ -1675,7 +1681,7 @@ def from_range_degrees( array(0.2777777...) """ - dtype = cast(Type[DTypeFloating], optional(dtype, DEFAULT_FLOAT_DTYPE)) + dtype = optional(dtype, DEFAULT_FLOAT_DTYPE) a = as_float_array(a, dtype) @@ -1690,8 +1696,8 @@ def from_range_degrees( def from_range_int( a: ArrayLike, - bit_depth: IntegerOrArrayLike = 8, - dtype: Optional[Type[DTypeFloating]] = None, + bit_depth: ArrayLike = 8, + dtype: Optional[Type[DTypeFloat]] = None, ) -> NDArray: """ Scale given array :math:`a` from int range. The behaviour is as follows: @@ -1709,7 +1715,7 @@ def from_range_int( a Array :math:`a` to scale from int range. bit_depth - Bit depth, usually *integer* but can be a :class:`numpy.ndarray` if + Bit depth, usually *int* but can be a :class:`numpy.ndarray` if some axis need different scaling to be brought from int range. dtype Data type used for the conversion to :class:`np.ndarray`. @@ -1753,7 +1759,7 @@ def from_range_int( array(0.3921568...) """ - dtype = cast(Type[DTypeFloating], optional(dtype, DEFAULT_FLOAT_DTYPE)) + dtype = optional(dtype, DEFAULT_FLOAT_DTYPE) a = as_float_array(a, dtype) @@ -1848,7 +1854,7 @@ def closest(a: ArrayLike, b: ArrayLike) -> NDArray: return a[closest_indexes(a, b)] -def interval(distribution: ArrayLike, unique: Boolean = True) -> NDArray: +def interval(distribution: ArrayLike, unique: bool = True) -> NDArray: """ Return the interval size of given distribution. @@ -1894,7 +1900,7 @@ def interval(distribution: ArrayLike, unique: Boolean = True) -> NDArray: return differences -def is_uniform(distribution: ArrayLike) -> Boolean: +def is_uniform(distribution: ArrayLike) -> bool: """ Return whether given distribution is uniform. @@ -1946,7 +1952,7 @@ def in_array( Returns ------- :class:`numpy.ndarray` - A boolean array with array :math:`a` shape describing whether an + A bool array with array :math:`a` shape describing whether an element of array :math:`a` is present in array :math:`b` within given tolerance. @@ -1973,7 +1979,7 @@ def in_array( def tstack( - a: Union[ArrayLike, NestedSequence[NumberOrArrayLike]], + a: ArrayLike, dtype: Optional[Union[Type[DTypeBoolean], Type[DTypeNumber]]] = None, ) -> NDArray: """ @@ -2028,7 +2034,7 @@ def tstack( [ 5., 5., 5.]]]]) """ - dtype = cast(Type[DTypeFloating], optional(dtype, DEFAULT_FLOAT_DTYPE)) + dtype = optional(dtype, DEFAULT_FLOAT_DTYPE) a = as_array(a, dtype) @@ -2039,7 +2045,7 @@ def tstack( def tsplit( - a: Union[ArrayLike, NestedSequence[NumberOrArrayLike]], + a: ArrayLike, dtype: Optional[Union[Type[DTypeBoolean], Type[DTypeNumber]]] = None, ) -> NDArray: """ @@ -2095,7 +2101,7 @@ def tsplit( [[ 0., 1., 2., 3., 4., 5.]]]) """ - dtype = cast(Type[DTypeFloating], optional(dtype, DEFAULT_FLOAT_DTYPE)) + dtype = optional(dtype, DEFAULT_FLOAT_DTYPE) a = as_array(a, dtype) @@ -2320,7 +2326,7 @@ def fill_nan( return a -def has_only_nan(a: ArrayLike) -> Boolean: +def has_only_nan(a: ArrayLike) -> bool: """ Return whether given array :math:`a` contains only NaN values. @@ -2392,7 +2398,7 @@ def ndarray_write(a: ArrayLike) -> Generator: def zeros( - shape: Union[Integer, Tuple[int, ...]], + shape: Union[int, tuple[int, ...]], dtype: Optional[Type[DTypeNumber]] = None, order: Literal["C", "F"] = "C", ) -> NDArray: @@ -2424,13 +2430,13 @@ def zeros( array([ 0., 0., 0.]) """ - dtype = cast(Type[DTypeFloating], optional(dtype, DEFAULT_FLOAT_DTYPE)) + dtype = optional(dtype, DEFAULT_FLOAT_DTYPE) return np.zeros(shape, dtype, order) def ones( - shape: Union[Integer, Tuple[int, ...]], + shape: Union[int, tuple[int, ...]], dtype: Optional[Type[DTypeNumber]] = None, order: Literal["C", "F"] = "C", ) -> NDArray: @@ -2462,13 +2468,13 @@ def ones( array([ 1., 1., 1.]) """ - dtype = cast(Type[DTypeFloating], optional(dtype, DEFAULT_FLOAT_DTYPE)) + dtype = optional(dtype, DEFAULT_FLOAT_DTYPE) return np.ones(shape, dtype, order) def full( - shape: Union[Integer, Tuple[int, ...]], + shape: Union[int, tuple[int, ...]], fill_value: Number, dtype: Optional[Type[DTypeNumber]] = None, order: Literal["C", "F"] = "C", @@ -2502,7 +2508,7 @@ def full( array([ 1., 1., 1.]) """ - dtype = cast(Type[DTypeFloating], optional(dtype, DEFAULT_FLOAT_DTYPE)) + dtype = optional(dtype, DEFAULT_FLOAT_DTYPE) return np.full(shape, fill_value, dtype, order) @@ -2517,7 +2523,7 @@ def index_along_last_axis(a: ArrayLike, indexes: ArrayLike) -> NDArray: a Array :math:`a` to be indexed. indexes - *Integer* array with the same shape as `a` but with one dimension + *int* array with the same shape as `a` but with one dimension fewer, containing indices to the last dimension of `a`. All elements must be numbers between `0` and `m` - 1. @@ -2532,7 +2538,7 @@ def index_along_last_axis(a: ArrayLike, indexes: ArrayLike) -> NDArray: If the array :math:`a` and ``indexes`` have incompatible shapes. :class:`IndexError` If ``indexes`` has elements outside of the allowed range of 0 to - `m` - 1 or if it's not an *integer* array. + `m` - 1 or if it's not an *int* array. Examples -------- diff --git a/colour/utilities/common.py b/colour/utilities/common.py index 28fd980a8d..db2a47a5b1 100644 --- a/colour/utilities/common.py +++ b/colour/utilities/common.py @@ -33,12 +33,9 @@ from colour.constants import INTEGER_THRESHOLD from colour.hints import ( Any, - Boolean, Callable, - Dict, DTypeBoolean, Generator, - Integer, Iterable, Literal, Mapping, @@ -132,10 +129,10 @@ class CacheRegistry: """ def __init__(self) -> None: - self._registry: Dict = {} + self._registry: dict = {} @property - def registry(self) -> Dict: + def registry(self) -> dict: """ Getter property for the cache registry. @@ -164,7 +161,7 @@ def __str__(self) -> str: } ) - def register_cache(self, name: str) -> Dict: + def register_cache(self, name: str) -> dict: """ Register a new cache with given name in the registry. @@ -367,7 +364,7 @@ def wrapper(*args: Any, **kwargs: Any) -> Any: return wrapper -def attest(condition: Union[Boolean, DTypeBoolean], message: str = ""): +def attest(condition: Union[bool, DTypeBoolean], message: str = ""): """ Provide the `assert` statement functionality without being disabled by optimised Python execution. @@ -384,7 +381,7 @@ def attest(condition: Union[Boolean, DTypeBoolean], message: str = ""): raise AssertionError(message) -def batch(sequence: Sequence, k: Union[Integer, Literal[3]] = 3) -> Generator: +def batch(sequence: Sequence, k: Union[int, Literal[3]] = 3) -> Generator: """ Return a batch generator from given sequence. @@ -410,7 +407,7 @@ def batch(sequence: Sequence, k: Union[Integer, Literal[3]] = 3) -> Generator: yield sequence[i : i + k] -_MULTIPROCESSING_ENABLED: Boolean = True +_MULTIPROCESSING_ENABLED: bool = True """*Colour* multiprocessing state.""" @@ -570,7 +567,7 @@ def terminate(self): pool.terminate() -def is_ctlrender_installed(raise_exception: Boolean = False) -> Boolean: +def is_ctlrender_installed(raise_exception: bool = False) -> bool: """ Return whether *ctlrender* is installed and available. @@ -612,7 +609,7 @@ def is_ctlrender_installed(raise_exception: Boolean = False) -> Boolean: return False -def is_graphviz_installed(raise_exception: Boolean = False) -> Boolean: +def is_graphviz_installed(raise_exception: bool = False) -> bool: """ Return whether *Graphviz* is installed and available. @@ -648,7 +645,7 @@ def is_graphviz_installed(raise_exception: Boolean = False) -> Boolean: return False -def is_matplotlib_installed(raise_exception: Boolean = False) -> Boolean: +def is_matplotlib_installed(raise_exception: bool = False) -> bool: """ Return whether *Matplotlib* is installed and available. @@ -684,7 +681,7 @@ def is_matplotlib_installed(raise_exception: Boolean = False) -> Boolean: return False -def is_networkx_installed(raise_exception: Boolean = False) -> Boolean: +def is_networkx_installed(raise_exception: bool = False) -> bool: """ Return whether *NetworkX* is installed and available. @@ -721,7 +718,7 @@ def is_networkx_installed(raise_exception: Boolean = False) -> Boolean: return False -def is_opencolorio_installed(raise_exception: Boolean = False) -> Boolean: +def is_opencolorio_installed(raise_exception: bool = False) -> bool: """ Return whether *OpenColorIO* is installed and available. @@ -757,7 +754,7 @@ def is_opencolorio_installed(raise_exception: Boolean = False) -> Boolean: return False -def is_openimageio_installed(raise_exception: Boolean = False) -> Boolean: +def is_openimageio_installed(raise_exception: bool = False) -> bool: """ Return whether *OpenImageIO* is installed and available. @@ -793,7 +790,7 @@ def is_openimageio_installed(raise_exception: Boolean = False) -> Boolean: return False -def is_pandas_installed(raise_exception: Boolean = False) -> Boolean: +def is_pandas_installed(raise_exception: bool = False) -> bool: """ Return whether *Pandas* is installed and available. @@ -829,7 +826,7 @@ def is_pandas_installed(raise_exception: Boolean = False) -> Boolean: return False -def is_tqdm_installed(raise_exception: Boolean = False) -> Boolean: +def is_tqdm_installed(raise_exception: bool = False) -> bool: """ Return whether *tqdm* is installed and available. @@ -865,7 +862,7 @@ def is_tqdm_installed(raise_exception: Boolean = False) -> Boolean: return False -def is_trimesh_installed(raise_exception: Boolean = False) -> Boolean: +def is_trimesh_installed(raise_exception: bool = False) -> bool: """ Return whether *Trimesh* is installed and available. @@ -963,7 +960,7 @@ def wrapped(*args: Any, **kwargs: Any) -> Any: return wrapper -def is_iterable(a: Any) -> Boolean: +def is_iterable(a: Any) -> bool: """ Return whether given variable :math:`a` is iterable. @@ -988,7 +985,7 @@ def is_iterable(a: Any) -> Boolean: return is_string(a) or (True if getattr(a, "__iter__", False) else False) -def is_string(a: Any) -> Boolean: +def is_string(a: Any) -> bool: """ Return whether given variable :math:`a` is a :class:`str`-like variable. @@ -1013,7 +1010,7 @@ def is_string(a: Any) -> Boolean: return True if isinstance(a, str) else False -def is_numeric(a: Any) -> Boolean: +def is_numeric(a: Any) -> bool: """ Return whether given variable :math:`a` is a :class:`Number`-like variable. @@ -1043,12 +1040,26 @@ def is_numeric(a: Any) -> Boolean: float, complex, np.integer, + np.int8, + np.int8, + np.int16, + np.int32, + np.int64, + np.uint8, + np.uint16, + np.uint32, + np.uint64, np.floating, - ), + np.float16, + np.float32, + np.float64, + np.csingle, + np.cdouble, + ), # pyright: ignore ) -def is_integer(a: Any) -> Boolean: +def is_integer(a: Any) -> bool: """ Return whether given variable :math:`a` is an :class:`numpy.integer`-like variable under given threshold. @@ -1079,7 +1090,7 @@ def is_integer(a: Any) -> Boolean: return abs(a - np.around(a)) <= INTEGER_THRESHOLD -def is_sibling(element: Any, mapping: Mapping) -> Boolean: +def is_sibling(element: Any, mapping: Mapping) -> bool: """ Return whether given element type is present in given mapping types. @@ -1101,7 +1112,7 @@ def is_sibling(element: Any, mapping: Mapping) -> Boolean: ) -def filter_kwargs(function: Callable, **kwargs: Any) -> Dict: +def filter_kwargs(function: Callable, **kwargs: Any) -> dict: """ Filter keyword arguments incompatible with the given function signature. @@ -1152,7 +1163,7 @@ def filter_kwargs(function: Callable, **kwargs: Any) -> Dict: return kwargs -def filter_mapping(mapping: Mapping, names: Union[str, Sequence[str]]) -> Dict: +def filter_mapping(mapping: Mapping, names: Union[str, Sequence[str]]) -> dict: """ Filter given mapping with given names. @@ -1191,7 +1202,7 @@ class instance. {'Element A': } """ - def filter_mapping_with_name(mapping: Mapping, name: str) -> Dict: + def filter_mapping_with_name(mapping: Mapping, name: str) -> dict: """ Filter given mapping with given name. @@ -1372,7 +1383,7 @@ def optional(value: Optional[T], default: T) -> T: return value -def slugify(object_: Any, allow_unicode: Boolean = False) -> str: +def slugify(object_: Any, allow_unicode: bool = False) -> str: """ Generate a *SEO* friendly and human-readable slug from given object. diff --git a/colour/utilities/data_structures.py b/colour/utilities/data_structures.py index e0c325d942..983d417942 100644 --- a/colour/utilities/data_structures.py +++ b/colour/utilities/data_structures.py @@ -35,14 +35,11 @@ from colour.hints import ( Any, - Boolean, - Dict, Generator, - Integer, Iterable, - List, Mapping, Optional, + Self, Union, ) from colour.utilities.documentation import is_documentation_building @@ -135,7 +132,7 @@ def __dir__(self) -> Iterable: Returns ------- :class:`list` - List of valid attributes for the :class:`dict`-like object. + list of valid attributes for the :class:`dict`-like object. """ return self.keys() @@ -195,7 +192,7 @@ class Lookup(dict): ['Jane', 'John'] """ - def keys_from_value(self, value: Any) -> List: + def keys_from_value(self, value: Any) -> list: """ Get the keys associated with given value. @@ -316,12 +313,12 @@ class CanonicalMapping(MutableMapping): def __init__( self, data: Optional[Union[Generator, Mapping]] = None, **kwargs: Any ) -> None: - self._data: Dict = dict() + self._data: dict = dict() self.update({} if data is None else data, **kwargs) @property - def data(self) -> Dict: + def data(self) -> dict: """ Getter property for the delimiter and case-insensitive :class:`dict`-like object data. @@ -502,13 +499,13 @@ def __iter__(self) -> Generator: yield from self._data.keys() - def __len__(self) -> Integer: + def __len__(self) -> int: """ Return the items count. Returns ------- - :class:`numpy.integer` + :class:`int` Items count. """ @@ -563,7 +560,7 @@ def __ne__(self, other: Any) -> bool: return not (self == other) @staticmethod - def _collision_warning(keys: List): + def _collision_warning(keys: list): """ Issue a runtime warning when given keys are colliding. @@ -818,14 +815,14 @@ class Node: 7 """ - _INSTANCE_ID: Integer = 1 + _INSTANCE_ID: int = 1 """ Node id counter. _INSTANCE_ID """ - def __new__(cls, *args: Any, **kwargs: Any) -> Node: + def __new__(cls, *args: Any, **kwargs: Any) -> Self: """ Return a new instance of the :class:`colour.utilities.Node` class. @@ -839,7 +836,7 @@ def __new__(cls, *args: Any, **kwargs: Any) -> Node: instance = super().__new__(cls) - instance._id = Node._INSTANCE_ID # type: ignore[attr-defined] + instance._id = Node._INSTANCE_ID # pyright: ignore Node._INSTANCE_ID += 1 return instance @@ -847,16 +844,18 @@ def __new__(cls, *args: Any, **kwargs: Any) -> Node: def __init__( self, name: Optional[str] = None, - parent: Optional[Node] = None, - children: Optional[List[Node]] = None, + parent: Optional[Self] = None, + children: Optional[list[Self]] = None, data: Optional[Any] = None, ) -> None: self._name: str = f"{self.__class__.__name__}#{self.id}" self.name = self._name if name is None else name - self._parent: Optional[Node] = None + self._parent: Optional[Self] = None self.parent = parent - self._children: List[Node] = [] - self.children = self._children if children is None else children + self._children: list[Self] = [] + self.children = ( # pyright: ignore + self._children if children is None else children + ) self._data: Optional[Any] = data @property @@ -891,7 +890,7 @@ def name(self, value: str): self._name = value @property - def parent(self) -> Optional[Node]: + def parent(self) -> Optional[Self]: """ Getter and setter property for the node parent. @@ -909,7 +908,7 @@ def parent(self) -> Optional[Node]: return self._parent @parent.setter - def parent(self, value: Optional[Node]): + def parent(self, value: Optional[Self]): """Setter for the **self.parent** property.""" from colour.utilities import attest @@ -918,7 +917,7 @@ def parent(self, value: Optional[Node]): attest( issubclass(value.__class__, Node), f'"parent" property: "{value}" is not a ' - f'"{Node.__class__.__name__}" subclass!', + f'"{self.__class__.__name__}" subclass!', ) value.children.append(self) @@ -926,7 +925,7 @@ def parent(self, value: Optional[Node]): self._parent = value @property - def children(self) -> List[Node]: + def children(self) -> list[Self]: """ Getter and setter property for the node children. @@ -944,7 +943,7 @@ def children(self) -> List[Node]: return self._children @children.setter - def children(self, value: List[Node]): + def children(self, value: list[Self]): """Setter for the **self.children** property.""" from colour.utilities import attest @@ -958,7 +957,7 @@ def children(self, value: List[Node]): attest( issubclass(element.__class__, Node), f'"children" property: A "{element}" element is not a ' - f'"{Node.__class__.__name__}" subclass!', + f'"{self.__class__.__name__}" subclass!', ) for node in value: @@ -967,20 +966,20 @@ def children(self, value: List[Node]): self._children = value @property - def id(self) -> Integer: + def id(self) -> int: """ Getter property for the node id. Returns ------- - :class:`numpy.integer` + :class:`int` Node id. """ - return self._id # type: ignore[attr-defined] + return self._id # pyright: ignore @property - def root(self) -> Node: + def root(self) -> Self: """ Getter property for the node tree. @@ -1023,7 +1022,7 @@ def siblings(self) -> Generator: """ if self.parent is None: - return (sibling for sibling in ()) # type: ignore[var-annotated] + return (sibling for sibling in ()) else: return ( sibling @@ -1062,19 +1061,19 @@ def __str__(self) -> str: return f"{self.__class__.__name__}#{self.id}({self._data})" - def __len__(self) -> Integer: + def __len__(self) -> int: """ Return the number of children of the node. Returns ------- - :class:`numpy.integer` + :class:`int` Number of children of the node. """ return len(list(self.walk())) - def is_root(self) -> Boolean: + def is_root(self) -> bool: """ Return whether the node is a root node. @@ -1096,7 +1095,7 @@ def is_root(self) -> Boolean: return self.parent is None - def is_inner(self) -> Boolean: + def is_inner(self) -> bool: """ Return whether the node is an inner node. @@ -1118,7 +1117,7 @@ def is_inner(self) -> Boolean: return all([not self.is_root(), not self.is_leaf()]) - def is_leaf(self) -> Boolean: + def is_leaf(self) -> bool: """ Return whether the node is a leaf node. @@ -1140,7 +1139,7 @@ def is_leaf(self) -> Boolean: return len(self._children) == 0 - def walk(self, ascendants: Boolean = False) -> Generator: + def walk(self, ascendants: bool = False) -> Generator: """ Return a generator used to walk into :class:`colour.utilities.Node` trees. @@ -1190,7 +1189,7 @@ def walk(self, ascendants: Boolean = False) -> Generator: yield from node.walk(ascendants=ascendants) - def render(self, tab_level: Integer = 0): + def render(self, tab_level: int = 0): """ Render the current node and its children as a string. diff --git a/colour/utilities/deprecation.py b/colour/utilities/deprecation.py index a0e9f339a2..7879aa648e 100644 --- a/colour/utilities/deprecation.py +++ b/colour/utilities/deprecation.py @@ -13,7 +13,7 @@ from operator import attrgetter from colour.utilities import attest, optional, usage_warning -from colour.hints import Any, Dict, List, ModuleType, Optional +from colour.hints import Any, ModuleType, Optional __author__ = "Colour Developers" __copyright__ = "Copyright 2013 Colour Developers" @@ -332,7 +332,7 @@ class ModuleAPI: ... # doctest: +SKIP """ - def __init__(self, module: ModuleType, changes: Optional[Dict] = None): + def __init__(self, module: ModuleType, changes: Optional[dict] = None): self._module = module self._changes = optional(changes, {}) @@ -373,7 +373,7 @@ def __getattr__(self, attribute: str) -> Any: return getattr(self._module, attribute) - def __dir__(self) -> List: + def __dir__(self) -> list: """ Return the list of names in the module local scope filtered according to the changes. @@ -430,7 +430,7 @@ def get_attribute(attribute: str) -> Any: return attrgetter(attribute)(module) -def build_API_changes(changes: dict) -> Dict: +def build_API_changes(changes: dict) -> dict: """ Build the effective API changes for a desired API changes mapping. @@ -507,7 +507,7 @@ def build_API_changes(changes: dict) -> Dict: return changes -def handle_arguments_deprecation(changes: dict, **kwargs: Any) -> Dict: +def handle_arguments_deprecation(changes: dict, **kwargs: Any) -> dict: """ Handle arguments deprecation according to desired API changes mapping. diff --git a/colour/utilities/documentation.py b/colour/utilities/documentation.py index 7dd3ea1d52..d17bb05579 100644 --- a/colour/utilities/documentation.py +++ b/colour/utilities/documentation.py @@ -7,8 +7,6 @@ from __future__ import annotations -from colour.hints import Boolean - import os __author__ = "Colour Developers" @@ -73,7 +71,7 @@ class DocstringTuple(tuple): pass -def is_documentation_building() -> Boolean: +def is_documentation_building() -> bool: """ Return whether the documentation is being built by checking whether the *READTHEDOCS* or *COLOUR_SCIENCE__DOCUMENTATION_BUILD* environment diff --git a/colour/utilities/metrics.py b/colour/utilities/metrics.py index 62215b3f2d..53a41c2ef4 100644 --- a/colour/utilities/metrics.py +++ b/colour/utilities/metrics.py @@ -23,11 +23,9 @@ from colour.algebra import sdiv, sdiv_mode from colour.hints import ( ArrayLike, - FloatingOrNDArray, - Integer, + NDArrayFloat, Number, Optional, - Tuple, Union, ) from colour.utilities import as_float, as_float_array, zeros @@ -48,8 +46,8 @@ def metric_mse( a: ArrayLike, b: ArrayLike, - axis: Optional[Union[Integer, Tuple[Integer]]] = None, -) -> FloatingOrNDArray: + axis: Optional[Union[int, tuple[int]]] = None, +) -> NDArrayFloat: """ Compute the mean squared error (MSE) or mean squared deviation (MSD) between given variables :math:`a` and :math:`b`. @@ -68,7 +66,7 @@ def metric_mse( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Mean squared error (MSE). References @@ -92,8 +90,8 @@ def metric_psnr( a: ArrayLike, b: ArrayLike, max_a: Number = 1, - axis: Optional[Union[Integer, Tuple[Integer]]] = None, -) -> FloatingOrNDArray: + axis: Optional[Union[int, tuple[int]]] = None, +) -> NDArrayFloat: """ Compute the peak signal-to-noise ratio (PSNR) between given variables :math:`a` and :math:`b`. @@ -114,7 +112,7 @@ def metric_psnr( Returns ------- - :class:`numpy.floating` or :class:`numpy.ndarray` + :class:`numpy.ndarray` Peak signal-to-noise ratio (PSNR). References diff --git a/colour/utilities/tests/test_array.py b/colour/utilities/tests/test_array.py index 70d32a90e0..b76182cd9e 100644 --- a/colour/utilities/tests/test_array.py +++ b/colour/utilities/tests/test_array.py @@ -1753,7 +1753,7 @@ def test_exceptions(self): indexes = np.array([123, 456]) index_along_last_axis(a, indexes) - # Non-integer indexes + # Non-int indexes with self.assertRaises(IndexError): indexes = np.array([0.0, 0.0]) index_along_last_axis(a, indexes) diff --git a/colour/utilities/tests/test_common.py b/colour/utilities/tests/test_common.py index 2edd4df344..a3d04829e2 100644 --- a/colour/utilities/tests/test_common.py +++ b/colour/utilities/tests/test_common.py @@ -8,7 +8,7 @@ import unicodedata from functools import partial -from colour.hints import Any, Floating, Number, Tuple +from colour.hints import Any, Number from colour.utilities import ( CacheRegistry, CanonicalMapping, @@ -370,14 +370,14 @@ def fn_a(a: Any) -> Any: return a - def fn_b(a: Any, b: Floating = 0) -> Tuple[Any, Floating]: + def fn_b(a: Any, b: float = 0) -> tuple[Any, float]: """:func:`filter_kwargs` unit tests :func:`fn_b` definition.""" return a, b def fn_c( - a: Any, b: Floating = 0, c: Floating = 0 - ) -> Tuple[Any, Floating, Floating]: + a: Any, b: float = 0, c: float = 0 + ) -> tuple[float, float, float]: """:func:`filter_kwargs` unit tests :func:`fn_c` definition.""" return a, b, c diff --git a/colour/utilities/tests/test_deprecated.py b/colour/utilities/tests/test_deprecated.py index dba77cf921..dd595270e3 100644 --- a/colour/utilities/tests/test_deprecated.py +++ b/colour/utilities/tests/test_deprecated.py @@ -27,7 +27,7 @@ def __getattr__(self, attribute) -> Any: try: sys.modules[ "colour.utilities.tests.test_deprecated" - ] = deprecated( # type: ignore[assignment] + ] = deprecated( # pyright: ignore sys.modules["colour.utilities.tests.test_deprecated"], { "OLD_NAME": ObjectRenamed( diff --git a/colour/utilities/verbose.py b/colour/utilities/verbose.py index 5d4d05fd41..2c30c64874 100644 --- a/colour/utilities/verbose.py +++ b/colour/utilities/verbose.py @@ -21,11 +21,7 @@ from colour.utilities import is_string, optional from colour.hints import ( Any, - Boolean, Callable, - Dict, - Integer, - List, LiteralWarning, Mapping, Generator, @@ -91,8 +87,8 @@ class ColourRuntimeWarning(Warning): def message_box( message: str, - width: Integer = 79, - padding: Integer = 3, + width: int = 79, + padding: int = 3, print_callable: Callable = print, ): """ @@ -172,7 +168,7 @@ def show_warning( message: Union[Warning, str], category: Type[Warning], filename: str, - lineno: Integer, + lineno: int, file: Optional[TextIO] = None, line: Optional[str] = None, ) -> None: @@ -482,28 +478,28 @@ def numpy_print_options(*args: Any, **kwargs: Any) -> Generator: np.set_printoptions(**options) -ANCILLARY_COLOUR_SCIENCE_PACKAGES: Dict[str, str] = {} +ANCILLARY_COLOUR_SCIENCE_PACKAGES: dict[str, str] = {} """ Ancillary *colour-science.org* packages to describe. ANCILLARY_COLOUR_SCIENCE_PACKAGES """ -ANCILLARY_RUNTIME_PACKAGES: Dict[str, str] = {} +ANCILLARY_RUNTIME_PACKAGES: dict[str, str] = {} """ Ancillary runtime packages to describe. ANCILLARY_RUNTIME_PACKAGES """ -ANCILLARY_DEVELOPMENT_PACKAGES: Dict[str, str] = {} +ANCILLARY_DEVELOPMENT_PACKAGES: dict[str, str] = {} """ Ancillary development packages to describe. ANCILLARY_DEVELOPMENT_PACKAGES """ -ANCILLARY_EXTRAS_PACKAGES: Dict[str, str] = {} +ANCILLARY_EXTRAS_PACKAGES: dict[str, str] = {} """ Ancillary extras packages to describe. @@ -512,10 +508,10 @@ def numpy_print_options(*args: Any, **kwargs: Any) -> Generator: def describe_environment( - runtime_packages: Boolean = True, - development_packages: Boolean = False, - extras_packages: Boolean = False, - print_environment: Boolean = True, + runtime_packages: bool = True, + development_packages: bool = False, + extras_packages: bool = False, + print_environment: bool = True, **kwargs: Any, ) -> defaultdict: """ @@ -636,7 +632,7 @@ def describe_environment( try: # pragma: no cover output = subprocess.check_output( # nosec ["git", "describe"], - cwd=colour.__path__[0], + cwd=colour.__path__[0], # pyright: ignore stderr=subprocess.STDOUT, ).strip() version = output.decode("utf-8") @@ -773,7 +769,7 @@ def _get_package_version(package: str, mapping: Mapping) -> str: def multiline_str( object_: Any, - attributes: List[Dict], + attributes: list[dict], header_underline: str = "=", section_underline: str = "-", separator: str = " : ", @@ -929,8 +925,8 @@ def multiline_str( def multiline_repr( object_: Any, - attributes: List[Dict], - reduce_array_representation: Boolean = True, + attributes: list[dict], + reduce_array_representation: bool = True, ) -> str: # noqa: D405,D410,D407,D411 """ Return an (almost) evaluable string representation of the given object. @@ -982,7 +978,7 @@ def multiline_repr( justify = len(f"{object_.__class__.__name__}") + 1 - def _format(attribute: Dict) -> str: + def _format(attribute: dict) -> str: """Format given attribute and its value.""" if attribute["name"] is not None: diff --git a/colour/volume/datasets/optimal_colour_stimuli.py b/colour/volume/datasets/optimal_colour_stimuli.py index 07970b964a..7667c02630 100644 --- a/colour/volume/datasets/optimal_colour_stimuli.py +++ b/colour/volume/datasets/optimal_colour_stimuli.py @@ -29,7 +29,7 @@ import numpy as np -from colour.hints import NDArray +from colour.hints import NDArrayFloat from colour.utilities import CanonicalMapping __author__ = "Colour Developers" @@ -46,7 +46,7 @@ "OPTIMAL_COLOUR_STIMULI_ILLUMINANTS", ] -OPTIMAL_COLOUR_STIMULI_A: NDArray = np.array( +OPTIMAL_COLOUR_STIMULI_A: NDArrayFloat = np.array( [ [0.1120, 0.1985, 10], [0.0859, 0.2957, 10], @@ -268,7 +268,7 @@ [0.4392, 0.4080, 95], [0.4294, 0.4151, 95], [0.4254, 0.4180, 95], - ] + ] # pyright: ignore ) """ *CIE Standard Illuminant A* *Optimal Colour Stimuli*. @@ -278,7 +278,7 @@ :cite:`Wyszecki2000bb` """ -OPTIMAL_COLOUR_STIMULI_C: NDArray = np.array( +OPTIMAL_COLOUR_STIMULI_C: NDArrayFloat = np.array( [ [0.1363, 0.0692, 10], [0.1308, 0.0792, 10], @@ -477,7 +477,7 @@ [0.3270, 0.3172, 95], [0.3160, 0.3069, 95], [0.3053, 0.3096, 95], - ] + ] # pyright: ignore ) """ *CIE Illuminant C* *Optimal Colour Stimuli*. @@ -487,7 +487,7 @@ :cite:`MacAdam1935a` """ -OPTIMAL_COLOUR_STIMULI_D65: NDArray = np.array( +OPTIMAL_COLOUR_STIMULI_D65: NDArrayFloat = np.array( [ [0.1346, 0.0747, 10], [0.0990, 0.1607, 10], @@ -729,7 +729,7 @@ [0.3103, 0.3214, 95], [0.3006, 0.3259, 95], [0.2900, 0.3308, 95], - ] + ] # pyright: ignore ) """ *CIE Standard Illuminant D Series D65* *Optimal Colour Stimuli*. diff --git a/colour/volume/macadam_limits.py b/colour/volume/macadam_limits.py index 877e699244..c57a7f2023 100644 --- a/colour/volume/macadam_limits.py +++ b/colour/volume/macadam_limits.py @@ -12,10 +12,8 @@ from colour.hints import ( ArrayLike, - Dict, - Floating, Literal, - NDArray, + NDArrayFloat, Optional, Union, ) @@ -34,11 +32,11 @@ "is_within_macadam_limits", ] -_CACHE_OPTIMAL_COLOUR_STIMULI_XYZ: Dict = CACHE_REGISTRY.register_cache( +_CACHE_OPTIMAL_COLOUR_STIMULI_XYZ: dict = CACHE_REGISTRY.register_cache( f"{__name__}._CACHE_OPTIMAL_COLOUR_STIMULI_XYZ" ) -_CACHE_OPTIMAL_COLOUR_STIMULI_XYZ_TRIANGULATIONS: Dict = ( +_CACHE_OPTIMAL_COLOUR_STIMULI_XYZ_TRIANGULATIONS: dict = ( CACHE_REGISTRY.register_cache( f"{__name__}._CACHE_OPTIMAL_COLOUR_STIMULI_XYZ_TRIANGULATIONS" ) @@ -47,7 +45,7 @@ def _XYZ_optimal_colour_stimuli( illuminant: Union[Literal["A", "C", "D65"], str] = "D65" -) -> NDArray: +) -> NDArrayFloat: """ Return given illuminant *Optimal Colour Stimuli* in *CIE XYZ* tristimulus values and caches it if not existing. @@ -84,8 +82,8 @@ def _XYZ_optimal_colour_stimuli( def is_within_macadam_limits( xyY: ArrayLike, illuminant: Union[Literal["A", "C", "D65"], str] = "D65", - tolerance: Optional[Floating] = None, -) -> NDArray: + tolerance: Optional[float] = None, +) -> NDArrayFloat: """ Return whether given *CIE xyY* colourspace array is within MacAdam limits of given illuminant. diff --git a/colour/volume/mesh.py b/colour/volume/mesh.py index c7fc76afb3..8576056c83 100644 --- a/colour/volume/mesh.py +++ b/colour/volume/mesh.py @@ -10,7 +10,7 @@ import numpy as np from scipy.spatial import Delaunay -from colour.hints import ArrayLike, Floating, NDArray, Optional +from colour.hints import ArrayLike, NDArrayFloat, Optional __author__ = "Colour Developers" __copyright__ = "Copyright 2013 Colour Developers" @@ -25,8 +25,8 @@ def is_within_mesh_volume( - points: ArrayLike, mesh: ArrayLike, tolerance: Optional[Floating] = None -) -> NDArray: + points: ArrayLike, mesh: ArrayLike, tolerance: Optional[float] = None +) -> NDArrayFloat: """ Return whether given points are within given mesh volume using Delaunay triangulation. diff --git a/colour/volume/pointer_gamut.py b/colour/volume/pointer_gamut.py index 1551dafcad..d1c25fac91 100644 --- a/colour/volume/pointer_gamut.py +++ b/colour/volume/pointer_gamut.py @@ -7,7 +7,7 @@ from __future__ import annotations -from colour.hints import ArrayLike, Floating, NDArray, Optional +from colour.hints import ArrayLike, NDArrayFloat, Optional from colour.models import ( Lab_to_XYZ, LCHab_to_Lab, @@ -29,8 +29,8 @@ def is_within_pointer_gamut( - XYZ: ArrayLike, tolerance: Optional[Floating] = None -) -> NDArray: + XYZ: ArrayLike, tolerance: Optional[float] = None +) -> NDArrayFloat: """ Return whether given *CIE XYZ* tristimulus values are within Pointer's Gamut volume. diff --git a/colour/volume/rgb.py b/colour/volume/rgb.py index b91fbd67dc..7520963304 100644 --- a/colour/volume/rgb.py +++ b/colour/volume/rgb.py @@ -22,12 +22,9 @@ from colour.hints import ( ArrayLike, Callable, - Floating, - Integer, Literal, - NDArray, + NDArrayFloat, Optional, - Tuple, Union, ) from colour.models import ( @@ -57,7 +54,7 @@ ] -def _wrapper_RGB_colourspace_volume_MonteCarlo(arguments: Tuple) -> Integer: +def _wrapper_RGB_colourspace_volume_MonteCarlo(arguments: tuple) -> int: """ Call the :func:`colour.volume.rgb.sample_RGB_colourspace_volume_MonteCarlo` definition with multiple arguments. @@ -69,7 +66,7 @@ def _wrapper_RGB_colourspace_volume_MonteCarlo(arguments: Tuple) -> Integer: Returns ------- - :class:`numpy.integer` + :class:`int` Inside *RGB* colourspace volume samples count. """ @@ -78,7 +75,7 @@ def _wrapper_RGB_colourspace_volume_MonteCarlo(arguments: Tuple) -> Integer: def sample_RGB_colourspace_volume_MonteCarlo( colourspace: RGB_Colourspace, - samples: Integer = 1000000, + samples: int = 1000000, limits: ArrayLike = np.array([[0, 100], [-150, 150], [-150, 150]]), illuminant_Lab: ArrayLike = CCS_ILLUMINANTS[ "CIE 1931 2 Degree Standard Observer" @@ -104,7 +101,7 @@ def sample_RGB_colourspace_volume_MonteCarlo( ] = "CAT02", random_generator: Callable = random_triplet_generator, random_state: Optional[np.random.RandomState] = None, -) -> Integer: +) -> int: """ Randomly sample the *CIE L\\*a\\*b\\** colourspace volume and returns the ratio of samples within the given *RGB* colourspace volume. @@ -130,7 +127,7 @@ def sample_RGB_colourspace_volume_MonteCarlo( Returns ------- - :class:`numpy.integer` + :class:`int` Within *RGB* colourspace volume samples count. Notes @@ -171,7 +168,7 @@ def sample_RGB_colourspace_volume_MonteCarlo( return len(RGB_w) -def RGB_colourspace_limits(colourspace: RGB_Colourspace) -> NDArray: +def RGB_colourspace_limits(colourspace: RGB_Colourspace) -> NDArrayFloat: """ Compute given *RGB* colourspace volume limits in *CIE L\\*a\\*b\\** colourspace. @@ -228,7 +225,7 @@ def RGB_colourspace_limits(colourspace: RGB_Colourspace) -> NDArray: def RGB_colourspace_volume_MonteCarlo( colourspace: RGB_Colourspace, - samples: Integer = 1000000, + samples: int = 1000000, limits: ArrayLike = np.array([[0, 100], [-150, 150], [-150, 150]]), illuminant_Lab: ArrayLike = CCS_ILLUMINANTS[ "CIE 1931 2 Degree Standard Observer" @@ -254,7 +251,7 @@ def RGB_colourspace_volume_MonteCarlo( ] = "CAT02", random_generator: Callable = random_triplet_generator, random_state: Optional[np.random.RandomState] = None, -) -> Floating: +) -> float: """ Perform given *RGB* colourspace volume computation using *Monte Carlo* method and multiprocessing. @@ -280,7 +277,7 @@ def RGB_colourspace_volume_MonteCarlo( Returns ------- - :class:`numpy.floating` + :class:`float` *RGB* colourspace volume. Notes @@ -337,10 +334,10 @@ def RGB_colourspace_volume_MonteCarlo( def RGB_colourspace_volume_coverage_MonteCarlo( colourspace: RGB_Colourspace, coverage_sampler: Callable, - samples: Integer = 1000000, + samples: int = 1000000, random_generator: Callable = random_triplet_generator, random_state: Optional[np.random.RandomState] = None, -) -> Floating: +) -> float: """ Return given *RGB* colourspace percentage coverage of an arbitrary volume. @@ -360,7 +357,7 @@ def RGB_colourspace_volume_coverage_MonteCarlo( Returns ------- - :class:`numpy.floating` + :class:`float` Percentage coverage of volume. Examples @@ -399,10 +396,10 @@ def RGB_colourspace_volume_coverage_MonteCarlo( def RGB_colourspace_pointer_gamut_coverage_MonteCarlo( colourspace: RGB_Colourspace, - samples: Integer = 1000000, + samples: int = 1000000, random_generator: Callable = random_triplet_generator, random_state: Optional[np.random.RandomState] = None, -) -> Floating: +) -> float: """ Return given *RGB* colourspace percentage coverage of Pointer's Gamut volume using *Monte Carlo* method. @@ -421,7 +418,7 @@ def RGB_colourspace_pointer_gamut_coverage_MonteCarlo( Returns ------- - :class:`numpy.floating` + :class:`float` Percentage coverage of *Pointer's Gamut* volume. Examples @@ -445,10 +442,10 @@ def RGB_colourspace_pointer_gamut_coverage_MonteCarlo( def RGB_colourspace_visible_spectrum_coverage_MonteCarlo( colourspace: RGB_Colourspace, - samples: Integer = 1000000, + samples: int = 1000000, random_generator: Callable = random_triplet_generator, random_state: Optional[np.random.RandomState] = None, -) -> Floating: +) -> float: """ Return given *RGB* colourspace percentage coverage of visible spectrum volume using *Monte Carlo* method. @@ -467,7 +464,7 @@ def RGB_colourspace_visible_spectrum_coverage_MonteCarlo( Returns ------- - :class:`numpy.floating` + :class:`float` Percentage coverage of visible spectrum volume. Examples diff --git a/colour/volume/spectrum.py b/colour/volume/spectrum.py index 8f0f57991d..c577a2e090 100644 --- a/colour/volume/spectrum.py +++ b/colour/volume/spectrum.py @@ -35,12 +35,8 @@ from colour.hints import ( Any, ArrayLike, - Boolean, - Dict, - Floating, - Integer, Literal, - NDArray, + NDArrayFloat, Optional, Union, ) @@ -68,20 +64,20 @@ interval of 5. """ -_CACHE_OUTER_SURFACE_XYZ: Dict = CACHE_REGISTRY.register_cache( +_CACHE_OUTER_SURFACE_XYZ: dict = CACHE_REGISTRY.register_cache( f"{__name__}._CACHE_OUTER_SURFACE_XYZ" ) -_CACHE_OUTER_SURFACE_XYZ_POINTS: Dict = CACHE_REGISTRY.register_cache( +_CACHE_OUTER_SURFACE_XYZ_POINTS: dict = CACHE_REGISTRY.register_cache( f"{__name__}._CACHE_OUTER_SURFACE_XYZ_POINTS" ) def generate_pulse_waves( - bins: Integer, + bins: int, pulse_order: Union[Literal["Bins", "Pulse Wave Width"], str] = "Bins", - filter_jagged_pulses: Boolean = False, -) -> NDArray: + filter_jagged_pulses: bool = False, +) -> NDArrayFloat: """ Generate the pulse waves of given number of bins necessary to totally stimulate the colour matching functions and produce the *Rösch-MacAdam* @@ -248,9 +244,9 @@ def XYZ_outer_surface( cmfs: Optional[MultiSpectralDistributions] = None, illuminant: Optional[SpectralDistribution] = None, point_order: Union[Literal["Bins", "Pulse Wave Width"], str] = "Bins", - filter_jagged_points: Boolean = False, + filter_jagged_points: bool = False, **kwargs: Any, -) -> NDArray: +) -> NDArrayFloat: """ Generate the *Rösch-MacAdam* colour solid, i.e. *CIE XYZ* colourspace outer surface, for given colour matching functions using multi-spectral @@ -388,9 +384,9 @@ def is_within_visible_spectrum( XYZ: ArrayLike, cmfs: Optional[MultiSpectralDistributions] = None, illuminant: Optional[SpectralDistribution] = None, - tolerance: Optional[Floating] = None, + tolerance: Optional[float] = None, **kwargs: Any, -) -> NDArray: +) -> NDArrayFloat: """ Return whether given *CIE XYZ* tristimulus values are within the visible spectrum volume, i.e. *Rösch-MacAdam* colour solid, for given colour diff --git a/docs/colour.hints.rst b/docs/colour.hints.rst index 9d9e959a3d..4b637db67e 100644 --- a/docs/colour.hints.rst +++ b/docs/colour.hints.rst @@ -8,60 +8,47 @@ Annotation Type Hints .. autosummary:: :toctree: generated/ + ModuleType Any Callable - Dict Generator Iterable Iterator - List + Literal Mapping - ModuleType Optional - Union + Protocol Sequence - SupportsIndex + TYPE_CHECKING TextIO - Tuple Type - TypedDict TypeVar + TypedDict + Union + cast + runtime_checkable + Self + ArrayLike + NDArray RegexFlag - DTypeBoolean - DTypeInteger - DTypeFloating + DTypeInt + DTypeFloat DTypeNumber DTypeComplex + DTypeBoolean DType - Integer - Floating Number - Complex - Boolean - Literal Dataclass - NestedSequence - ArrayLike - IntegerOrArrayLike - FloatingOrArrayLike - NumberOrArrayLike - ComplexOrArrayLike - BooleanOrArrayLike - ScalarType - StrOrArrayLike - NDArray - IntegerOrNDArray - FloatingOrNDArray - NumberOrNDArray - ComplexOrNDArray - BooleanOrNDArray - StrOrNDArray + NDArrayInt + NDArrayFloat + NDArrayNumber + NDArrayComplex + NDArrayBoolean + NDArrayStr TypeInterpolator TypeExtrapolator TypeLUTSequenceItem LiteralWarning - cast - diff --git a/docs/conf.py b/docs/conf.py index 5d3f193d99..2c9e43fd17 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -6,6 +6,7 @@ import os import re import setuptools.archive_util +import urllib.parse import urllib.request import colour as package # noqa @@ -79,27 +80,20 @@ autodoc_typehints = "both" autodoc_type_aliases = { "ArrayLike": "ArrayLike", - "Boolean": "bool", - "BooleanOrArrayLike": "BooleanOrArrayLike", - "BooleanOrNDArray": "BooleanOrNDArray", "DType": "DType", "DTypeBoolean": "DTypeBoolean", "DTypeComplex": "DTypeComplex", - "DTypeFloating": "DTypeFloating", - "DTypeInteger": "DTypeInteger", + "DTypeFloat": "DTypeFloat", + "DTypeInt": "DTypeInt", "DTypeNumber": "DTypeNumber", - "Floating": "float", - "FloatingOrArrayLike": "FloatingOrArrayLike", - "FloatingOrNDArray": "FloatingOrNDArray", - "Integer": "int", - "IntegerOrArrayLike": "IntegerOrArrayLike", - "IntegerOrNDArray": "IntegerOrNDArray", - "NestedSequence": "NestedSequence", + "Dataclass": "Dataclass", + "NDArrayBoolean": "NDArrayBoolean", + "NDArrayComplex": "NDArrayComplex", + "NDArrayFloat": "NDArrayFloat", + "NDArrayInt": "NDArrayInt", + "NDArrayNumber": "NDArrayNumber", + "NDArrayStr": "NDArrayStr", "Number": "Number", - "NumberOrArrayLike": "NumberOrArrayLike", - "NumberOrNDArray": "NumberOrNDArray", - "StrOrArrayLike": "StrOrArrayLike", - "StrOrNDArray": "StrOrNDArray", } autodoc_preserve_defaults = True diff --git a/pyproject.toml b/pyproject.toml index f19a39b1d0..ba2f4d84d4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -65,10 +65,10 @@ flake8 = { version = "*", optional = true } # Development dependency. flynt = { version = "*", optional = true } # Development dependency. invoke = { version = "*", optional = true } # Development dependency. jupyter = { version = "*", optional = true } # Development dependency. -mypy = { version = "*", optional = true } # Development dependency. pre-commit = { version = "*", optional = true } # Development dependency. pydata-sphinx-theme = { version = "*", optional = true } # Development dependency. pydocstyle = { version = "*", optional = true } # Development dependency. +pyright = { version = "*", optional = true } # Development dependency. pytest = { version = "*", optional = true } # Development dependency. pytest-cov = { version = "*", optional = true } # Development dependency. pytest-xdist = { version = "*", optional = true} #Development dependency @@ -89,10 +89,10 @@ flake8 = "*" flynt = "*" invoke = "*" jupyter = "*" -mypy = "*" pre-commit = "*" pydata-sphinx-theme = "*" pydocstyle = "*" +pyright = "*" pytest = "*" pytest-cov = "*" pytest-xdist = "*" @@ -114,10 +114,10 @@ development = [ "flynt", "invoke", "jupyter", - "mypy", "pre-commit", "pydata-sphinx-theme", "pydocstyle", + "pyright", "pytest", "pytest-cov", "pytest-xdist", @@ -146,7 +146,6 @@ line-length = 79 exclude = ''' /( \.git - | \.mypy_cache | build | dist )/ @@ -155,14 +154,19 @@ exclude = ''' [tool.flynt] line_length=999 -[tool.mypy] -plugins = "numpy.typing.mypy_plugin" -ignore_missing_imports = true - [tool.pydocstyle] convention = "numpy" add-ignore = "D104,D200,D202,D205,D301,D400" +[tool.pyright] +reportMissingImports = false +reportMissingModuleSource = false +reportUnboundVariable = false +reportUnnecessaryCast = true +reportUnnecessaryTypeIgnoreComment = true +reportUnsupportedDunderAll = false +reportUnusedExpression = false + [tool.pytest.ini_options] addopts = "-n auto --dist=loadscope --durations=5" diff --git a/requirements.txt b/requirements.txt index 68367823e7..47fa677992 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,7 +4,7 @@ appnope==0.1.3 argon2-cffi==21.3.0 argon2-cffi-bindings==21.2.0 astor==0.8.1 -asttokens==2.1.0 +asttokens==2.2.1 attrs==22.1.0 Babel==2.11.0 backcall==0.2.0 @@ -33,7 +33,7 @@ entrypoints==0.4 execnet==1.9.0 executing==1.2.0 fastjsonschema==2.16.2 -filelock==3.8.0 +filelock==3.8.2 flake8==6.0.0 flynt==0.77 fonttools==4.38.0 @@ -51,9 +51,9 @@ ipywidgets==8.0.2 jaraco.classes==3.2.3 jedi==0.18.2 Jinja2==3.1.2 -jsonschema==4.17.1 +jsonschema==4.17.3 jupyter==1.0.0 -jupyter_client==7.4.7 +jupyter_client==7.4.8 jupyter-console==6.4.4 jupyter_core==5.1.0 jupyter-server==1.23.3 @@ -68,11 +68,10 @@ matplotlib-inline==0.1.6 mccabe==0.7.0 mistune==2.0.4 more-itertools==9.0.0 -mypy==0.991 mypy-extensions==0.4.3 nbclassic==0.4.8 -nbclient==0.7.0 -nbconvert==7.2.5 +nbclient==0.7.2 +nbconvert==7.2.6 nbformat==5.7.0 nest-asyncio==1.5.6 networkx==2.8.8 @@ -89,7 +88,7 @@ pexpect==4.8.0 pickleshare==0.7.5 Pillow==9.3.0 pip==22.3.1 -pkginfo==1.8.3 +pkginfo==1.9.2 platformdirs==2.5.4 pluggy==1.0.0 pre-commit==2.20.0 @@ -108,13 +107,14 @@ pyflakes==3.0.1 Pygments==2.13.0 pygraphviz==1.10 pyparsing==3.0.9 +pyright==1.1.282 pyrsistent==0.19.2 pytest==7.2.0 pytest-cov==4.0.0 -pytest-xdist==3.0.2 +pytest-xdist==3.1.0 python-dateutil==2.8.2 pytz==2022.6 -pyupgrade==3.2.2 +pyupgrade==3.3.0 PyYAML==6.0 pyzmq==24.0.1 qtconsole==5.4.0 @@ -142,20 +142,20 @@ sphinxcontrib-jsmath==1.0.1 sphinxcontrib-qthelp==1.0.3 sphinxcontrib-serializinghtml==1.1.5 stack-data==0.6.2 -terminado==0.17.0 +terminado==0.17.1 tinycss2==1.2.1 tokenize-rt==5.0.0 toml==0.10.2 tomli==2.0.1 tornado==6.2 tqdm==4.64.1 -traitlets==5.5.0 +traitlets==5.6.0 trimesh==3.16.4 -twine==4.0.1 +twine==4.0.2 types-setuptools==65.6.0.1 typing_extensions==4.4.0 urllib3==1.26.13 -virtualenv==20.17.0 +virtualenv==20.17.1 wcwidth==0.2.5 webencodings==0.5.1 websocket-client==1.4.2 diff --git a/tasks.py b/tasks.py index 781a79d990..9bde6724da 100644 --- a/tasks.py +++ b/tasks.py @@ -13,13 +13,12 @@ import uuid import colour -from colour.hints import Boolean from colour.utilities import message_box import inspect if not hasattr(inspect, "getargspec"): - inspect.getargspec = inspect.getfullargspec + inspect.getargspec = inspect.getfullargspec # pyright: ignore from invoke import Context, task @@ -69,10 +68,10 @@ @task def clean( ctx: Context, - docs: Boolean = True, - bytecode: Boolean = False, - mypy: Boolean = True, - pytest: Boolean = True, + docs: bool = True, + bytecode: bool = False, + mypy: bool = True, + pytest: bool = True, ): """ Clean the project. @@ -116,8 +115,8 @@ def clean( @task def formatting( ctx: Context, - asciify: Boolean = True, - bibtex: Boolean = True, + asciify: bool = True, + bibtex: bool = True, ): """ Convert unicode characters to ASCII and cleanup the *BibTeX* file. @@ -163,8 +162,8 @@ def formatting( @task def quality( ctx: Context, - mypy: Boolean = True, - rstlint: Boolean = True, + mypy: bool = True, + rstlint: bool = True, ): """ Check the codebase with *Mypy* and lints various *restructuredText* @@ -237,7 +236,7 @@ def tests(ctx: Context): @task -def examples(ctx: Context, plots: Boolean = False): +def examples(ctx: Context, plots: bool = False): """ Run the examples. @@ -285,9 +284,9 @@ def preflight(ctx: Context): @task def docs( ctx: Context, - plots: Boolean = True, - html: Boolean = True, - pdf: Boolean = True, + plots: bool = True, + html: bool = True, + pdf: bool = True, ): """ Build the documentation. @@ -467,7 +466,7 @@ def sub_callable(match): @task -def virtualise(ctx: Context, tests: Boolean = True): +def virtualise(ctx: Context, tests: bool = True): """ Create a virtual environment for the project build. @@ -525,17 +524,17 @@ def tag(ctx: Context): file_content = file_handle.read() major_version = re.search( '__major_version__\\s+=\\s+"(.*)"', file_content - ).group( # type: ignore[union-attr] + ).group( # pyright: ignore 1 ) minor_version = re.search( '__minor_version__\\s+=\\s+"(.*)"', file_content - ).group( # type: ignore[union-attr] + ).group( # pyright: ignore 1 ) change_version = re.search( '__change_version__\\s+=\\s+"(.*)"', file_content - ).group( # type: ignore[union-attr] + ).group( # pyright: ignore 1 ) diff --git a/utilities/generate_plots.py b/utilities/generate_plots.py index d251fc5439..7eba9a05c2 100755 --- a/utilities/generate_plots.py +++ b/utilities/generate_plots.py @@ -483,7 +483,7 @@ def generate_documentation_plots(output_directory: str): output_directory, "Plotting_Plot_Image.png" ) path = os.path.join( - colour.__path__[0], + colour.__path__[0], # pyright: ignore "examples", "plotting", "resources", @@ -783,7 +783,7 @@ def generate_documentation_plots(output_directory: str): ), None, ], - ] + ] # pyright: ignore ) arguments["filename"] = os.path.join( output_directory, "Plotting_Plot_Constant_Hue_Loci.png" @@ -822,7 +822,11 @@ def generate_documentation_plots(output_directory: str): light_source = light_source.copy().align(SpectralShape(360, 830, 1)) cqs_i = colour_quality_scale(illuminant, additional_data=True) cqs_l = colour_quality_scale(light_source, additional_data=True) - plt.close(plot_colour_quality_bars([cqs_i, cqs_l], **arguments)[0]) + plt.close( + plot_colour_quality_bars( + [cqs_i, cqs_l], **arguments # pyright: ignore + )[0] + ) arguments["filename"] = os.path.join( output_directory,