Coverage for appearance/tests/test_hke.py: 100%

1"""Define the unit tests for the :mod:`colour.appearance.hke` module."""

2

3 from __future__ import annotations

4

5 from itertools import product

6

7 import numpy as np

8

9 from colour.appearance.hke import (

10 HelmholtzKohlrausch_effect_luminous_Nayatani1997,

11 HelmholtzKohlrausch_effect_object_Nayatani1997,

12 coefficient_K_Br_Nayatani1997,

13 coefficient_q_Nayatani1997,

14)

15 from colour.constants import TOLERANCE_ABSOLUTE_TESTS

16 from colour.utilities import ignore_numpy_errors

17

18 __author__ = "Ilia Sibiryakov"

19 __copyright__ = "Copyright 2013 Colour Developers"

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

21 __maintainer__ = "Colour Developers"

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

23 __status__ = "Production"

24

25 __all__ = [

26 "TestHelmholtzKohlrauschEffectObjectNayatani1997",

27 "TestHelmholtzKohlrauschEffectLuminousNayatani1997",

28 "TestCoefficient_K_Br_Nayatani1997",

29 "TestCoefficient_q_Nayatani1997",

30]

31

32

33 class TestHelmholtzKohlrauschEffectObjectNayatani1997:

34 """

35 Define :func:`colour.colour.appearance.hke.\

36 HelmholtzKohlrausch_effect_object_Nayatani1997` definition unit tests methods.

37 """

38

39 def test_HelmholtzKohlrausch_effect_object_Nayatani1997(self) -> None:

40 """

41 Test :func:`colour.appearance.hke.\

42 HelmholtzKohlrausch_effect_object_Nayatani1997` definition.

43 """

44

45 np.testing.assert_allclose(

46 HelmholtzKohlrausch_effect_object_Nayatani1997(

47 np.array([0.40351010, 0.53933673]),

48 np.array([0.19783001, 0.46831999]),

49 63.66,

50 method="VCC",

51 ),

52 1.344152435497761,

53 atol=TOLERANCE_ABSOLUTE_TESTS,

54 )

55

56 np.testing.assert_allclose(

57 HelmholtzKohlrausch_effect_object_Nayatani1997(

58 np.array([0.40351010, 0.53933673]),

59 np.array([0.19783001, 0.46831999]),

60 63.66,

61 method="VAC",

62 ),

63 1.261777232837009,

64 atol=TOLERANCE_ABSOLUTE_TESTS,

65 )

66

67 def test_n_dimensional_HelmholtzKohlrausch_effect_object_Nayatani1997(

68 self,

69 ) -> None:

70 """

71 Test :func:`colour.appearance.hke.\

72 HelmholtzKohlrausch_effect_object_Nayatani1997` definition n_dimensional

73 arrays support.

74 """

75

76 uv_d65 = np.array([0.19783001, 0.46831999])

77 uv = np.array([0.40351010, 0.53933673])

78 L_a = 63.66

79

80 result_vcc = HelmholtzKohlrausch_effect_object_Nayatani1997(

81 uv, uv_d65, L_a, method="VCC"

82 )

83 result_vac = HelmholtzKohlrausch_effect_object_Nayatani1997(

84 uv, uv_d65, L_a, method="VAC"

85 )

86

87 uv_d65 = np.tile(uv_d65, (6, 1))

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

89 result_vcc = np.tile(result_vcc, 6)

90 result_vac = np.tile(result_vac, 6)

91

92 np.testing.assert_allclose(

93 HelmholtzKohlrausch_effect_object_Nayatani1997(

94 uv, uv_d65, L_a, method="VCC"

95 ),

96 result_vcc,

97 atol=TOLERANCE_ABSOLUTE_TESTS,

98 )

99

100 np.testing.assert_allclose(

101 HelmholtzKohlrausch_effect_object_Nayatani1997(

102 uv, uv_d65, L_a, method="VAC"

103 ),

104 result_vac,

105 atol=TOLERANCE_ABSOLUTE_TESTS,

106 )

107

108 uv_d65 = np.reshape(uv_d65, (2, 3, 2))

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

110 result_vcc = np.reshape(result_vcc, (2, 3))

111 result_vac = np.reshape(result_vac, (2, 3))

112

113 np.testing.assert_allclose(

114 HelmholtzKohlrausch_effect_object_Nayatani1997(

115 uv, uv_d65, L_a, method="VCC"

116 ),

117 result_vcc,

118 atol=TOLERANCE_ABSOLUTE_TESTS,

119 )

120

121 np.testing.assert_allclose(

122 HelmholtzKohlrausch_effect_object_Nayatani1997(

123 uv, uv_d65, L_a, method="VAC"

124 ),

125 result_vac,

126 atol=TOLERANCE_ABSOLUTE_TESTS,

127 )

128

129 @ignore_numpy_errors

130 def test_nan_HelmholtzKohlrausch_effect_object_Nayatani1997(self) -> None:

