Skip to content

PR: Add domain-range scale annotations.#1371

Merged
KelSolaar merged 10 commits intodevelopfrom
feature/domain-range-scale-annotations
Nov 2, 2025
Merged

PR: Add domain-range scale annotations.#1371
KelSolaar merged 10 commits intodevelopfrom
feature/domain-range-scale-annotations

Conversation

@KelSolaar
Copy link
Copy Markdown
Member

@KelSolaar KelSolaar commented Oct 30, 2025

Summary

This PR adds domain-range scale annotations to most of our functions as a special form of lean metadata on parameters and return values:

def XYZ_to_CIECAM16(
    XYZ: Annotated[ArrayLike, 100],
    XYZ_w: Annotated[ArrayLike, 100],
    L_A: ArrayLike,
    Y_b: ArrayLike,
    surround: (
        InductionFactors_CIECAM02 | InductionFactors_CIECAM16
    ) = VIEWING_CONDITIONS_CIECAM16["Average"],
    discount_illuminant: bool = False,
    compute_H: bool = True,
) -> Annotated[CAM_Specification_CIECAM16, (100, 100, 360, 100, 100, 100, 400)]:


def XYZ_to_Lab(
    XYZ: Annotated[ArrayLike, 1],
    illuminant: ArrayLike = CCS_ILLUMINANTS["CIE 1931 2 Degree Standard Observer"][
        "D65"
    ],
) -> Annotated[NDArrayFloat, 100]:

They can then be retrieved with the new colour.get_domain_range_scale_metadata definition:

>>> from colour.hints import Annotated, ArrayLike, NDArrayFloat
>>> def example_function(
...     XYZ: Annotated[ArrayLike, 1],
...     illuminant: ArrayLike = None,
... ) -> Annotated[NDArrayFloat, 100]:
...     pass
>>> metadata = get_domain_range_scale_metadata(example_function)
>>> metadata["domain"]
{'XYZ': 1}
>>> metadata["range"]
100

The most common cases have dedicated type aliases:

  • Domain1 : 1,
  • Domain10 : 10,
  • Domain100 : 100,
  • Domain360 : 360,
  • Domain100_100_360 : (100, 100, 360),
  • Range1 : 1,
  • Range10 : 10,
  • Range100 : 100,
  • Range360 : 360,
  • Range100_100_360 : (100, 100, 360),

Thus XYZ_to_Lab is effectively

def XYZ_to_Lab(
    XYZ: Domain1,
    illuminant: ArrayLike = CCS_ILLUMINANTS["CIE 1931 2 Degree Standard Observer"][
        "D65"
    ],
) -> Range100:

The conversion graph is now able to input and output at the reference scale using the new from_reference and to_reference parameters.

I took that opportunity to simplify the docstring tables and cross-check them.

Preflight

Code Style and Quality

  • Unit tests have been implemented and passed.
  • Pyright static checking has been run and passed.
  • Pre-commit hooks have been run and passed.
  • New transformations have been added to the Automatic Colour Conversion Graph.
  • New transformations have been exported to the relevant namespaces, e.g. colour, colour.models.

Documentation

  • New features are documented along with examples if relevant.
  • The documentation is Sphinx and numpydoc compliant.

@KelSolaar KelSolaar force-pushed the feature/domain-range-scale-annotations branch from 2570a24 to 259f218 Compare October 31, 2025 20:52
@coveralls
Copy link
Copy Markdown

coveralls commented Oct 31, 2025

Coverage Status

coverage: 99.24% (-0.007%) from 99.247%
when pulling d6d982c on feature/domain-range-scale-annotations
into 63b475d on develop.

@KelSolaar KelSolaar force-pushed the feature/domain-range-scale-annotations branch 3 times, most recently from b6a12cd to c8b5029 Compare November 1, 2025 21:15
@KelSolaar KelSolaar marked this pull request as ready for review November 1, 2025 21:15
@KelSolaar KelSolaar added this to the v0.4.7 milestone Nov 1, 2025
@KelSolaar KelSolaar force-pushed the feature/domain-range-scale-annotations branch 5 times, most recently from fef5e66 to a788883 Compare November 2, 2025 20:42
@KelSolaar KelSolaar force-pushed the feature/domain-range-scale-annotations branch from a788883 to 88b6835 Compare November 2, 2025 21:01
@KelSolaar KelSolaar force-pushed the feature/domain-range-scale-annotations branch from 92cbd1e to d6d982c Compare November 2, 2025 21:06
@KelSolaar KelSolaar merged commit b027924 into develop Nov 2, 2025
29 of 32 checks passed
@KelSolaar KelSolaar deleted the feature/domain-range-scale-annotations branch November 14, 2025 08:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants