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

1"""Define the unit tests for the :mod:`colour.models.jzazbz` 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 Izazbz_to_XYZ, Jzazbz_to_XYZ, XYZ_to_Izazbz, XYZ_to_Jzazbz

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 "TestXYZ_to_Izazbz",

22 "TestIzazbz_to_XYZ",

23 "TestXYZ_to_Jzazbz",

24 "TestJzazbz_to_XYZ",

25]

26

27

28 class TestXYZ_to_Izazbz:

29 """

30 Define :func:`colour.models.jzazbz.TestXYZ_to_Izazbz` definition unit

31 tests methods.

32 """

33

34 def test_XYZ_to_Izazbz(self) -> None:

35 """Test :func:`colour.models.jzazbz.XYZ_to_Izazbz` definition."""

36

37 np.testing.assert_allclose(

38 XYZ_to_Izazbz(np.array([0.20654008, 0.12197225, 0.05136952])),

39 np.array([0.01207793, 0.00924302, 0.00526007]),

40 atol=TOLERANCE_ABSOLUTE_TESTS,

41 )

42

43 np.testing.assert_allclose(

44 XYZ_to_Izazbz(np.array([0.14222010, 0.23042768, 0.10495772])),

45 np.array([0.01397346, -0.00608426, 0.00534077]),

46 atol=TOLERANCE_ABSOLUTE_TESTS,

47 )

48

49 np.testing.assert_allclose(

50 XYZ_to_Izazbz(np.array([0.96907232, 1.00000000, 1.12179215])),

51 np.array([0.03927203, 0.00064174, -0.00052906]),

52 atol=TOLERANCE_ABSOLUTE_TESTS,

53 )

54

55 np.testing.assert_allclose(

56 XYZ_to_Izazbz(

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

58 method="Safdar 2021",

59 ),

60 np.array([0.01049146, 0.00924302, 0.00526007]),

61 atol=TOLERANCE_ABSOLUTE_TESTS,

62 )

63

64 np.testing.assert_array_equal(

65 XYZ_to_Izazbz(

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

67 method="Safdar 2021",

68 ),

69 XYZ_to_Izazbz(

70 np.array([0.20654008, 0.12197225, 0.05136952]), method="ZCAM"

71 ),

72 )

73

74 def test_n_dimensional_XYZ_to_Izazbz(self) -> None:

75 """

76 Test :func:`colour.models.jzazbz.XYZ_to_Izazbz` definition

77 n-dimensional support.

78 """

79

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

81 Izazbz = XYZ_to_Izazbz(XYZ)

82

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

84 Izazbz = np.tile(Izazbz, (6, 1))

85 np.testing.assert_allclose(

86 XYZ_to_Izazbz(XYZ), Izazbz, atol=TOLERANCE_ABSOLUTE_TESTS

87 )

88

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

90 Izazbz = np.reshape(Izazbz, (2, 3, 3))

91 np.testing.assert_allclose(

92 XYZ_to_Izazbz(XYZ), Izazbz, atol=TOLERANCE_ABSOLUTE_TESTS

93 )

94

95 def test_domain_range_scale_XYZ_to_Izazbz(self) -> None:

96 """

97 Test :func:`colour.models.jzazbz.XYZ_to_Izazbz` definition domain and

98 range scale support.

99 """

100

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

102 Izazbz = XYZ_to_Izazbz(XYZ)

103

104 d_r = (("reference", 1), ("1", 1), ("100", 1))

105 for scale, factor in d_r:

106 with domain_range_scale(scale):

107 np.testing.assert_allclose(

108 XYZ_to_Izazbz(XYZ * factor),

109 Izazbz * factor,

110 atol=TOLERANCE_ABSOLUTE_TESTS,

111 )

112

113 @ignore_numpy_errors

114 def test_nan_XYZ_to_Izazbz(self) -> None:

115 """

116 Test :func:`colour.models.jzazbz.XYZ_to_Izazbz` definition nan

117 support.

118 """

119

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

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

122 XYZ_to_Izazbz(cases)

123

124

125 class TestIzazbz_to_XYZ:

126 """

127 Define :func:`colour.models.jzazbz.Izazbz_to_XYZ` definition unit tests

128 methods.

