Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR: Use shape if passed, to also reshape the colour.continuous.AbstractContinuousSignal sub-classes in colour.colorimetry.sd_to_XYZ_integration definition. #1250

Merged
merged 2 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions colour/colorimetry/tests/test_tristimulus_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,17 @@ def test_sd_to_XYZ_integration(self):
atol=TOLERANCE_ABSOLUTE_TESTS,
)

np.testing.assert_allclose(
sd_to_XYZ_integration(
SD_SAMPLE,
cmfs,
SDS_ILLUMINANTS["FL2"],
shape=SpectralShape(400, 700, 20),
),
np.array([11.98232967, 10.13543929, 3.66442524]),
atol=TOLERANCE_ABSOLUTE_TESTS,
)

def test_domain_range_scale_sd_to_XYZ_integration(self):
"""
Test :func:`colour.colorimetry.tristimulus_values.\
Expand Down Expand Up @@ -1368,6 +1379,18 @@ def test_sd_to_XYZ(self):
atol=TOLERANCE_ABSOLUTE_TESTS,
)

np.testing.assert_allclose(
sd_to_XYZ(
self._sd,
self._cmfs,
self._A,
method="Integration",
shape=SpectralShape(400, 700, 20),
),
np.array([14.52005467, 10.88000966, 2.03888717]),
atol=TOLERANCE_ABSOLUTE_TESTS,
)


class TestMsds_to_XYZ_integration(unittest.TestCase):
"""
Expand Down
29 changes: 17 additions & 12 deletions colour/colorimetry/tristimulus_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,8 +570,8 @@ def sd_to_XYZ_integration(
be the spectral concentration of the radiometric quantity corresponding
to the photometric quantity required.
shape
Spectral shape of the spectral distribution, ``cmfs`` and
``illuminant`` will be aligned to it if ``sd`` is an `ArrayLike`.
Spectral shape that ``sd``, ``cmfs`` and ``illuminant`` will be
aligned to it if passed.

Returns
-------
Expand Down Expand Up @@ -647,9 +647,9 @@ def sd_to_XYZ_integration(

# NOTE: The "illuminant" argument is reshaped by the
# `handle_spectral_arguments` definition, but, in this case, it is not
# desirable as we want to reshape it according to the final "shape" which
# is only available after the subsequent if/else block thus we are careful
# not unpacking over it.
# desirable as we want to reshape it according to the final "shape" which,
# if not directly passed, is only available after the subsequent if/else
# block thus we are carefully avoiding to unpack over it.
if illuminant is None:
cmfs, illuminant = handle_spectral_arguments(
cmfs, illuminant, illuminant_default="E"
Expand All @@ -660,6 +660,10 @@ def sd_to_XYZ_integration(
)

if isinstance(sd, (SpectralDistribution, MultiSpectralDistributions)):
if shape is not None:
cmfs = reshape_msds(cmfs, shape, copy=False)
illuminant = reshape_sd(illuminant, shape, copy=False)

shape = cmfs.shape

if sd.shape != shape:
Expand Down Expand Up @@ -1146,8 +1150,9 @@ def sd_to_XYZ(
tristimulus values will use a dedicated interpolation method instead
of a table of tristimulus weighting factors.
shape
Spectral shape of the spectral distribution, ``cmfs`` and
``illuminant`` will be aligned to it if ``sd`` is an `ArrayLike`.
{:func:`colour.colorimetry.sd_to_XYZ_integration`},
Spectral shape that ``sd``, ``cmfs`` and ``illuminant`` will be
aligned to it if passed.
use_practice_range
{:func:`colour.colorimetry.sd_to_XYZ_ASTME308`},
Practise *ASTM E308-15* working wavelengths range is [360, 780],
Expand Down Expand Up @@ -1244,7 +1249,7 @@ def sd_to_XYZ(
(
sd
if isinstance(sd, (SpectralDistribution, MultiSpectralDistributions))
else int_digest(sd.tobytes()) # pyright: ignore
else int_digest(np.asarray(sd).tobytes()) # pyright: ignore
), # pyright: ignore
cmfs,
illuminant,
Expand Down Expand Up @@ -1309,8 +1314,8 @@ def msds_to_XYZ_integration(
be the spectral concentration of the radiometric quantity corresponding
to the photometric quantity required.
shape
Spectral shape of the multi-spectral distributions, ``cmfs`` and
``illuminant`` will be aligned to it if ``msds`` is an `ArrayLike`.
Spectral shape that ``sd``, ``cmfs`` and ``illuminant`` will be
aligned to it if passed.

Returns
-------
Expand Down Expand Up @@ -1812,8 +1817,8 @@ def msds_to_XYZ(
of a table of tristimulus weighting factors.
shape
{:func:`colour.colorimetry.msds_to_XYZ_integration`},
Spectral shape of the multi-spectral distributions array :math:`msds`,
``cmfs`` and ``illuminant`` will be aligned to it.
Spectral shape that ``sd``, ``cmfs`` and ``illuminant`` will be
aligned to it if passed.
use_practice_range
{:func:`colour.colorimetry.msds_to_XYZ_ASTME308`},
Practise *ASTM E308-15* working wavelengths range is [360, 780],
Expand Down
124 changes: 62 additions & 62 deletions colour/recovery/jiang2013.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,37 +205,37 @@ def RGB_to_sd_camera_sensitivity_Jiang2013(
... R_w,
... SPECTRAL_SHAPE_BASIS_FUNCTIONS_DYER2017,
... ) # doctest: +ELLIPSIS
SpectralDistribution([[ 4.00000000e+02, 7.3976716...e-04],
[ 4.10000000e+02, -8.7040243...e-04],
[ 4.20000000e+02, 4.6893657...e-03],
[ 4.30000000e+02, 7.7522012...e-03],
[ 4.40000000e+02, 6.9238417...e-03],
[ 4.50000000e+02, 5.3089422...e-03],
[ 4.60000000e+02, 4.4780109...e-03],
[ 4.70000000e+02, 4.6386816...e-03],
[ 4.80000000e+02, 5.1897663...e-03],
[ 4.90000000e+02, 4.3906620...e-03],
[ 5.00000000e+02, 4.2189259...e-03],
[ 5.10000000e+02, 5.4270976...e-03],
[ 5.20000000e+02, 9.6722601...e-03],
[ 5.30000000e+02, 1.4272520...e-02],
[ 5.40000000e+02, 7.9609053...e-03],
[ 5.50000000e+02, 4.5917460...e-03],
[ 5.60000000e+02, 5.2723695...e-03],
[ 5.70000000e+02, 1.0479224...e-02],
[ 5.80000000e+02, 5.3101298...e-02],
[ 5.90000000e+02, 9.8185490...e-02],
[ 6.00000000e+02, 9.9775094...e-02],
[ 6.10000000e+02, 8.3935824...e-02],
[ 6.20000000e+02, 6.9216733...e-02],
[ 6.30000000e+02, 5.6902763...e-02],
[ 6.40000000e+02, 4.2810635...e-02],
[ 6.50000000e+02, 3.0064003...e-02],
[ 6.60000000e+02, 2.3093789...e-02],
[ 6.70000000e+02, 1.3756855...e-02],
[ 6.80000000e+02, 4.1785101...e-03],
[ 6.90000000e+02, -3.8014848...e-04],
[ 7.00000000e+02, -5.7544253...e-04]],
SpectralDistribution([[ 4.00000000e+02, 7.2066502...e-04],
[ 4.10000000e+02, -8.9698693...e-04],
[ 4.20000000e+02, 4.6871961...e-03],
[ 4.30000000e+02, 7.7694971...e-03],
[ 4.40000000e+02, 6.9335511...e-03],
[ 4.50000000e+02, 5.3134947...e-03],
[ 4.60000000e+02, 4.4819958...e-03],
[ 4.70000000e+02, 4.6393791...e-03],
[ 4.80000000e+02, 5.1866668...e-03],
[ 4.90000000e+02, 4.3828317...e-03],
[ 5.00000000e+02, 4.2001231...e-03],
[ 5.10000000e+02, 5.4065544...e-03],
[ 5.20000000e+02, 9.6445141...e-03],
[ 5.30000000e+02, 1.4277112...e-02],
[ 5.40000000e+02, 7.9950718...e-03],
[ 5.50000000e+02, 4.6429813...e-03],
[ 5.60000000e+02, 5.3423840...e-03],
[ 5.70000000e+02, 1.0519383...e-02],
[ 5.80000000e+02, 5.2889443...e-02],
[ 5.90000000e+02, 9.7851167...e-02],
[ 6.00000000e+02, 9.9600382...e-02],
[ 6.10000000e+02, 8.3840892...e-02],
[ 6.20000000e+02, 6.9180858...e-02],
[ 6.30000000e+02, 5.6967854...e-02],
[ 6.40000000e+02, 4.2930308...e-02],
[ 6.50000000e+02, 3.0241267...e-02],
[ 6.60000000e+02, 2.3230047...e-02],
[ 6.70000000e+02, 1.3721943...e-02],
[ 6.80000000e+02, 4.0944885...e-03],
[ 6.90000000e+02, -4.4223475...e-04],
[ 7.00000000e+02, -6.1427769...e-04]],
SpragueInterpolator,
{},
Extrapolator,
Expand Down Expand Up @@ -335,37 +335,37 @@ def RGB_to_msds_camera_sensitivities_Jiang2013(
... BASIS_FUNCTIONS_DYER2017,
... SPECTRAL_SHAPE_BASIS_FUNCTIONS_DYER2017,
... ).values # doctest: +ELLIPSIS
array([[ 7.2281577...e-03, 9.2250648...e-03, -9.8836897...e-03],
[ -8.5045760...e-03, 1.1277748...e-02, 3.8624865...e-03],
[ 4.5819113...e-02, 7.1552094...e-02, 4.0406829...e-01],
[ 7.5745635...e-02, 1.1530030...e-01, 7.1177452...e-01],
[ 6.7651854...e-02, 1.5311354...e-01, 8.5161378...e-01],
[ 5.1872905...e-02, 1.8828774...e-01, 9.3658053...e-01],
[ 4.3753995...e-02, 2.6093723...e-01, 9.7049828...e-01],
[ 4.5323885...e-02, 3.7531459...e-01, 9.5883525...e-01],
[ 5.0708454...e-02, 4.4750685...e-01, 8.8451412...e-01],
[ 4.2900523...e-02, 4.5047800...e-01, 7.5069924...e-01],
[ 4.1222513...e-02, 6.1672868...e-01, 5.5327277...e-01],
[ 5.3027385...e-02, 7.8015416...e-01, 3.8368507...e-01],
[ 9.4506252...e-02, 9.1751657...e-01, 2.4143664...e-01],
[ 1.3945472...e-01, 1.0000000...e+00, 1.5616071...e-01],
[ 7.7784852...e-02, 9.2719372...e-01, 1.0462050...e-01],
[ 4.4865285...e-02, 8.5627976...e-01, 6.5035086...e-02],
[ 5.1515558...e-02, 7.5193757...e-01, 3.3979292...e-02],
[ 1.0239098...e-01, 6.2562412...e-01, 2.0583993...e-02],
[ 5.1884509...e-01, 4.9264953...e-01, 1.4571020...e-02],
[ 9.5935619...e-01, 3.4322427...e-01, 1.0656116...e-02],
[ 9.7488799...e-01, 2.0857245...e-01, 6.8892462...e-03],
[ 8.2012477...e-01, 1.1178699...e-01, 4.3808407...e-03],
[ 6.7630666...e-01, 6.5977834...e-02, 4.0420907...e-03],
[ 5.5598866...e-01, 4.4719007...e-02, 4.2502316...e-03],
[ 4.1829651...e-01, 3.3471790...e-02, 4.6139542...e-03],
[ 2.9375101...e-01, 2.4044889...e-02, 4.7376860...e-03],
[ 2.2564606...e-01, 1.8870707...e-02, 4.6336440...e-03],
[ 1.3441624...e-01, 1.0702974...e-02, 3.4919622...e-03],
[ 4.0827617...e-02, 5.5529047...e-03, 1.3990786...e-03],
[ -3.7143757...e-03, 2.5093564...e-03, 3.9765262...e-04],
[ -5.6225656...e-03, 1.5643397...e-03, 5.8472693...e-04]])
array([[ 7.0437846...e-03, 9.2126044...e-03, -7.6408087...e-03],
[ -8.7671560...e-03, 1.1272669...e-02, 6.3743419...e-03],
[ 4.5812685...e-02, 7.1800041...e-02, 4.0000169...e-01],
[ 7.5939115...e-02, 1.1562093...e-01, 7.1152155...e-01],
[ 6.7768573...e-02, 1.5340644...e-01, 8.5266831...e-01],
[ 5.1934131...e-02, 1.8857547...e-01, 9.3895784...e-01],
[ 4.3807056...e-02, 2.6108660...e-01, 9.7213072...e-01],
[ 4.5345321...e-02, 3.7544039...e-01, 9.6145068...e-01],
[ 5.0694514...e-02, 4.4765815...e-01, 8.8648114...e-01],
[ 4.2837825...e-02, 4.5071344...e-01, 7.5177077...e-01],
[ 4.1052030...e-02, 6.1657728...e-01, 5.5273073...e-01],
[ 5.2843697...e-02, 7.8019954...e-01, 3.8226917...e-01],
[ 9.4265543...e-02, 9.1767425...e-01, 2.4035461...e-01],
[ 1.3954459...e-01, 1.0000000...e+00, 1.5537481...e-01],
[ 7.8143883...e-02, 9.2772027...e-01, 1.0440935...e-01],
[ 4.5380529...e-02, 8.5670156...e-01, 6.5122285...e-02],
[ 5.2216496...e-02, 7.5232292...e-01, 3.4295447...e-02],
[ 1.0281652...e-01, 6.2580973...e-01, 2.0949510...e-02],
[ 5.1694176...e-01, 4.9274616...e-01, 1.4852461...e-02],
[ 9.5639793...e-01, 3.4336481...e-01, 1.0898318...e-02],
[ 9.7349477...e-01, 2.0858770...e-01, 7.0049439...e-03],
[ 8.1946141...e-01, 1.1178483...e-01, 4.4718000...e-03],
[ 6.7617415...e-01, 6.5907196...e-02, 4.1013538...e-03],
[ 5.5680417...e-01, 4.4626835...e-02, 4.1852898...e-03],
[ 4.1960111...e-01, 3.3367103...e-02, 4.4916588...e-03],
[ 2.9557834...e-01, 2.3948776...e-02, 4.4593273...e-03],
[ 2.2705062...e-01, 1.8778777...e-02, 4.3169731...e-03],
[ 1.3411835...e-01, 1.0695498...e-02, 3.4119265...e-03],
[ 4.0019556...e-02, 5.5551238...e-03, 1.3679492...e-03],
[ -4.3224053...e-03, 2.4973119...e-03, 3.8030327...e-04],
[ -6.0039541...e-03, 1.5467822...e-03, 5.4039435...e-04]])
"""

R, G, B = tsplit(np.reshape(RGB, [-1, 3]))
Expand Down
Loading