131 """

132 Test :func:`colour.appearance.hke.\

133 HelmholtzKohlrausch_effect_object_Nayatani1997` definition nan support.

134 """

135

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

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

138 for case in cases:

139 HelmholtzKohlrausch_effect_object_Nayatani1997(case, case, case[0])

140

141

142 class TestHelmholtzKohlrauschEffectLuminousNayatani1997:

143 """

144 Define :func:`colour.appearance.hke.\

145 HelmholtzKohlrausch_effect_luminous_Nayatani1997` definition unit tests

146 methods.

147 """

148

149 def test_HelmholtzKohlrausch_effect_luminous_Nayatani1997(self) -> None:

150 """

151 Test :func:`colour.appearance.hke.\

152 HelmholtzKohlrausch_effect_luminous_Nayatani1997` definition.

153 """

154

155 np.testing.assert_allclose(

156 HelmholtzKohlrausch_effect_luminous_Nayatani1997(

157 np.array([0.40351010, 0.53933673]),

158 np.array([0.19783001, 0.46831999]),

159 63.66,

160 method="VCC",

161 ),

162 2.014433723774654,

163 atol=TOLERANCE_ABSOLUTE_TESTS,

164 )

165

166 np.testing.assert_allclose(

167 HelmholtzKohlrausch_effect_luminous_Nayatani1997(

168 np.array([0.40351010, 0.53933673]),

169 np.array([0.19783001, 0.46831999]),

170 63.66,

171 method="VAC",

172 ),

173 1.727991241148628,

174 atol=TOLERANCE_ABSOLUTE_TESTS,

175 )

176

177 def test_n_dimensional_HelmholtzKohlrausch_effect_luminous_Nayatani1997(

178 self,

179 ) -> None:

180 """

181 Test :func:`colour.appearance.hke.\

182 HelmholtzKohlrausch_effect_luminous_Nayatani1997` definition n_dimensional

183 arrays support.

184 """

185

186 uv_d65 = np.array([0.19783001, 0.46831999])

187 uv = np.array([0.40351010, 0.53933673])

188 L_a = 63.66

189

190 result_vcc = HelmholtzKohlrausch_effect_luminous_Nayatani1997(

191 uv, uv_d65, L_a, method="VCC"

192 )

193 result_vac = HelmholtzKohlrausch_effect_luminous_Nayatani1997(

194 uv, uv_d65, L_a, method="VAC"

195 )

196

197 uv_d65 = np.tile(uv_d65, (6, 1))

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

199 result_vcc = np.tile(result_vcc, 6)

200 result_vac = np.tile(result_vac, 6)

201

202 np.testing.assert_allclose(

203 HelmholtzKohlrausch_effect_luminous_Nayatani1997(

204 uv, uv_d65, L_a, method="VCC"

205 ),

206 result_vcc,

207 atol=TOLERANCE_ABSOLUTE_TESTS,

208 )

209

210 np.testing.assert_allclose(

211 HelmholtzKohlrausch_effect_luminous_Nayatani1997(

212 uv, uv_d65, L_a, method="VAC"

213 ),

214 result_vac,

215 atol=TOLERANCE_ABSOLUTE_TESTS,

216 )

217

218 uv_d65 = np.reshape(uv_d65, (2, 3, 2))

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

220 result_vcc = np.reshape(result_vcc, (2, 3))

221 result_vac = np.reshape(result_vac, (2, 3))

222

223 np.testing.assert_allclose(

224 HelmholtzKohlrausch_effect_luminous_Nayatani1997(

225 uv, uv_d65, L_a, method="VCC"

226 ),

227 result_vcc,

228 atol=TOLERANCE_ABSOLUTE_TESTS,

229 )

230

231 np.testing.assert_allclose(

232 HelmholtzKohlrausch_effect_luminous_Nayatani1997(

233 uv, uv_d65, L_a, method="VAC"

234 ),

235 result_vac,

236 atol=TOLERANCE_ABSOLUTE_TESTS,

237 )

238

239 @ignore_numpy_errors

240 def test_nan_HelmholtzKohlrausch_effect_luminous_Nayatani1997(self) -> None:

241 """

242 Test :func:`colour.appearance.hke.\

243 HelmholtzKohlrausch_effect_luminous_Nayatani1997` definition nan support.

244 """

245

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

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

248 for case in cases:

249 HelmholtzKohlrausch_effect_luminous_Nayatani1997(case, case, case[0])

250

251

252 class TestCoefficient_K_Br_Nayatani1997:

253 """

254 Define :func:`colour.appearance.hke.coefficient_K_Br_Nayatani1997`

255 definition unit tests methods.

256 """

257

258 def test_coefficient_K_Br_Nayatani1997(self) -> None:

259 """

260 Test :func:`colour.appearance.hke.coefficient_K_Br_Nayatani1997`

261 definition.

262 """

263

264 np.testing.assert_allclose(

265 coefficient_K_Br_Nayatani1997(10.00000000),

266 0.71344817765758839,

267 atol=TOLERANCE_ABSOLUTE_TESTS,

268 )

269