129 """

130

131 def test_Izazbz_to_XYZ(self) -> None:

132 """Test :func:`colour.models.jzazbz.Izazbz_to_XYZ` definition."""

133

134 np.testing.assert_allclose(

135 Izazbz_to_XYZ(np.array([0.01207793, 0.00924302, 0.00526007])),

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

137 atol=TOLERANCE_ABSOLUTE_TESTS,

138 )

139

140 np.testing.assert_allclose(

141 Izazbz_to_XYZ(np.array([0.01397346, -0.00608426, 0.00534077])),

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

143 atol=TOLERANCE_ABSOLUTE_TESTS,

144 )

145

146 np.testing.assert_allclose(

147 Izazbz_to_XYZ(np.array([0.03927203, 0.00064174, -0.00052906])),

148 np.array([0.96907232, 1.00000000, 1.12179215]),

149 atol=TOLERANCE_ABSOLUTE_TESTS,

150 )

151

152 np.testing.assert_allclose(

153 Izazbz_to_XYZ(np.array([0.03927203, 0.00064174, -0.00052906])),

154 np.array([0.96907232, 1.00000000, 1.12179215]),

155 atol=TOLERANCE_ABSOLUTE_TESTS,

156 )

157

158 np.testing.assert_allclose(

159 Izazbz_to_XYZ(

160 np.array([0.01049146, 0.00924302, 0.00526007]),

161 method="Safdar 2021",

162 ),

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

164 atol=TOLERANCE_ABSOLUTE_TESTS,

165 )

166

167 np.testing.assert_array_equal(

168 Izazbz_to_XYZ(

169 np.array([0.01049146, 0.00924302, 0.00526007]),

170 method="Safdar 2021",

171 ),

172 Izazbz_to_XYZ(

173 np.array([0.01049146, 0.00924302, 0.00526007]), method="ZCAM"

174 ),

175 )

176

177 def test_n_dimensional_Izazbz_to_XYZ(self) -> None:

178 """

179 Test :func:`colour.models.jzazbz.Izazbz_to_XYZ` definition

180 n-dimensional support.

181 """

182

183 Izazbz = np.array([0.01207793, 0.00924302, 0.00526007])

184 XYZ = Izazbz_to_XYZ(Izazbz)

185

186 Izazbz = np.tile(Izazbz, (6, 1))

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

188 np.testing.assert_allclose(

189 Izazbz_to_XYZ(Izazbz), XYZ, atol=TOLERANCE_ABSOLUTE_TESTS

190 )

191

192 Izazbz = np.reshape(Izazbz, (2, 3, 3))

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

194 np.testing.assert_allclose(

195 Izazbz_to_XYZ(Izazbz), XYZ, atol=TOLERANCE_ABSOLUTE_TESTS

196 )

197

198 def test_domain_range_scale_Izazbz_to_XYZ(self) -> None:

199 """

200 Test :func:`colour.models.jzazbz.Izazbz_to_XYZ` definition domain and

201 range scale support.

202 """

203

204 Izazbz = np.array([0.01207793, 0.00924302, 0.00526007])

205 XYZ = Izazbz_to_XYZ(Izazbz)

206

207 d_r = (("reference", 1), ("1", 1), ("100", 1))

208 for scale, factor in d_r:

209 with domain_range_scale(scale):

210 np.testing.assert_allclose(

211 Izazbz_to_XYZ(Izazbz * factor),

212 XYZ * factor,

213 atol=TOLERANCE_ABSOLUTE_TESTS,

214 )

215

216 @ignore_numpy_errors

217 def test_nan_Izazbz_to_XYZ(self) -> None:

218 """

219 Test :func:`colour.models.jzazbz.Izazbz_to_XYZ` definition nan

220 support.

221 """

222

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

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

225 Izazbz_to_XYZ(cases)

226

227

228 class TestXYZ_to_Jzazbz:

229 """

230 Define :func:`colour.models.jzazbz.TestXYZ_to_Jzazbz` definition unit

231 tests methods.

232 """

233

234 def test_XYZ_to_Jzazbz(self) -> None:

235 """Test :func:`colour.models.jzazbz.XYZ_to_Jzazbz` definition."""

236

237 np.testing.assert_allclose(

238 XYZ_to_Jzazbz(np.array([0.20654008, 0.12197225, 0.05136952])),

239 np.array([0.00535048, 0.00924302, 0.00526007]),

240 atol=TOLERANCE_ABSOLUTE_TESTS,

241 )

242

243 np.testing.assert_allclose(

244 XYZ_to_Jzazbz(np.array([0.14222010, 0.23042768, 0.10495772])),

245 np.array([0.00619681, -0.00608426, 0.00534077]),

246 atol=TOLERANCE_ABSOLUTE_TESTS,

247 )

248

249 np.testing.assert_allclose(

250 XYZ_to_Jzazbz(np.array([0.96907232, 1.00000000, 1.12179215])),

251 np.array([0.01766826, 0.00064174, -0.00052906]),

252 atol=TOLERANCE_ABSOLUTE_TESTS,

253 )

254

255 def test_n_dimensional_XYZ_to_Jzazbz(self) -> None:

256 """

