Coverage for models/tests/test_din99.py: 100%

1"""Define the unit tests for the :mod:`colour.models.din99` module."""

2

3 from __future__ import annotations

4

5 from itertools import product

6

7 import numpy as np

8

9 from colour.constants import TOLERANCE_ABSOLUTE_TESTS

10 from colour.models import DIN99_to_Lab, DIN99_to_XYZ, Lab_to_DIN99, XYZ_to_DIN99

11 from colour.utilities import domain_range_scale, ignore_numpy_errors

12

13 __author__ = "Colour Developers"

14 __copyright__ = "Copyright 2013 Colour Developers"

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

16 __maintainer__ = "Colour Developers"

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

18 __status__ = "Production"

19

20 __all__ = [

21 "TestLab_to_DIN99",

22 "TestDIN99_to_Lab",

23 "TestXYZ_to_DIN99",

24 "TestDIN99_to_XYZ",

25]

26

27

28 class TestLab_to_DIN99:

29 """

30 Define :func:`colour.models.din99.Lab_to_DIN99` definition unit tests

31 methods.

32 """

33

34 def test_Lab_to_DIN99(self) -> None:

35 """Test :func:`colour.models.din99.Lab_to_DIN99` definition."""

36

37 np.testing.assert_allclose(

38 Lab_to_DIN99(np.array([41.52787529, 52.63858304, 26.92317922])),

39 np.array([53.22821988, 28.41634656, 3.89839552]),

40 atol=TOLERANCE_ABSOLUTE_TESTS,

41 )

42

43 np.testing.assert_allclose(

44 Lab_to_DIN99(np.array([55.11636304, -41.08791787, 30.91825778])),

45 np.array([66.08943912, -17.35290106, 16.09690691]),

46 atol=TOLERANCE_ABSOLUTE_TESTS,

47 )

48

49 np.testing.assert_allclose(

50 Lab_to_DIN99(np.array([29.80565520, 20.01830466, -48.34913874])),

51 np.array([40.71533366, 3.48714163, -21.45321411]),

52 atol=TOLERANCE_ABSOLUTE_TESTS,

53 )

54

55 np.testing.assert_allclose(

56 Lab_to_DIN99(

57 np.array([41.52787529, 52.63858304, 26.92317922]),

58 method="DIN99b",

59 ),

60 np.array([45.58303137, 34.71824493, 17.61622149]),

61 atol=TOLERANCE_ABSOLUTE_TESTS,

62 )

63

64 np.testing.assert_allclose(

65 Lab_to_DIN99(

66 np.array([41.52787529, 52.63858304, 26.92317922]),

67 method="DIN99c",

68 ),

69 np.array([45.40284208, 32.75074741, 15.74603532]),

70 atol=TOLERANCE_ABSOLUTE_TESTS,

71 )

72

73 np.testing.assert_allclose(

74 Lab_to_DIN99(

75 np.array([41.52787529, 52.63858304, 26.92317922]),

76 method="DIN99d",

77 ),

78 np.array([45.31204747, 31.42106716, 14.17004652]),

79 atol=TOLERANCE_ABSOLUTE_TESTS,

80 )

81

82 def test_n_dimensional_Lab_to_DIN99(self) -> None:

83 """

84 Test :func:`colour.models.din99.Lab_to_DIN99` definition n-dimensional

85 support.

86 """

87

88 Lab = np.array([41.52787529, 52.63858304, 26.92317922])

89 Lab_99 = Lab_to_DIN99(Lab)

90

91 Lab = np.tile(Lab, (6, 1))

92 Lab_99 = np.tile(Lab_99, (6, 1))

93 np.testing.assert_allclose(

94 Lab_to_DIN99(Lab), Lab_99, atol=TOLERANCE_ABSOLUTE_TESTS

95 )

96

97 Lab = np.reshape(Lab, (2, 3, 3))

98 Lab_99 = np.reshape(Lab_99, (2, 3, 3))

99 np.testing.assert_allclose(

100 Lab_to_DIN99(Lab), Lab_99, atol=TOLERANCE_ABSOLUTE_TESTS

101 )

102

103 def test_domain_range_scale_Lab_to_DIN99(self) -> None:

104 """

105 Test :func:`colour.models.din99.Lab_to_DIN99` definition domain and

106 range scale support.

107 """

108

109 Lab = np.array([41.52787529, 52.63858304, 26.92317922])

110 Lab_99 = Lab_to_DIN99(Lab)

111 Lab_99_b = Lab_to_DIN99(Lab, method="DIN99b")

112 Lab_99_c = Lab_to_DIN99(Lab, method="DIN99c")