270 np.testing.assert_allclose(

271 coefficient_K_Br_Nayatani1997(63.66000000),

272 1.000128455584031,

273 atol=TOLERANCE_ABSOLUTE_TESTS,

274 )

275

276 np.testing.assert_allclose(

277 coefficient_K_Br_Nayatani1997(1000.00000000),

278 1.401080840298197,

279 atol=TOLERANCE_ABSOLUTE_TESTS,

280 )

281

282 np.testing.assert_allclose(

283 coefficient_K_Br_Nayatani1997(10000.00000000),

284 1.592511806930447,

285 atol=TOLERANCE_ABSOLUTE_TESTS,

286 )

287

288 def test_n_dimensional_coefficient_K_Br_Nayatani1997(self) -> None:

289 """

290 Test :func:`colour.appearance.hke.coefficient_K_Br_Nayatani1997`

291 definition n_dimensional arrays support.

292 """

293

294 L_a = 63.66

295 K_Br = coefficient_K_Br_Nayatani1997(L_a)

296

297 L_a = np.tile(L_a, 6)

298 K_Br = np.tile(K_Br, 6)

299 np.testing.assert_allclose(

300 coefficient_K_Br_Nayatani1997(L_a),

301 K_Br,

302 atol=TOLERANCE_ABSOLUTE_TESTS,

303 )

304

305 L_a = np.reshape(L_a, (2, 3))

306 K_Br = np.reshape(K_Br, (2, 3))

307 np.testing.assert_allclose(

308 coefficient_K_Br_Nayatani1997(L_a),

309 K_Br,

310 atol=TOLERANCE_ABSOLUTE_TESTS,

311 )

312

313 L_a = np.reshape(L_a, (2, 3, 1))

314 K_Br = np.reshape(K_Br, (2, 3, 1))

315 np.testing.assert_allclose(

316 coefficient_K_Br_Nayatani1997(L_a),

317 K_Br,

318 atol=TOLERANCE_ABSOLUTE_TESTS,

319 )

320

321 @ignore_numpy_errors

322 def test_nan_coefficient_K_Br_Nayatani1997(self) -> None:

323 """

324 Test :func:`colour.appearance.hke.coefficient_K_Br_Nayatani1997`

325 definition nan support.

326 """

327

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

329 coefficient_K_Br_Nayatani1997(cases)

330

331

332 class TestCoefficient_q_Nayatani1997:

333 """

334 Define :func:`colour.appearance.hke.coefficient_q_Nayatani1997`

335 definition unit tests methods.

336 """

337

338 def test_coefficient_q_Nayatani1997(self) -> None:

339 """

340 Test :func:`colour.appearance.hke.coefficient_q_Nayatani1997`

341 definition.

342 """

343

344 np.testing.assert_allclose(

345 coefficient_q_Nayatani1997(0.00000000),

346 -0.121200000000000,

347 atol=TOLERANCE_ABSOLUTE_TESTS,

348 )

349

350 np.testing.assert_allclose(

351 coefficient_q_Nayatani1997(0.78539816),

352 0.125211117768464,

353 atol=TOLERANCE_ABSOLUTE_TESTS,

354 )

355

356 np.testing.assert_allclose(

357 coefficient_q_Nayatani1997(1.57079633),

358 0.191679999416415,

359 atol=TOLERANCE_ABSOLUTE_TESTS,

360 )

361

362 np.testing.assert_allclose(

363 coefficient_q_Nayatani1997(2.35619449),

364 0.028480866426611,

365 atol=TOLERANCE_ABSOLUTE_TESTS,

366 )

367

368 def test_n_dimensional_coefficient_q_Nayatani1997(self) -> None:

369 """

370 Test :func:`colour.appearance.hke.coefficient_q_Nayatani1997`

371 definition n_dimensional arrays support.

372 """

373

374 L_a = 63.66

375 q = coefficient_q_Nayatani1997(L_a)

376

377 L_a = np.tile(L_a, 6)

378 q = np.tile(q, 6)

379 np.testing.assert_allclose(

380 coefficient_q_Nayatani1997(L_a), q, atol=TOLERANCE_ABSOLUTE_TESTS

381 )

382

383 L_a = np.reshape(L_a, (2, 3))

384 q = np.reshape(q, (2, 3))

385 np.testing.assert_allclose(

386 coefficient_q_Nayatani1997(L_a), q, atol=TOLERANCE_ABSOLUTE_TESTS

387 )

388

389 L_a = np.reshape(L_a, (2, 3, 1))

390 q = np.reshape(q, (2, 3, 1))

391 np.testing.assert_allclose(

392 coefficient_q_Nayatani1997(L_a), q, atol=TOLERANCE_ABSOLUTE_TESTS

393 )

394

395 @ignore_numpy_errors

396 def test_nan_coefficient_q_Nayatani1997(self) -> None:

397 """

398 Test :func:`colour.appearance.hke.coefficient_q_Nayatani1997`

399 definition nan support.

400 """

401

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

403 coefficient_q_Nayatani1997(cases)