257 Test :func:`colour.models.jzazbz.XYZ_to_Jzazbz` definition

258 n-dimensional support.

259 """

260

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

262 Jzazbz = XYZ_to_Jzazbz(XYZ)

263

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

265 Jzazbz = np.tile(Jzazbz, (6, 1))

266 np.testing.assert_allclose(

267 XYZ_to_Jzazbz(XYZ), Jzazbz, atol=TOLERANCE_ABSOLUTE_TESTS

268 )

269

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

271 Jzazbz = np.reshape(Jzazbz, (2, 3, 3))

272 np.testing.assert_allclose(

273 XYZ_to_Jzazbz(XYZ), Jzazbz, atol=TOLERANCE_ABSOLUTE_TESTS

274 )

275

276 def test_domain_range_scale_XYZ_to_Jzazbz(self) -> None:

277 """

278 Test :func:`colour.models.jzazbz.XYZ_to_Jzazbz` definition domain and

279 range scale support.

280 """

281

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

283 Jzazbz = XYZ_to_Jzazbz(XYZ)

284

285 d_r = (("reference", 1), ("1", 1), ("100", 1))

286 for scale, factor in d_r:

287 with domain_range_scale(scale):

288 np.testing.assert_array_equal(

289 XYZ_to_Jzazbz(XYZ * factor), Jzazbz * factor

290 )

291

292 @ignore_numpy_errors

293 def test_nan_XYZ_to_Jzazbz(self) -> None:

294 """

295 Test :func:`colour.models.jzazbz.XYZ_to_Jzazbz` definition nan

296 support.

297 """

298

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

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

301 XYZ_to_Jzazbz(cases)

302

303

304 class TestJzazbz_to_XYZ:

305 """

306 Define :func:`colour.models.jzazbz.Jzazbz_to_XYZ` definition unit tests

307 methods.

308 """

309

310 def test_Jzazbz_to_XYZ(self) -> None:

311 """Test :func:`colour.models.jzazbz.Jzazbz_to_XYZ` definition."""

312

313 np.testing.assert_allclose(

314 Jzazbz_to_XYZ(np.array([0.00535048, 0.00924302, 0.00526007])),

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

316 atol=1e-6,

317 )

318

319 np.testing.assert_allclose(

320 Jzazbz_to_XYZ(np.array([0.00619681, -0.00608426, 0.00534077])),

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

322 atol=1e-6,

323 )

324

325 np.testing.assert_allclose(

326 Jzazbz_to_XYZ(np.array([0.01766826, 0.00064174, -0.00052906])),

327 np.array([0.96907232, 1.00000000, 1.12179215]),

328 atol=1e-6,

329 )

330

331 def test_n_dimensional_Jzazbz_to_XYZ(self) -> None:

332 """

333 Test :func:`colour.models.jzazbz.Jzazbz_to_XYZ` definition

334 n-dimensional support.

335 """

336

337 Jzazbz = np.array([0.00535048, 0.00924302, 0.00526007])

338 XYZ = Jzazbz_to_XYZ(Jzazbz)

339

340 Jzazbz = np.tile(Jzazbz, (6, 1))

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

342 np.testing.assert_allclose(

343 Jzazbz_to_XYZ(Jzazbz), XYZ, atol=TOLERANCE_ABSOLUTE_TESTS

344 )

345

346 Jzazbz = np.reshape(Jzazbz, (2, 3, 3))

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

348 np.testing.assert_allclose(

349 Jzazbz_to_XYZ(Jzazbz), XYZ, atol=TOLERANCE_ABSOLUTE_TESTS

350 )

351

352 def test_domain_range_scale_Jzazbz_to_XYZ(self) -> None:

353 """

354 Test :func:`colour.models.jzazbz.Jzazbz_to_XYZ` definition domain and

355 range scale support.

356 """

357

358 Jzazbz = np.array([0.00535048, 0.00924302, 0.00526007])

359 XYZ = Jzazbz_to_XYZ(Jzazbz)

360

361 d_r = (("reference", 1), ("1", 1), ("100", 1))

362 for scale, factor in d_r:

363 with domain_range_scale(scale):

364 np.testing.assert_allclose(

365 Jzazbz_to_XYZ(Jzazbz * factor),

366 XYZ * factor,

367 atol=TOLERANCE_ABSOLUTE_TESTS,

368 )

369

370 @ignore_numpy_errors

371 def test_nan_Jzazbz_to_XYZ(self) -> None:

372 """

373 Test :func:`colour.models.jzazbz.Jzazbz_to_XYZ` definition nan

374 support.

375 """

376

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

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

379 Jzazbz_to_XYZ(cases)