Skip to content

Commit

Permalink
Merge branch 'feature/v0.4.7' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
unknown committed Oct 28, 2024
2 parents 9d74314 + 1799f2e commit e7a3ac0
Show file tree
Hide file tree
Showing 14 changed files with 78 additions and 84 deletions.
6 changes: 4 additions & 2 deletions colour/adaptation/zhai2018.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
Express, 26(6), 7724. doi:10.1364/OE.26.007724
"""

from __future__ import annotations

import numpy as np

from colour.adaptation import CHROMATIC_ADAPTATION_TRANSFORMS
from colour.algebra import vecmul
from colour.hints import ArrayLike, Literal, NDArrayFloat, Union
from colour.hints import ArrayLike, Literal, NDArrayFloat
from colour.utilities import (
as_float_array,
from_range_100,
Expand All @@ -44,7 +46,7 @@ def chromatic_adaptation_Zhai2018(
D_b: ArrayLike = 1,
D_d: ArrayLike = 1,
XYZ_wo: ArrayLike = np.array([1, 1, 1]),
transform: Union[Literal["CAT02", "CAT16"], str] = "CAT02",
transform: Literal["CAT02", "CAT16"] | str = "CAT02",
) -> NDArrayFloat:
"""
Adapt given sample colour :math:`XYZ_{\\beta}` tristimulus values from
Expand Down
36 changes: 19 additions & 17 deletions colour/appearance/llab.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
Colour_Appearance_and_Gamut_Mapping
"""

from __future__ import annotations

from collections import namedtuple
from dataclasses import dataclass, field

Expand All @@ -37,7 +39,7 @@
spow,
vecmul,
)
from colour.hints import ArrayLike, NDArrayFloat, Optional, Union
from colour.hints import ArrayLike, NDArrayFloat
from colour.utilities import (
CanonicalMapping,
MixinDataclassArithmetic,
Expand Down Expand Up @@ -201,14 +203,14 @@ class CAM_ReferenceSpecification_LLAB(MixinDataclassArithmetic):
:cite:`Fairchild2013x`, :cite:`Luo1996b`, :cite:`Luo1996c`
"""

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)
L_L: float | NDArrayFloat | None = field(default_factory=lambda: None)
Ch_L: float | NDArrayFloat | None = field(default_factory=lambda: None)
h_L: float | NDArrayFloat | None = field(default_factory=lambda: None)
s_L: float | NDArrayFloat | None = field(default_factory=lambda: None)
C_L: float | NDArrayFloat | None = field(default_factory=lambda: None)
HC: float | NDArrayFloat | None = field(default_factory=lambda: None)
A_L: float | NDArrayFloat | None = field(default_factory=lambda: None)
B_L: float | NDArrayFloat | None = field(default_factory=lambda: None)


@dataclass
Expand Down Expand Up @@ -248,14 +250,14 @@ class CAM_Specification_LLAB(MixinDataclassArithmetic):
:cite:`Fairchild2013x`, :cite:`Luo1996b`, :cite:`Luo1996c`
"""

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)
J: float | NDArrayFloat | None = field(default_factory=lambda: None)
C: float | NDArrayFloat | None = field(default_factory=lambda: None)
h: float | NDArrayFloat | None = field(default_factory=lambda: None)
s: float | NDArrayFloat | None = field(default_factory=lambda: None)
M: float | NDArrayFloat | None = field(default_factory=lambda: None)
HC: float | NDArrayFloat | None = field(default_factory=lambda: None)
a: float | NDArrayFloat | None = field(default_factory=lambda: None)
b: float | NDArrayFloat | None = field(default_factory=lambda: None)


def XYZ_to_LLAB(
Expand Down
4 changes: 2 additions & 2 deletions colour/constants/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import numpy as np

from colour.hints import DTypeFloat, Type, Union, cast
from colour.hints import DTypeFloat, Type, cast
from colour.utilities.documentation import (
DocstringFloat,
is_documentation_building,
Expand Down Expand Up @@ -55,7 +55,7 @@
"""