113 Lab_99_d = Lab_to_DIN99(Lab, method="DIN99d")

114

115 d_r = (("reference", 1), ("1", 0.01), ("100", 1))

116 for scale, factor in d_r:

117 with domain_range_scale(scale):

118 np.testing.assert_allclose(

119 Lab_to_DIN99(Lab * factor),

120 Lab_99 * factor,

121 atol=TOLERANCE_ABSOLUTE_TESTS,

122 )

123 np.testing.assert_allclose(

124 Lab_to_DIN99((Lab * factor), method="DIN99b"),

125 Lab_99_b * factor,

126 atol=TOLERANCE_ABSOLUTE_TESTS,

127 )

128 np.testing.assert_allclose(

129 Lab_to_DIN99((Lab * factor), method="DIN99c"),

130 Lab_99_c * factor,

131 atol=TOLERANCE_ABSOLUTE_TESTS,

132 )

133 np.testing.assert_allclose(

134 Lab_to_DIN99((Lab * factor), method="DIN99d"),

135 Lab_99_d * factor,

136 atol=TOLERANCE_ABSOLUTE_TESTS,

137 )

138

139 @ignore_numpy_errors

140 def test_nan_Lab_to_DIN99(self) -> None:

141 """Test :func:`colour.models.din99.Lab_to_DIN99` definition nan support."""

142

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

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

145 Lab_to_DIN99(cases)

146 Lab_to_DIN99(cases, method="DIN99b")

147 Lab_to_DIN99(cases, method="DIN99c")

148 Lab_to_DIN99(cases, method="DIN99d")

149

150

151 class TestDIN99_to_Lab:

152 """

153 Define :func:`colour.models.din99.DIN99_to_Lab` definition unit tests

154 methods.

155 """

156

157 def test_DIN99_to_Lab(self) -> None:

158 """Test :func:`colour.models.din99.DIN99_to_Lab` definition."""

159

160 np.testing.assert_allclose(

161 DIN99_to_Lab(np.array([53.22821988, 28.41634656, 3.89839552])),

162 np.array([41.52787529, 52.63858304, 26.92317922]),

163 atol=TOLERANCE_ABSOLUTE_TESTS,

164 )

165

166 np.testing.assert_allclose(

167 DIN99_to_Lab(np.array([66.08943912, -17.35290106, 16.09690691])),

168 np.array([55.11636304, -41.08791787, 30.91825778]),

169 atol=TOLERANCE_ABSOLUTE_TESTS,

170 )

171

172 np.testing.assert_allclose(

173 DIN99_to_Lab(np.array([40.71533366, 3.48714163, -21.45321411])),

174 np.array([29.80565520, 20.01830466, -48.34913874]),

175 atol=TOLERANCE_ABSOLUTE_TESTS,

176 )

177

178 np.testing.assert_allclose(

179 DIN99_to_Lab(

180 np.array([45.58303137, 34.71824493, 17.61622149]),

181 method="DIN99b",

182 ),

183 np.array([41.52787529, 52.63858304, 26.92317922]),

184 atol=TOLERANCE_ABSOLUTE_TESTS,

185 )

186

187 np.testing.assert_allclose(

188 DIN99_to_Lab(

189 np.array([45.40284208, 32.75074741, 15.74603532]),

190 method="DIN99c",

191 ),

192 np.array([41.52787529, 52.63858304, 26.92317922]),

193 atol=TOLERANCE_ABSOLUTE_TESTS,

194 )

195

196 np.testing.assert_allclose(

197 DIN99_to_Lab(

198 np.array([45.31204747, 31.42106716, 14.17004652]),

199 method="DIN99d",

200 ),

201 np.array([41.52787529, 52.63858304, 26.92317922]),

202 atol=TOLERANCE_ABSOLUTE_TESTS,

203 )

204

205 def test_n_dimensional_DIN99_to_Lab(self) -> None:

206 """

207 Test :func:`colour.models.din99.DIN99_to_Lab` definition n-dimensional

208 support.

209 """

210

211 Lab_99 = np.array([53.22821988, 28.41634656, 3.89839552])

212 Lab = DIN99_to_Lab(Lab_99)

213

214 Lab_99 = np.tile(Lab_99, (6, 1))

215 Lab = np.tile(Lab, (6, 1))

216 np.testing.assert_allclose(

217 DIN99_to_Lab(Lab_99), Lab, atol=TOLERANCE_ABSOLUTE_TESTS

218 )

219

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

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

