Coverage for temperature/tests/test_ohno2013.py: 100%

1"""Define the unit tests for the :mod:`colour.temperature.ohno2013` module."""

2

3 from __future__ import annotations

4

5 from itertools import product

6

7 import numpy as np

8

9 from colour.colorimetry import MSDS_CMFS

10 from colour.constants import TOLERANCE_ABSOLUTE_TESTS

11 from colour.temperature import (

12 CCT_to_uv_Ohno2013,

13 CCT_to_XYZ_Ohno2013,

14 XYZ_to_CCT_Ohno2013,

15 uv_to_CCT_Ohno2013,

16)

17 from colour.temperature.ohno2013 import planckian_table

18 from colour.utilities import ignore_numpy_errors

19

20 __author__ = "Colour Developers"

21 __copyright__ = "Copyright 2013 Colour Developers"

22 __license__ = "BSD-3-Clause - https://opensource.org/licenses/BSD-3-Clause"

23 __maintainer__ = "Colour Developers"

24 __email__ = "colour-developers@colour-science.org"

25 __status__ = "Production"

26

27 __all__ = [

28 "TestPlanckianTable",

29 "TestUv_to_CCT_Ohno2013",

30 "TestCCT_to_uv_Ohno2013",

31 "Test_XYZ_to_CCT_Ohno2013",

32 "Test_CCT_to_XYZ_Ohno2013",

33]

34

35

36 class TestPlanckianTable:

37 """

38 Define :func:`colour.temperature.ohno2013.planckian_table` definition

39 unit tests methods.

40 """

41

42 def test_planckian_table(self) -> None:

43 """Test :func:`colour.temperature.ohno2013.planckian_table` definition."""

44

45 np.testing.assert_allclose(

46 planckian_table(

47 MSDS_CMFS["CIE 1931 2 Degree Standard Observer"],

48 5000,

49 6000,

50 1.01,

51 ),

52 np.array(

53 [

54 [5.00000000e03, 2.11424442e-01, 3.23115810e-01],

55 [5.00100000e03, 2.11414166e-01, 3.23105716e-01],

56 [5.05101000e03, 2.10906941e-01, 3.22603850e-01],

57 [5.09965995e03, 2.10425840e-01, 3.22121155e-01],

58 [5.14875592e03, 2.09952257e-01, 3.21639518e-01],

59 [5.19830158e03, 2.09486095e-01, 3.21159015e-01],

60 [5.24830059e03, 2.09027261e-01, 3.20679719e-01],

61 [5.29875665e03, 2.08575658e-01, 3.20201701e-01],

62 [5.34967349e03, 2.08131192e-01, 3.19725033e-01],

63 [5.40105483e03, 2.07693769e-01, 3.19249784e-01],

64 [5.45290444e03, 2.07263296e-01, 3.18776019e-01],

65 [5.50522609e03, 2.06839680e-01, 3.18303806e-01],

66 [5.55802360e03, 2.06422828e-01, 3.17833209e-01],

67 [5.61130078e03, 2.06012650e-01, 3.17364290e-01],

68 [5.66506148e03, 2.05609054e-01, 3.16897111e-01],

69 [5.71930956e03, 2.05211949e-01, 3.16431730e-01],

70 [5.77404891e03, 2.04821246e-01, 3.15968207e-01],

71 [5.82928344e03, 2.04436856e-01, 3.15506598e-01],

72 [5.88501707e03, 2.04058690e-01, 3.15046958e-01],

73 [5.94125375e03, 2.03686660e-01, 3.14589340e-01],

74 [5.99799745e03, 2.03320679e-01, 3.14133796e-01],

75 [5.99900000e03, 2.03314296e-01, 3.14125803e-01],

76 [6.00000000e03, 2.03307932e-01, 3.14117832e-01],

77 ]

78 ),

79 atol=1e-6,

80 )

81

82

83 class TestUv_to_CCT_Ohno2013:

84 """

85 Define :func:`colour.temperature.ohno2013.uv_to_CCT_Ohno2013` definition

86 unit tests methods.

87 """

88

89 def test_uv_to_CCT_Ohno2013(self) -> None:

90 """

91 Test :func:`colour.temperature.ohno2013.uv_to_CCT_Ohno2013`

92 definition.

93 """

94

95 CCT = np.linspace(1_000, 100_000, 3_000)

96 D_uv = np.linspace(-0.01, 0.01, 10)

97

98 CCT, D_uv = np.meshgrid(CCT, D_uv)

99 table_r = np.transpose((np.ravel(CCT), np.ravel(D_uv)))

100 table_t = uv_to_CCT_Ohno2013(CCT_to_uv_Ohno2013(table_r))

101

102 np.testing.assert_allclose(table_t[1, :], table_r[1, :], atol=1)

