Skip to content

Commit 7a1e114

Browse files
lassefschmidtKelSolaar
authored andcommitted
Address raised comments on PR. Renamed new functions and title case for correction method function argument
1 parent 014f5a3 commit 7a1e114

File tree

3 files changed

+44
-39
lines changed

3 files changed

+44
-39
lines changed

colour/difference/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
)
6767
from .din99 import delta_E_DIN99
6868
from .huang2015 import power_function_Huang2015
69-
from .metamerism import metamerism_index_from_Lab, metamerism_index_from_XYZ
69+
from .metamerism import Lab_to_metamerism_index, XYZ_to_metamerism_index
7070
from .stress import INDEX_STRESS_METHODS, index_stress, index_stress_Garcia2007
7171

7272
__all__ = [
@@ -101,8 +101,8 @@
101101
"index_stress_Garcia2007",
102102
]
103103
__all__ += [
104-
"metamerism_index_from_Lab",
105-
"metamerism_index_from_XYZ",
104+
"Lab_to_metamerism_index",
105+
"XYZ_to_metamerism_index",
106106
]
107107

108108
DELTA_E_METHODS: CanonicalMapping = CanonicalMapping(

colour/difference/metamerism.py

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
"""
22
:math:`M_{t}` - Metamerism Index
3-
====================================================
3+
================================
44
55
Define the :math:`M_{t}` metamerism computation objects.
66
7-
- :func:`colour.difference.metamerism_index_from_Lab`
8-
- :func:`colour.difference.metamerism_index_from_XYZ`
7+
- :func:`colour.difference.Lab_to_metamerism_index`
8+
- :func:`colour.difference.XYZ_to_metamerism_index`
99
1010
References
1111
----------
@@ -30,6 +30,7 @@
3030
from colour.utilities import (
3131
as_array,
3232
filter_kwargs,
33+
validate_method,
3334
)
3435

3536
__author__ = "Colour Developers"
@@ -40,17 +41,17 @@
4041
__status__ = "Production"
4142

4243
__all__ = [
43-
"metamerism_index_from_Lab",
44-
"metamerism_index_from_XYZ",
44+
"Lab_to_metamerism_index",
45+
"XYZ_to_metamerism_index",
4546
]
4647

4748

48-
def metamerism_index_from_Lab(
49+
def Lab_to_metamerism_index(
4950
Lab_spl_t: Domain100,
5051
Lab_std_t: Domain100,
5152
Lab_spl_r: Domain100,
5253
Lab_std_r: Domain100,
53-
correction: Literal["additive", "multiplicative"] | str = "additive",
54+
correction: Literal["Additive", "Multiplicative"] | str = "Additive",
5455
method: LiteralDeltaEMethod | str = "CIE 2000",
5556
**kwargs: Any,
5657
) -> NDArrayFloat:
@@ -79,7 +80,7 @@ def metamerism_index_from_Lab(
7980
*CIE L\\*a\\*b\\** colourspace array of colour standard under
8081
reference illuminant.
8182
correction
82-
Correction method to apply, either 'additive' or 'multiplicative'.
83+
Correction method to apply, either 'Additive' or 'Multiplicative'.
8384
metric
8485
Colour difference metric to use.
8586
@@ -130,26 +131,28 @@ def metamerism_index_from_Lab(
130131
>>> Lab_std_t = np.array([38.17781, -17.4939, 21.0618])
131132
>>> Lab_spl_r = np.array([38.83253, -19.8787, 20.0453])
132133
>>> Lab_spl_t = np.array([37.9013, -19.56327, 16.9346])
133-
>>> metamerism_index_from_Lab(
134+
>>> Lab_to_metamerism_index(
134135
... Lab_spl_t,
135136
... Lab_std_t,
136137
... Lab_spl_r,
137138
... Lab_std_r,
138-
... correction="additive",
139+
... correction="Additive",
139140
... method="CIE 1976",
140141
... ) # doctest: +ELLIPSIS
141142
3.8267581...
142-
>>> metamerism_index_from_Lab(
143+
>>> Lab_to_metamerism_index(
143144
... Lab_spl_t,
144145
... Lab_std_t,
145146
... Lab_spl_r,
146147
... Lab_std_r,
147-
... correction="multiplicative",
148+
... correction="Multiplicative",
148149
... method="CIE 1976",
149150
... ) # doctest: +ELLIPSIS
150151
3.9842216...
151152
"""
152153

154+
correction = validate_method(correction, ("Additive", "Multiplicative"))
155+
153156
if correction == "additive":
154157
Lab_corr_t = as_array(Lab_spl_t) - (as_array(Lab_spl_r) - as_array(Lab_std_r))
155158

@@ -164,12 +167,12 @@ def metamerism_index_from_Lab(
164167
)
165168

166169

167-
def metamerism_index_from_XYZ(
170+
def XYZ_to_metamerism_index(
168171
XYZ_spl_t: Domain1,
169172
XYZ_std_t: Domain1,
170173
XYZ_spl_r: Domain1,
171174
XYZ_std_r: Domain1,
172-
correction: Literal["additive", "multiplicative"] | str = "multiplicative",
175+
correction: Literal["Additive", "Multiplicative"] | str = "Multiplicative",
173176
method: LiteralDeltaEMethod | str = "CIE 2000",
174177
**kwargs: Any,
175178
) -> NDArrayFloat:
@@ -200,8 +203,8 @@ def metamerism_index_from_XYZ(
200203
*CIE XYZ* tristimulus array of the standard under reference
201204
illuminant.
202205
correction
203-
Correction method to apply, either 'additive' or
204-
'multiplicative'.
206+
Correction method to apply, either 'Additive' or
207+
'Multiplicative'.
205208
method
206209
Colour-difference method.
207210
@@ -257,7 +260,7 @@ def metamerism_index_from_XYZ(
257260
>>> XYZ_std_t = np.array([8.96442, 10.1878, 1.6663]) / 100
258261
>>> XYZ_spl_r = np.array([7.6933, 10.5616, 5.54474]) / 100
259262
>>> XYZ_spl_t = np.array([8.56438, 10.0324, 1.9315]) / 100
260-
>>> metamerism_index_from_XYZ(
263+
>>> XYZ_to_metamerism_index(
261264
... XYZ_spl_t,
262265
... XYZ_std_t,
263266
... XYZ_spl_r,
@@ -267,7 +270,7 @@ def metamerism_index_from_XYZ(
267270
... illuminant=CCS_ILLUMINANTS["CIE 1964 10 Degree Standard Observer"]["A"],
268271
... ) # doctest: +ELLIPSIS
269272
3.7906989...
270-
>>> metamerism_index_from_XYZ(
273+
>>> XYZ_to_metamerism_index(
271274
... XYZ_spl_t,
272275
... XYZ_std_t,
273276
... XYZ_spl_r,
@@ -279,6 +282,8 @@ def metamerism_index_from_XYZ(
279282
4.6910648...
280283
"""
281284

285+
correction = validate_method(correction, ("Additive", "Multiplicative"))
286+
282287
if correction == "additive":
283288
XYZ_corr_t = as_array(XYZ_spl_t) - (as_array(XYZ_spl_r) - as_array(XYZ_std_r))
284289

colour/difference/tests/test_metamerism.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
from colour.constants import TOLERANCE_ABSOLUTE_TESTS
88
from colour.difference.metamerism import (
9-
metamerism_index_from_Lab,
10-
metamerism_index_from_XYZ,
9+
Lab_to_metamerism_index,
10+
XYZ_to_metamerism_index,
1111
)
1212
from colour.utilities import domain_range_scale
1313

@@ -19,33 +19,33 @@
1919
__status__ = "Production"
2020

2121
__all__ = [
22-
"TestMetamerism_Index_From_Lab",
23-
"TestMetamerism_Index_From_XYZ",
22+
"TestLab_to_Metamerism_Index",
23+
"TestXYZ_to_Metamerism_Index",
2424
]
2525

2626

27-
class TestMetamerism_Index_From_Lab:
27+
class TestLab_to_Metamerism_Index:
2828
"""
29-
Define :func:`colour.difference.metamerism.metamerism_index_from_Lab`
29+
Define :func:`colour.difference.metamerism.Lab_to_metamerism_index`
3030
definition unit tests methods.
3131
"""
3232

33-
def test_domain_range_scale_metamerism_index_from_lab(self) -> None:
33+
def test_domain_range_scale_Lab_to_metamerism_index(self) -> None:
3434
"""
35-
Test :func:`colour.difference.metamerism.metamerism_index_from_Lab`
35+
Test :func:`colour.difference.metamerism.Lab_to_metamerism_index`
3636
definition domain and range scale support.
3737
"""
3838

3939
Lab_1 = np.array([48.99183622, -0.10561667, 400.65619925])
4040
offset = np.array([0, 0, 2])
4141

42-
c = ("additive", "multiplicative")
42+
c = ("Additive", "Multiplicative")
4343
m = ("CIE 1976", "CIE 1994", "CIE 2000", "CMC", "DIN99")
4444
it = [
4545
(
4646
correction,
4747
method,
48-
metamerism_index_from_Lab(
48+
Lab_to_metamerism_index(
4949
Lab_1 + offset,
5050
Lab_1,
5151
Lab_1,
@@ -63,7 +63,7 @@ def test_domain_range_scale_metamerism_index_from_lab(self) -> None:
6363
for scale, factor in d_r:
6464
with domain_range_scale(scale):
6565
np.testing.assert_allclose(
66-
metamerism_index_from_Lab(
66+
Lab_to_metamerism_index(
6767
(Lab_1 + offset) * factor,
6868
Lab_1 * factor,
6969
Lab_1 * factor,
@@ -76,28 +76,28 @@ def test_domain_range_scale_metamerism_index_from_lab(self) -> None:
7676
)
7777

7878

79-
class TestMetamerism_Index_From_XYZ:
79+
class TestXYZ_to_Metamerism_Index:
8080
"""
81-
Define :func:`colour.difference.metamerism.metamerism_index_from_XYZ`
81+
Define :func:`colour.difference.metamerism.XYZ_to_metamerism_index`
8282
definition unit tests methods.
8383
"""
8484

85-
def test_domain_range_scale_metamerism_index_from_XYZ(self) -> None:
85+
def test_domain_range_scale_XYZ_to_metamerism_index(self) -> None:
8686
"""
87-
Test :func:`colour.difference.metamerism.metamerism_index_from_XYZ`
87+
Test :func:`colour.difference.metamerism.XYZ_to_metamerism_index`
8888
definition domain and range scale support.
8989
"""
9090

9191
XYZ_1 = np.array([0.20654008, 0.12197225, 0.05136952])
9292
offset = np.array([0, 0, 0.01])
9393

94-
c = ("additive", "multiplicative")
94+
c = ("Additive", "Multiplicative")
9595
m = ("CIE 1976", "CIE 1994", "CIE 2000", "CMC", "DIN99")
9696
it = [
9797
(
9898
correction,
9999
method,
100-
metamerism_index_from_XYZ(
100+
XYZ_to_metamerism_index(
101101
XYZ_1 + offset,
102102
XYZ_1,
103103
XYZ_1,
@@ -115,7 +115,7 @@ def test_domain_range_scale_metamerism_index_from_XYZ(self) -> None:
115115
for scale, factor in d_r:
116116
with domain_range_scale(scale):
117117
np.testing.assert_allclose(
118-
metamerism_index_from_XYZ(
118+
XYZ_to_metamerism_index(
119119
(XYZ_1 + offset) * factor,
120120
XYZ_1 * factor,
121121
XYZ_1 * factor,

0 commit comments

Comments
 (0)