222 np.testing.assert_allclose(

223 DIN99_to_Lab(Lab_99), Lab, atol=TOLERANCE_ABSOLUTE_TESTS

224 )

225

226 def test_domain_range_scale_DIN99_to_Lab(self) -> None:

227 """

228 Test :func:`colour.models.din99.DIN99_to_Lab` definition domain and

229 range scale support.

230 """

231

232 Lab_99 = np.array([53.22821988, 28.41634656, 3.89839552])

233 Lab = DIN99_to_Lab(Lab_99)

234 Lab_b = DIN99_to_Lab(Lab_99, method="DIN99b")

235 Lab_c = DIN99_to_Lab(Lab_99, method="DIN99c")

236 Lab_d = DIN99_to_Lab(Lab_99, method="DIN99d")

237

238 d_r = (("reference", 1), ("1", 0.01), ("100", 1))

239 for scale, factor in d_r:

240 with domain_range_scale(scale):

241 np.testing.assert_allclose(

242 DIN99_to_Lab(Lab_99 * factor),

243 Lab * factor,

244 atol=TOLERANCE_ABSOLUTE_TESTS,

245 )

246 np.testing.assert_allclose(

247 DIN99_to_Lab((Lab_99 * factor), method="DIN99b"),

248 Lab_b * factor,

249 atol=TOLERANCE_ABSOLUTE_TESTS,

250 )

251 np.testing.assert_allclose(

252 DIN99_to_Lab((Lab_99 * factor), method="DIN99c"),

253 Lab_c * factor,

254 atol=TOLERANCE_ABSOLUTE_TESTS,

255 )

256 np.testing.assert_allclose(

257 DIN99_to_Lab((Lab_99 * factor), method="DIN99d"),

258 Lab_d * factor,

259 atol=TOLERANCE_ABSOLUTE_TESTS,

260 )

261

262 @ignore_numpy_errors

263 def test_nan_DIN99_to_Lab(self) -> None:

264 """Test :func:`colour.models.din99.DIN99_to_Lab` definition nan support."""

265

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

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

268 DIN99_to_Lab(cases)

269 DIN99_to_Lab(cases, method="DIN99b")

270 DIN99_to_Lab(cases, method="DIN99c")

271 DIN99_to_Lab(cases, method="DIN99d")

272

273

274 class TestXYZ_to_DIN99:

275 """

276 Define :func:`colour.models.din99.XYZ_to_DIN99` definition unit tests

277 methods.

278 """

279

280 def test_XYZ_to_DIN99(self) -> None:

281 """Test :func:`colour.models.din99.XYZ_to_DIN99` definition."""

282

283 np.testing.assert_allclose(

284 XYZ_to_DIN99(np.array([0.20654008, 0.12197225, 0.05136952])),

285 np.array([53.22821988, 28.41634656, 3.89839552]),

286 atol=TOLERANCE_ABSOLUTE_TESTS,

287 )

288

289 np.testing.assert_allclose(

290 XYZ_to_DIN99(np.array([0.14222010, 0.23042768, 0.10495772])),

291 np.array([66.08943912, -17.35290106, 16.09690691]),

292 atol=TOLERANCE_ABSOLUTE_TESTS,

293 )

294

295 np.testing.assert_allclose(

296 XYZ_to_DIN99(np.array([0.07818780, 0.06157201, 0.28099326])),

297 np.array([40.71533366, 3.48714163, -21.45321411]),

298 atol=TOLERANCE_ABSOLUTE_TESTS,

299 )

300

301 np.testing.assert_allclose(

302 XYZ_to_DIN99(

303 np.array([0.20654008, 0.12197225, 0.05136952]), method="DIN99b"

304 ),

305 np.array([45.58303137, 34.71824493, 17.61622149]),

306 atol=TOLERANCE_ABSOLUTE_TESTS,

307 )

308

309 def test_n_dimensional_XYZ_to_DIN99(self) -> None:

310 """

311 Test :func:`colour.models.din99.XYZ_to_DIN99` definition n-dimensional

312 support.

313 """

314

315 XYZ = np.array([0.20654008, 0.12197225, 0.05136952])

316 Lab_99 = XYZ_to_DIN99(XYZ)

317

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

319 Lab_99 = np.tile(Lab_99, (6, 1))

320 np.testing.assert_allclose(

321 XYZ_to_DIN99(XYZ), Lab_99, atol=TOLERANCE_ABSOLUTE_TESTS

322 )

323

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

325 Lab_99 = np.reshape(Lab_99, (2, 3, 3))

326 np.testing.assert_allclose(

327 XYZ_to_DIN99(XYZ), Lab_99, atol=TOLERANCE_ABSOLUTE_TESTS

328 )