103

104 np.testing.assert_allclose(

105 uv_to_CCT_Ohno2013(np.array([0.1978, 0.3122])),

106 np.array([6507.474788799616363, 0.003223346337596]),

107 atol=TOLERANCE_ABSOLUTE_TESTS,

108 )

109

110 np.testing.assert_allclose(

111 uv_to_CCT_Ohno2013(np.array([0.4328, 0.2883])),

112 np.array([1041.678320000468375, -0.067378053475797]),

113 atol=TOLERANCE_ABSOLUTE_TESTS,

114 )

115

116 np.testing.assert_allclose(

117 uv_to_CCT_Ohno2013(np.array([0.2927, 0.2722])),

118 np.array([2444.971818951082696, -0.084370641205118]),

119 atol=TOLERANCE_ABSOLUTE_TESTS,

120 )

121

122 def test_n_dimensional_uv_to_CCT_Ohno2013(self) -> None:

123 """

124 Test :func:`colour.temperature.ohno2013.uv_to_CCT_Ohno2013` definition

125 n-dimensional arrays support.

126 """

127

128 uv = np.array([0.1978, 0.3122])

129 CCT_D_uv = uv_to_CCT_Ohno2013(uv)

130

131 uv = np.tile(uv, (6, 1))

132 CCT_D_uv = np.tile(CCT_D_uv, (6, 1))

133 np.testing.assert_allclose(

134 uv_to_CCT_Ohno2013(uv), CCT_D_uv, atol=TOLERANCE_ABSOLUTE_TESTS

135 )

136

137 uv = np.reshape(uv, (2, 3, 2))

138 CCT_D_uv = np.reshape(CCT_D_uv, (2, 3, 2))

139 np.testing.assert_allclose(

140 uv_to_CCT_Ohno2013(uv), CCT_D_uv, atol=TOLERANCE_ABSOLUTE_TESTS

141 )

142

143 @ignore_numpy_errors

144 def test_nan_uv_to_CCT_Ohno2013(self) -> None:

145 """

146 Test :func:`colour.temperature.ohno2013.uv_to_CCT_Ohno2013` definition

147 nan support.

148 """

149

150 cases = [-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]

151 cases = np.array(list(set(product(cases, repeat=2))))

152 uv_to_CCT_Ohno2013(cases)

153

154

155 class TestCCT_to_uv_Ohno2013:

156 """

157 Define :func:`colour.temperature.ohno2013.CCT_to_uv_Ohno2013` definition

158 unit tests methods.

159 """

160

161 def test_CCT_to_uv_Ohno2013(self) -> None:

162 """

163 Test :func:`colour.temperature.ohno2013.CCT_to_uv_Ohno2013`

164 definition.

165 """

166

167 np.testing.assert_allclose(

168 CCT_to_uv_Ohno2013(np.array([6507.47380460, 0.00322335])),

169 np.array([0.19779997, 0.31219997]),

170 atol=TOLERANCE_ABSOLUTE_TESTS,

171 )

172

173 np.testing.assert_allclose(

174 CCT_to_uv_Ohno2013(np.array([1041.68315360, -0.06737802])),

175 np.array([0.43279885, 0.28830013]),

176 atol=TOLERANCE_ABSOLUTE_TESTS,

177 )

178

179 np.testing.assert_allclose(

180 CCT_to_uv_Ohno2013(np.array([2452.15316417, -0.08437064])),

181 np.array([0.29247364, 0.27215157]),

182 atol=TOLERANCE_ABSOLUTE_TESTS,

183 )

184

185 def test_n_dimensional_CCT_to_uv_Ohno2013(self) -> None:

186 """

187 Test :func:`colour.temperature.ohno2013.CCT_to_uv_Ohno2013` definition

188 n-dimensional arrays support.

189 """

190

191 CCT_D_uv = np.array([6507.47380460, 0.00322335])

192 uv = CCT_to_uv_Ohno2013(CCT_D_uv)

193

194 CCT_D_uv = np.tile(CCT_D_uv, (6, 1))

195 uv = np.tile(uv, (6, 1))

196 np.testing.assert_allclose(

197 CCT_to_uv_Ohno2013(CCT_D_uv), uv, atol=TOLERANCE_ABSOLUTE_TESTS

198 )

199

200 CCT_D_uv = np.reshape(CCT_D_uv, (2, 3, 2))

201 uv = np.reshape(uv, (2, 3, 2))

202 np.testing.assert_allclose(

203 CCT_to_uv_Ohno2013(CCT_D_uv), uv, atol=TOLERANCE_ABSOLUTE_TESTS

204 )

205

206 @ignore_numpy_errors

207 def test_nan_CCT_to_uv_Ohno2013(self) -> None:

208 """

209 Test :func:`colour.temperature.ohno2013.CCT_to_uv_Ohno2013` definition

210 nan support.

211 """

212

213 cases = [-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]

214 cases = np.array(list(set(product(cases, repeat=2))))

215 CCT_to_uv_Ohno2013(cases)

216

217

218 class Test_XYZ_to_CCT_Ohno2013:

219 """

220 Define :func:`colour.temperature.ohno2013.XYZ_to_CCT_Ohno2013` definition

221 unit tests methods.

222 """

223

224 def test_XYZ_to_CCT_Ohno2013(self) -> None:

225 """

226 Test :func:`colour.temperature.ohno2013.XYZ_to_CCT_Ohno2013` definition.

227 """

228

229 np.testing.assert_allclose(

230 XYZ_to_CCT_Ohno2013(np.array([95.04, 100.00, 108.88])),

231 np.array([6503.30711709, 0.00321729]),

232 atol=TOLERANCE_ABSOLUTE_TESTS,

233 )

234

235 def test_n_dimensional_XYZ_to_CCT_Ohno2013(self) -> None:

236 """

237 Test :func:`colour.temperature.ohno2013.XYZ_to_CCT_Ohno2013` definition

238 n-dimensional arrays support.

239 """

240

241 XYZ = np.array([95.04, 100.00, 108.88])

242 CCT_D_uv = XYZ_to_CCT_Ohno2013(XYZ)

243

244 XYZ = np.tile(XYZ, (6, 1))

245 CCT_D_uv = np.tile(CCT_D_uv, (6, 1))

246 np.testing.assert_allclose(

247 XYZ_to_CCT_Ohno2013(XYZ), CCT_D_uv, atol=TOLERANCE_ABSOLUTE_TESTS

248 )

249

250 XYZ = np.reshape(XYZ, (2, 3, 3))

251 CCT_D_uv = np.reshape(CCT_D_uv, (2, 3, 2))

252 np.testing.assert_allclose(

253 XYZ_to_CCT_Ohno2013(XYZ), CCT_D_uv, atol=TOLERANCE_ABSOLUTE_TESTS

254 )

255

256 @ignore_numpy_errors

257 def test_nan_XYZ_to_CCT_Ohno2013(self) -> None:

258 """

259 Test :func:`colour.temperature.ohno2013.XYZ_to_CCT_Ohno2013` definition

260 nan support.

261 """

262

263 cases = [-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]

264 cases = np.array(list(set(product(cases, repeat=3))))

265 XYZ_to_CCT_Ohno2013(cases)

266

267

268 class Test_CCT_to_XYZ_Ohno2013:

269 """

270 Define :func:`colour.temperature.ohno2013.CCT_to_XYZ_Ohno2013` definition

271 unit tests methods.

272 """

273

274 def test_CCT_to_XYZ_Ohno2013(self) -> None:

275 """

276 Test :func:`colour.temperature.ohno2013.CCT_to_XYZ_Ohno2013` definition.

277 """

278

279 np.testing.assert_allclose(

280 CCT_to_XYZ_Ohno2013(np.array([6503.30711709, 0.00321729])),

281 np.array([95.04, 100.00, 108.88]) / 100,

282 atol=1e-6,

283 )

284

285 def test_n_dimensional_CCT_to_XYZ_Ohno2013(self) -> None:

286 """

287 Test :func:`colour.temperature.ohno2013.CCT_to_XYZ_Ohno2013` definition

288 n-dimensional arrays support.

289 """

290

291 CCT_D_uv = np.array([6503.30711709, 0.00321729])

292 XYZ = CCT_to_XYZ_Ohno2013(CCT_D_uv)

293

294 CCT_D_uv = np.tile(CCT_D_uv, (6, 1))

295 XYZ = np.tile(XYZ, (6, 1))

296 np.testing.assert_allclose(

297 CCT_to_XYZ_Ohno2013(CCT_D_uv), XYZ, atol=TOLERANCE_ABSOLUTE_TESTS

298 )

299

300 CCT_D_uv = np.reshape(CCT_D_uv, (2, 3, 2))

301 XYZ = np.reshape(XYZ, (2, 3, 3))

302 np.testing.assert_allclose(

303 CCT_to_XYZ_Ohno2013(CCT_D_uv), XYZ, atol=TOLERANCE_ABSOLUTE_TESTS

304 )

305

306 @ignore_numpy_errors

307 def test_nan_CCT_to_uv_Ohno2013(self) -> None:

308 """

309 Test :func:`colour.temperature.ohno2013.CCT_to_uv_Ohno2013` definition

310 nan support.

311 """

312

313 cases = [-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]

314 cases = np.array(list(set(product(cases, repeat=2))))

315 CCT_to_uv_Ohno2013(cases)