Skip to content

Commit

Permalink
Merge branch 'feature/v0.4.3' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
KelSolaar committed May 3, 2023
2 parents 8e0c9c1 + 8fbad05 commit 363f2eb
Show file tree
Hide file tree
Showing 20 changed files with 550 additions and 141 deletions.
6 changes: 3 additions & 3 deletions BIBLIOGRAPHY.bib
Original file line number Diff line number Diff line change
Expand Up @@ -2209,9 +2209,9 @@ @article{Morovic2000
file = {/Users/kelsolaar/Zotero/storage/VD5SFTFE/Morovič, Luo - 2000 - Calculating medium and image gamut boundaries for gamut mapping.pdf}
}

@article{MunishRagoo2021,
@article{Ragoo2021,
title = {Optimising a {{Euclidean Colour Space Transform}} for {{Colour Order}} and {{Perceptual Uniformity}}},
author = {Munish Ragoo, Luvin and Farup, Ivar},
author = {Ragoo, Luvin Munish and Farup, Ivar},
year = {2021},
month = nov,
journal = {Color and Imaging Conference},
Expand All @@ -2221,7 +2221,7 @@ @article{MunishRagoo2021
issn = {2166-9635},
doi = {10.2352/issn.2169-2629.2021.29.282},
urldate = {2022-05-22},
file = {/Users/kelsolaar/Zotero/storage/5AR4C5XH/Munish Ragoo and Farup - 2021 - Optimising a Euclidean Colour Space Transform for .pdf}
file = {/Users/kelsolaar/Zotero/storage/5AR4C5XH/Ragoo and Farup - 2021 - Optimising a Euclidean Colour Space Transform for .pdf}
}

@misc{MunsellColorScienceb,
Expand Down
6 changes: 3 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -851,12 +851,12 @@ IPT Colourspace
>>> colour.XYZ_to_IPT([0.20654008, 0.12197225, 0.05136952])
array([ 0.38426191, 0.38487306, 0.18886838])
Munish Ragoo and Farup (2021) Optimised IPT Colourspace
*******************************************************
Ragoo and Farup (2021) Optimised IPT Colourspace
************************************************
.. code-block:: python
>>> colour.XYZ_to_IPT_Munish2021([0.20654008, 0.12197225, 0.05136952])
>>> colour.XYZ_to_IPT_Ragoo2021([0.20654008, 0.12197225, 0.05136952])
array([ 0.42248243, 0.2910514 , 0.20410663])
DIN99 Colourspace and DIN99b, DIN99c, DIN99d Refined Formulas
Expand Down
22 changes: 18 additions & 4 deletions colour/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@
IgPgTg_to_XYZ,
IPT_hue_angle,
IPT_to_XYZ,
IPT_Munish2021_to_XYZ,
IPT_Ragoo2021_to_XYZ,
JMh_CAM16_to_CAM16LCD,
JMh_CAM16_to_CAM16SCD,
JMh_CAM16_to_CAM16UCS,
Expand Down Expand Up @@ -323,7 +323,7 @@
XYZ_to_ICtCp,
XYZ_to_IgPgTg,
XYZ_to_IPT,
XYZ_to_IPT_Munish2021,
XYZ_to_IPT_Ragoo2021,
XYZ_to_Jzazbz,
XYZ_to_K_ab_HunterLab1966,
XYZ_to_Lab,
Expand Down Expand Up @@ -684,7 +684,7 @@ def __getattr__(self, attribute) -> Any:
"IgPgTg_to_XYZ",
"IPT_hue_angle",
"IPT_to_XYZ",
"IPT_Munish2021_to_XYZ",
"IPT_Ragoo2021_to_XYZ",
"JMh_CAM16_to_CAM16LCD",
"JMh_CAM16_to_CAM16SCD",
"JMh_CAM16_to_CAM16UCS",
Expand Down Expand Up @@ -747,7 +747,7 @@ def __getattr__(self, attribute) -> Any:
"XYZ_to_ICtCp",
"XYZ_to_IgPgTg",
"XYZ_to_IPT",
"XYZ_to_IPT_Munish2021",
"XYZ_to_IPT_Ragoo2021",
"XYZ_to_Jzazbz",
"XYZ_to_K_ab_HunterLab1966",
"XYZ_to_Lab",
Expand Down Expand Up @@ -943,6 +943,20 @@ def __getattr__(self, attribute) -> Any:
],
]
}

# v0.4.3
API_CHANGES["ObjectRenamed"].extend(
[
[
"colour.XYZ_to_IPT_Munish2021",
"colour.XYZ_to_IPT_Ragoo2021",
],
[
"colour.IPT_Munish2021_to_XYZ",
"colour.IPT_Ragoo2021_to_XYZ",
],
]
)
"""Defines the *colour.models* sub-package API changes."""