329

330 def test_domain_range_scale_XYZ_to_DIN99(self) -> None:

331 """

332 Test :func:`colour.models.din99.XYZ_to_DIN99` definition domain and

333 range scale support.

334 """

335

336 XYZ = np.array([0.20654008, 0.12197225, 0.05136952])

337 Lab_99 = XYZ_to_DIN99(XYZ)

338

339 d_r = (("reference", 1, 1), ("1", 1, 0.01), ("100", 100, 1))

340 for scale, factor_a, factor_b in d_r:

341 with domain_range_scale(scale):

342 np.testing.assert_allclose(

343 XYZ_to_DIN99(XYZ * factor_a),

344 Lab_99 * factor_b,

345 atol=TOLERANCE_ABSOLUTE_TESTS,

346 )

347

348 @ignore_numpy_errors

349 def test_nan_XYZ_to_DIN99(self) -> None:

350 """Test :func:`colour.models.din99.XYZ_to_DIN99` definition nan support."""

351

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

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

354 XYZ_to_DIN99(cases)

355

356

357 class TestDIN99_to_XYZ:

358 """

359 Define :func:`colour.models.din99.DIN99_to_XYZ` definition unit tests

360 methods.

361 """

362

363 def test_DIN99_to_XYZ(self) -> None:

364 """Test :func:`colour.models.din99.DIN99_to_XYZ` definition."""

365

366 np.testing.assert_allclose(

367 DIN99_to_XYZ(np.array([53.22821988, 28.41634656, 3.89839552])),

368 np.array([0.20654008, 0.12197225, 0.05136952]),

369 atol=TOLERANCE_ABSOLUTE_TESTS,

370 )

371

372 np.testing.assert_allclose(

373 DIN99_to_XYZ(np.array([66.08943912, -17.35290106, 16.09690691])),

374 np.array([0.14222010, 0.23042768, 0.10495772]),

375 atol=TOLERANCE_ABSOLUTE_TESTS,

376 )

377

378 np.testing.assert_allclose(

379 DIN99_to_XYZ(np.array([40.71533366, 3.48714163, -21.45321411])),

380 np.array([0.07818780, 0.06157201, 0.28099326]),

381 atol=TOLERANCE_ABSOLUTE_TESTS,

382 )

383

384 np.testing.assert_allclose(

385 DIN99_to_XYZ(

386 np.array([45.58303137, 34.71824493, 17.61622149]),

387 method="DIN99b",

388 ),

389 np.array([0.20654008, 0.12197225, 0.05136952]),

390 atol=TOLERANCE_ABSOLUTE_TESTS,

391 )

392

393 def test_n_dimensional_DIN99_to_XYZ(self) -> None:

394 """

395 Test :func:`colour.models.din99.DIN99_to_XYZ` definition n-dimensional

396 support.

397 """

398

399 Lab_99 = np.array([53.22821988, 28.41634656, 3.89839552])

400 XYZ = DIN99_to_XYZ(Lab_99)

401

402 Lab_99 = np.tile(Lab_99, (6, 1))

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

404 np.testing.assert_allclose(

405 DIN99_to_XYZ(Lab_99), XYZ, atol=TOLERANCE_ABSOLUTE_TESTS

406 )

407

408 Lab_99 = np.reshape(Lab_99, (2, 3, 3))

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

410 np.testing.assert_allclose(

411 DIN99_to_XYZ(Lab_99), XYZ, atol=TOLERANCE_ABSOLUTE_TESTS

412 )

413

414 def test_domain_range_scale_DIN99_to_XYZ(self) -> None:

415 """

416 Test :func:`colour.models.din99.DIN99_to_XYZ` definition domain and

417 range scale support.

418 """

419

420 Lab_99 = np.array([53.22821988, 28.41634656, 3.89839552])

421 XYZ = DIN99_to_XYZ(Lab_99)

422

423 d_r = (("reference", 1, 1), ("1", 0.01, 1), ("100", 1, 100))

424 for scale, factor_a, factor_b in d_r:

425 with domain_range_scale(scale):

426 np.testing.assert_allclose(

427 DIN99_to_XYZ(Lab_99 * factor_a),

428 XYZ * factor_b,

429 atol=TOLERANCE_ABSOLUTE_TESTS,

430 )

431

432 @ignore_numpy_errors

433 def test_nan_DIN99_to_XYZ(self) -> None:

434 """Test :func:`colour.models.din99.DIN99_to_XYZ` definition nan support."""

435

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

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

438 DIN99_to_XYZ(cases)