DTYPE_INT_DEFAULT: Type[np.int32 | np.int64] = cast(
Type[Union[np.int32, np.int64]],
Type[np.int32 | np.int64],
np.sctypeDict.get(
os.environ.get("COLOUR_SCIENCE__DEFAULT_INT_DTYPE", "int64"), np.int64
),
Expand Down
4 changes: 1 addition & 3 deletions colour/continuous/signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,11 @@
DTypeFloat,
Literal,
NDArrayFloat,
Optional,
ProtocolExtrapolator,
ProtocolInterpolator,
Real,
Self,
Type,
Union,
cast,
)
from colour.utilities import (
Expand Down Expand Up @@ -1097,7 +1095,7 @@ def arithmetical_operation(
@staticmethod
@ndarray_copy_enable(True)
def signal_unpack_data(
data=Optional[Union[ArrayLike, dict, Series, "Signal"]],
data=ArrayLike | dict | Series | "Signal" | None,
domain: ArrayLike | None = None,
dtype: Type[DTypeFloat] | None = None,
) -> tuple:
Expand Down
3 changes: 2 additions & 1 deletion colour/graph/conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from __future__ import annotations

import inspect
import itertools
import re
import sys
import textwrap
Expand Down Expand Up @@ -1095,7 +1096,7 @@ def _conversion_path(source: str, target: str) -> List[Callable]:

return [
CONVERSION_GRAPH.get_edge_data(a, b)["conversion_function"] # pyright: ignore
for a, b in zip(path[:-1], path[1:])
for a, b in itertools.pairwise(path)
]


Expand Down
36 changes: 16 additions & 20 deletions colour/hints/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
List,
Literal,
NewType,
Optional,
Protocol,
Set,
SupportsIndex,
Expand All @@ -31,7 +30,6 @@
Type,
TypeVar,
TypedDict,
Union,
cast,
overload,
runtime_checkable,
Expand Down Expand Up @@ -61,7 +59,6 @@
"Literal",
"Mapping",
"NewType",
"Optional",
"Protocol",
"Sequence",
"Set",
Expand All @@ -72,7 +69,6 @@
"Type",
"TypeVar",
"TypedDict",
"Union",
"cast",
"overload",
"runtime_checkable",
Expand Down Expand Up @@ -116,30 +112,30 @@

RegexFlag = NewType("RegexFlag", re.RegexFlag)

DTypeInt = Union[
np.int8,
np.int16,
np.int32,
np.int64,
np.uint8,
np.uint16,
np.uint32,
np.uint64,
]
DTypeFloat = Union[np.float16, np.float32, np.float64]
DTypeReal = Union[DTypeInt, DTypeFloat]
DTypeComplex = Union[np.csingle, np.cdouble]
DTypeInt = (
np.int8
| np.int16
| np.int32
| np.int64
| np.uint8
| np.uint16
| np.uint32
| np.uint64
)
DTypeFloat = np.float16 | np.float32 | np.float64
DTypeReal = DTypeInt | DTypeFloat
DTypeComplex = np.csingle | np.cdouble
DTypeBoolean = np.bool_
DType = Union[DTypeBoolean, DTypeReal, DTypeComplex]
DType = DTypeBoolean | DTypeReal | DTypeComplex

Real = Union[int, float]
Real = int | float

# TODO: Revisit to use Protocol.
Dataclass = Any

NDArrayInt = NDArray[DTypeInt]
NDArrayFloat = NDArray[DTypeFloat]
NDArrayReal = NDArray[Union[DTypeInt, DTypeFloat]]
NDArrayReal = NDArray[DTypeInt | DTypeFloat]
NDArrayComplex = NDArray[DTypeComplex]
NDArrayBoolean = NDArray[DTypeBoolean]
NDArrayStr = NDArray[np.str_]
Expand Down
3 changes: 1 addition & 2 deletions colour/io/fichet2021.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
NDArrayFloat,
Sequence,
Tuple,
Union,
)
from colour.io.image import (
MAPPING_BIT_DEPTH,
Expand Down Expand Up @@ -114,7 +113,7 @@
"""


ComponentsFichet2021 = Dict[Union[str, float], Tuple[NDArrayFloat, NDArrayFloat]]
ComponentsFichet2021 = Dict[str | float, Tuple[NDArrayFloat, NDArrayFloat]]


def match_groups_to_nm(
Expand Down
5 changes: 1 addition & 4 deletions colour/io/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
Literal,
NDArrayFloat,
NDArrayReal,
Optional,
Sequence,
Tuple,
Type,
Expand Down Expand Up @@ -104,9 +103,7 @@ class Image_Specification_Attribute:

name: str
value: Any
type_: Optional[ # noqa: UP007
OpenImageIO.TypeDesc # pyright: ignore # noqa: F821
] = field( # noqa: RUF100
type_: OpenImageIO.TypeDesc | None = field( # noqa: F821, RUF100 # pyright: ignore # noqa: F821
default_factory=lambda: None
)

Expand Down
4 changes: 2 additions & 2 deletions colour/models/rgb/itut_h_273.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@

import numpy as np

from colour.hints import Any, Callable, Dict, NDArrayFloat, Union
from colour.hints import Any, Callable, Dict, NDArrayFloat
from colour.models.rgb.datasets.dcdm_xyz import (
CCS_WHITEPOINT_DCDM_XYZ,
MATRIX_DCDM_XYZ_TO_XYZ,
Expand Down Expand Up @@ -187,7 +187,7 @@


def _clipped_domain_function(
function: Callable, domain: Union[list, tuple] = (0, 1)
function: Callable, domain: list | tuple = (0, 1)
) -> Callable:
"""
Wrap given function and produce a new callable clipping the input value to
Expand Down
35 changes: 18 additions & 17 deletions colour/models/rgb/transfer_functions/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from functools import partial

from colour.hints import (
Expand All @@ -15,7 +17,6 @@
LiteralCCTFDecoding,
LiteralOOTF,
LiteralOOTFInverse,
Union,
)
from colour.utilities import (
CanonicalMapping,
Expand Down Expand Up @@ -418,8 +419,8 @@


def log_encoding(
value: ArrayLike, function: Union[LiteralLogEncoding, str] = "Cineon", **kwargs: Any
) -> Union[NDArrayFloat, NDArrayInt]:
value: ArrayLike, function: LiteralLogEncoding | str = "Cineon", **kwargs: Any
) -> NDArrayFloat | NDArrayInt:
"""
Encode *scene-referred* exposure values to :math:`R'G'B'` video component
signal value using given *log* encoding function.
Expand Down Expand Up @@ -537,8 +538,8 @@ def log_encoding(


def log_decoding(
value: Union[ArrayLike, ArrayLike],
function: Union[LiteralLogDecoding, str] = "Cineon",
value: ArrayLike,
function: LiteralLogDecoding | str = "Cineon",
**kwargs: Any,
) -> NDArrayFloat:
"""
Expand Down Expand Up @@ -650,7 +651,7 @@ def log_decoding(


def oetf(
value: ArrayLike, function: Union[LiteralOETF, str] = "ITU-R BT.709", **kwargs: Any
value: ArrayLike, function: LiteralOETF | str = "ITU-R BT.709", **kwargs: Any
) -> NDArrayFloat:
"""
Encode estimated tristimulus values in a scene to :math:`R'G'B'` video
Expand Down Expand Up @@ -724,7 +725,7 @@ def oetf(

def oetf_inverse(
value: ArrayLike,
function: Union[LiteralOETFInverse, str] = "ITU-R BT.709",
function: LiteralOETFInverse | str = "ITU-R BT.709",
**kwargs: Any,
) -> NDArrayFloat:
"""
Expand Down Expand Up @@ -798,8 +799,8 @@ def oetf_inverse(


def eotf(
value: Union[ArrayLike, ArrayLike],
function: Union[LiteralEOTF, str] = "ITU-R BT.1886",
value: ArrayLike,
function: LiteralEOTF | str = "ITU-R BT.1886",
**kwargs: Any,
) -> NDArrayFloat:
"""
Expand Down Expand Up @@ -870,9 +871,9 @@ def eotf(

def eotf_inverse(
value: ArrayLike,
function: Union[LiteralEOTFInverse, str] = "ITU-R BT.1886",
function: LiteralEOTFInverse | str = "ITU-R BT.1886",
**kwargs,
) -> Union[NDArrayFloat, NDArrayInt]:
) -> NDArrayFloat | NDArrayInt:
"""
Encode estimated tristimulus values in a scene to :math:`R'G'B'` video
component signal value using given inverse electro-optical transfer
Expand Down Expand Up @@ -968,8 +969,8 @@ def eotf_inverse(


def cctf_encoding(
value: ArrayLike, function: Union[LiteralCCTFEncoding, str] = "sRGB", **kwargs: Any
) -> Union[NDArrayFloat, NDArrayInt]:
value: ArrayLike, function: LiteralCCTFEncoding | str = "sRGB", **kwargs: Any
) -> NDArrayFloat | NDArrayInt:
"""
Encode linear :math:`RGB` values to non-linear :math:`R'G'B'` values using
given encoding colour component transfer function (Encoding CCTF).
Expand Down Expand Up @@ -1070,8 +1071,8 @@ def cctf_encoding(


def cctf_decoding(
value: Union[ArrayLike, ArrayLike],
function: Union[LiteralCCTFDecoding, str] = "sRGB",
value: ArrayLike,
function: LiteralCCTFDecoding | str = "sRGB",
**kwargs: Any,
) -> NDArrayFloat:
"""
Expand Down Expand Up @@ -1159,7 +1160,7 @@ def cctf_decoding(

def ootf(
value: ArrayLike,
function: Union[LiteralOOTF, str] = "ITU-R BT.2100 PQ",
function: LiteralOOTF | str = "ITU-R BT.2100 PQ",
**kwargs: Any,
) -> NDArrayFloat:
"""
Expand Down Expand Up @@ -1217,7 +1218,7 @@ def ootf(

def ootf_inverse(
value: ArrayLike,
function: Union[LiteralOOTFInverse, str] = "ITU-R BT.2100 PQ",
function: LiteralOOTFInverse | str = "ITU-R BT.2100 PQ",
**kwargs: Any,
) -> NDArrayFloat:
"""
Expand Down
Loading

0 comments on commit e7a3ac0

Please sign in to comment.