if not is_documentation_building():
Expand Down
36 changes: 27 additions & 9 deletions colour/colorimetry/spectrum.py
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,21 @@ def __init__(
self._display_name: str = self.name
self.display_name = kwargs.get("display_name", self._display_name)

self._shape: SpectralShape | None = None

def _on_domain_changed(
self, name: str, value: NDArrayFloat
) -> NDArrayFloat:
"""Invalidate *self._shape* when *self._domain* is changed."""
if name == "_domain":
self._shape = None

return value

self.register_callback(
"_domain", "on_domain_changed", _on_domain_changed
)

@property
def display_name(self) -> str:
"""
Expand Down Expand Up @@ -836,17 +851,20 @@ def shape(self) -> SpectralShape:
SpectralShape(500.0, 600.0, 10.0)
"""

wavelengths = self.wavelengths
wavelengths_interval = interval(wavelengths)
if wavelengths_interval.size != 1:
runtime_warning(
f'"{self.name}" spectral distribution is not uniform, using '
f"minimum interval!"
if self._shape is None:
wavelengths = self.wavelengths
wavelengths_interval = interval(wavelengths)
if wavelengths_interval.size != 1:
runtime_warning(
f'"{self.name}" spectral distribution is not uniform, '
"using minimum interval!"
)

self._shape = SpectralShape(
wavelengths[0], wavelengths[-1], min(wavelengths_interval)
)

return SpectralShape(
wavelengths[0], wavelengths[-1], min(wavelengths_interval)
)
return self._shape

def interpolate(
self,
Expand Down
90 changes: 63 additions & 27 deletions colour/colorimetry/tests/test_spectrum.py
Original file line number Diff line number Diff line change
Expand Up @@ -1515,30 +1515,35 @@ def test_interpolate(self):
SpectralDistribution.interpolate` method.
"""

shape = SpectralShape(self._sd.shape.start, self._sd.shape.end, 1)
sd = reshape_sd(self._sd, shape, "Interpolate")
np.testing.assert_array_almost_equal(
reshape_sd(
self._sd,
SpectralShape(self._sd.shape.start, self._sd.shape.end, 1),
"Interpolate",
).values,
sd.values,
DATA_SAMPLE_INTERPOLATED,
decimal=7,
)
self.assertEqual(sd.shape, shape)

shape = SpectralShape(
self._non_uniform_sd.shape.start,
self._non_uniform_sd.shape.end,
1,
)
sd = reshape_sd(self._non_uniform_sd, shape, "Interpolate")
np.testing.assert_allclose(
reshape_sd(
self._non_uniform_sd,
SpectralShape(
self._non_uniform_sd.shape.start,
self._non_uniform_sd.shape.end,
1,
),
"Interpolate",
).values,
sd.values,
DATA_SAMPLE_INTERPOLATED_NON_UNIFORM,
rtol=0.0000001,
atol=0.0000001,
)
self.assertEqual(
sd.shape,
SpectralShape(
np.ceil(self._non_uniform_sd.shape.start),
np.floor(self._non_uniform_sd.shape.end),
1,
),
)

def test_extrapolate(self):
"""
Expand All @@ -1556,8 +1561,9 @@ def test_extrapolate(self):
sd = SpectralDistribution(
np.linspace(0, 1, 10), np.linspace(25, 35, 10)
)
shape = SpectralShape(10, 50, 10)
sd.extrapolate(
SpectralShape(10, 50, 10),
shape,
extrapolator_kwargs={
"method": "Linear",
"left": None,
Expand Down Expand Up @@ -1602,6 +1608,17 @@ def test_normalise(self):
self._sd.copy().normalise(100).values, DATA_SAMPLE_NORMALISED
)

def test_callback_on_domain_changed(self):
"""
Test :class:`colour.colorimetry.spectrum.\
SpectralDistribution` *on_domain_changed* callback.
"""

sd = self._sd.copy()
self.assertEqual(sd.shape, SpectralShape(340, 820, 20))
sd[840] = 0
self.assertEqual(sd.shape, SpectralShape(340, 840, 20))


class TestMultiSpectralDistributions(unittest.TestCase):
"""
Expand Down Expand Up @@ -1760,26 +1777,25 @@ def test_interpolate(self):
"""

# pylint: disable=E1102
msds = reshape_msds(
self._sample_msds,
SpectralShape(
self._sample_msds.shape.start, self._sample_msds.shape.end, 1
),
"Interpolate",
shape = SpectralShape(
self._sample_msds.shape.start, self._sample_msds.shape.end, 1
)
msds = reshape_msds(self._sample_msds, shape, "Interpolate")
for signal in msds.signals.values():
np.testing.assert_array_almost_equal(
signal.values, DATA_SAMPLE_INTERPOLATED, decimal=7
)
self.assertEqual(msds.shape, shape)

# pylint: disable=E1102
shape = SpectralShape(
self._non_uniform_sample_msds.shape.start,
self._non_uniform_sample_msds.shape.end,
1,
)
msds = reshape_msds(
self._non_uniform_sample_msds,
SpectralShape(
self._non_uniform_sample_msds.shape.start,
self._non_uniform_sample_msds.shape.end,
1,
),
shape,
"Interpolate",
)
for signal in msds.signals.values():
Expand All @@ -1789,6 +1805,14 @@ def test_interpolate(self):
rtol=0.0000001,
atol=0.0000001,
)
self.assertEqual(
msds.shape,
SpectralShape(
np.ceil(self._non_uniform_sample_msds.shape.start),
np.floor(self._non_uniform_sample_msds.shape.end),
1,
),
)

def test_extrapolate(self):
"""
Expand Down Expand Up @@ -1853,7 +1877,7 @@ def test_trim(self):

def test_normalise(self):
"""
Test :func:`colour.colorimetry.spectrum.
Test :func:`colour.colorimetry.spectrum.
MultiSpectralDistributions.normalise` method.
"""

Expand All @@ -1875,6 +1899,18 @@ def test_to_sds(self):
self.assertEqual(sd.name, self._labels[i])
self.assertEqual(sd.display_name, self._display_labels[i])

def test_callback_on_domain_changed(self):
"""
Test underlying :class:`colour.colorimetry.spectrum.\
SpectralDistribution` *on_domain_changed* callback when used with
:class:`colour.colorimetry.spectrum.MultiSpectralDistributions` class.
"""

msds = self._msds.copy()
self.assertEqual(msds.shape, SpectralShape(380, 780, 5))
msds[785] = 0
self.assertEqual(msds.shape, SpectralShape(380, 785, 5))


class TestReshapeSd(unittest.TestCase):
"""
Expand Down
3 changes: 2 additions & 1 deletion colour/continuous/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
Type,
)
from colour.utilities import (
MixinCallback,
as_float,
attest,
closest,
Expand All @@ -49,7 +50,7 @@
]


class AbstractContinuousFunction(ABC):
class AbstractContinuousFunction(ABC, MixinCallback):
"""
Define the base class for abstract continuous function.
Expand Down
6 changes: 2 additions & 4 deletions colour/continuous/signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -948,8 +948,7 @@ def _fill_domain_nan(
variable.
"""

self._domain = fill_nan(self._domain, method, default)
self._function = None # Invalidate the underlying continuous function.
self.domain = fill_nan(self.domain, method, default)

def _fill_range_nan(
self,
Expand All @@ -974,8 +973,7 @@ def _fill_range_nan(
variable.
"""

self._range = fill_nan(self._range, method, default)
self._function = None # Invalidate the underlying continuous function.
self.range = fill_nan(self.range, method, default)

def arithmetical_operation(
self,
Expand Down
8 changes: 4 additions & 4 deletions colour/examples/models/examples_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,20 +332,20 @@
print("\n")

message_box(
f'Converting to "Munish Ragoo and Farup (2021)" "Optimised IPT" '
f'Converting to "Ragoo and Farup (2021)" "Optimised IPT" '
f'colourspace from given "CIE XYZ" tristimulus values:\n\n\t{XYZ}'
)
print(colour.XYZ_to_IPT_Munish2021(XYZ))
print(colour.XYZ_to_IPT_Ragoo2021(XYZ))

print("\n")

IPT = np.array([0.42248243, 4.05710276, 0.20410663])
message_box(
f'Converting to "CIE XYZ" tristimulus values from given'
f'"Munish Ragoo and Farup (2021)" "Optimised IPT" colourspace '
f'"Ragoo and Farup (2021)" "Optimised IPT" colourspace '
f"values:\n\n\t{IPT}"
)
print(colour.IPT_Munish2021_to_XYZ(IPT))
print(colour.IPT_Ragoo2021_to_XYZ(IPT))

print("\n")

Expand Down
8 changes: 4 additions & 4 deletions colour/graph/conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
IHLS_to_RGB,
IgPgTg_to_XYZ,
IPT_to_XYZ,
IPT_Munish2021_to_XYZ,
IPT_Ragoo2021_to_XYZ,
JMh_CAM16_to_CAM16LCD,
JMh_CAM16_to_CAM16SCD,
JMh_CAM16_to_CAM16UCS,
Expand Down Expand Up @@ -115,7 +115,7 @@
XYZ_to_ICtCp,
XYZ_to_IgPgTg,
XYZ_to_IPT,
XYZ_to_IPT_Munish2021,
XYZ_to_IPT_Ragoo2021,
XYZ_to_Jzazbz,
XYZ_to_Lab,
XYZ_to_Luv,
Expand Down Expand Up @@ -741,8 +741,8 @@ def mired_to_CCT_D_uv(mired: ArrayLike) -> NDArrayFloat:
("IgPgTg", "CIE XYZ", IgPgTg_to_XYZ),
("CIE XYZ", "IPT", XYZ_to_IPT),
("IPT", "CIE XYZ", IPT_to_XYZ),
("CIE XYZ", "IPT Munish 2021", XYZ_to_IPT_Munish2021),
("IPT Munish 2021", "CIE XYZ", IPT_Munish2021_to_XYZ),
("CIE XYZ", "IPT Ragoo 2021", XYZ_to_IPT_Ragoo2021),
("IPT Ragoo 2021", "CIE XYZ", IPT_Ragoo2021_to_XYZ),
("CIE XYZ", "Jzazbz", XYZ_to_Jzazbz),
("Jzazbz", "CIE XYZ", Jzazbz_to_XYZ),
("CIE XYZ", "hdr-IPT", XYZ_to_hdr_IPT),
Expand Down
Loading

0 comments on commit 363f2eb

Please sign in to comment.