Coverage for colour/blindness/tests/test_machado2009.py: 100%

48 statements  

« prev     ^ index     » next       coverage.py v7.11.0, created at 2025-11-15 19:01 +1300

1"""Define the unit tests for the :mod:`colour.blindness.machado2009` module.""" 

2 

3from __future__ import annotations 

4 

5import numpy as np 

6 

7from colour.blindness import ( 

8 CVD_MATRICES_MACHADO2010, 

9 matrix_anomalous_trichromacy_Machado2009, 

10 matrix_cvd_Machado2009, 

11 msds_cmfs_anomalous_trichromacy_Machado2009, 

12) 

13from colour.characterisation import MSDS_DISPLAY_PRIMARIES 

14from colour.colorimetry import MSDS_CMFS_LMS 

15from colour.constants import TOLERANCE_ABSOLUTE_TESTS 

16from colour.utilities import ignore_numpy_errors 

17 

18__author__ = "Colour Developers" 

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

27 "TestMatrixAnomalousTrichromacyMachado2009", 

28 "TestMatrixCvdMachado2009", 

29] 

30 

31 

32class TestMsdsCmfsAnomalousTrichromacyMachado2009: 

33 """ 

34 Define :func:`colour.blindness.machado2009.\ 

35msds_cmfs_anomalous_trichromacy_Machado2009` definition unit tests methods. 

36 """ 

37 

38 def test_msds_cmfs_anomalous_trichromacy_Machado2009(self) -> None: 

39 """ 

40 Test :func:`colour.blindness.machado2009.\ 

41msds_cmfs_anomalous_trichromacy_Machado2009` definition. 

42 """ 

43 

44 cmfs = MSDS_CMFS_LMS["Smith & Pokorny 1975 Normal Trichromats"] 

45 np.testing.assert_allclose( 

46 msds_cmfs_anomalous_trichromacy_Machado2009( 

47 cmfs, 

48 np.array( 

49 [0, 0, 0], 

50 ), 

51 )[450], 

52 cmfs[450], 

53 atol=TOLERANCE_ABSOLUTE_TESTS, 

54 ) 

55 

56 np.testing.assert_allclose( 

57 msds_cmfs_anomalous_trichromacy_Machado2009( 

58 cmfs, 

59 np.array( 

60 [1, 0, 0], 

61 ), 

62 )[450], 

63 np.array([0.03631700, 0.06350000, 0.91000000]), 

64 atol=TOLERANCE_ABSOLUTE_TESTS, 

65 ) 

66 

67 np.testing.assert_allclose( 

68 msds_cmfs_anomalous_trichromacy_Machado2009( 

69 cmfs, 

70 np.array( 

71 [0, 1, 0], 

72 ), 

73 )[450], 

74 np.array([0.03430000, 0.06178404, 0.91000000]), 

75 atol=TOLERANCE_ABSOLUTE_TESTS, 

76 ) 

77 

78 np.testing.assert_allclose( 

79 msds_cmfs_anomalous_trichromacy_Machado2009( 

80 cmfs, 

81 np.array( 

82 [0, 0, 1], 

83 ), 

84 )[450], 

85 np.array([0.03430000, 0.06350000, 0.92270240]), 

86 atol=TOLERANCE_ABSOLUTE_TESTS, 

87 ) 

88 

89 np.testing.assert_allclose( 

90 msds_cmfs_anomalous_trichromacy_Machado2009( 

91 cmfs, 

92 np.array( 

93 [10, 0, 0], 

94 ), 

95 )[450], 

96 np.array([0.05447001, 0.06350000, 0.91000000]), 

97 atol=TOLERANCE_ABSOLUTE_TESTS, 

98 ) 

99 

100 np.testing.assert_allclose( 

101 msds_cmfs_anomalous_trichromacy_Machado2009( 

102 cmfs, 

103 np.array( 

104 [0, 10, 0], 

105 ), 

106 )[450], 

107 np.array([0.03430000, 0.04634036, 0.91000000]), 

108 atol=TOLERANCE_ABSOLUTE_TESTS, 

109 ) 

110 

111 np.testing.assert_allclose( 

112 msds_cmfs_anomalous_trichromacy_Machado2009( 

113 cmfs, 

114 np.array( 

115 [0, 0, 10], 

116 ), 

117 )[450], 

118 np.array([0.03430000, 0.06350000, 1.00000000]), 

119 atol=TOLERANCE_ABSOLUTE_TESTS, 

120 ) 

121 

122 

123class TestMatrixAnomalousTrichromacyMachado2009: 

124 """ 

125 Define :func:`colour.blindness.machado2009.\ 

126matrix_anomalous_trichromacy_Machado2009` definition unit tests methods. 

127 """ 

128 

129 def test_matrix_anomalous_trichromacy_Machado2009(self) -> None: 

130 """ 

131 Test :func:`colour.blindness.machado2009.\ 

132matrix_anomalous_trichromacy_Machado2009` definition. 

133 """ 

134 

135 cmfs = MSDS_CMFS_LMS["Smith & Pokorny 1975 Normal Trichromats"] 

136 primaries = MSDS_DISPLAY_PRIMARIES["Typical CRT Brainard 1997"] 

137 np.testing.assert_allclose( 

138 matrix_anomalous_trichromacy_Machado2009( 

139 cmfs, primaries, np.array([0, 0, 0]) 

140 ), 

141 np.identity(3), 

142 atol=TOLERANCE_ABSOLUTE_TESTS, 

143 ) 

144 

145 np.testing.assert_allclose( 

146 matrix_anomalous_trichromacy_Machado2009( 

147 cmfs, primaries, np.array([2, 0, 0]) 

148 ), 

149 CVD_MATRICES_MACHADO2010["Protanomaly"][0.1], 

150 atol=0.0001, 

151 ) 

152 

153 np.testing.assert_allclose( 

154 matrix_anomalous_trichromacy_Machado2009( 

155 cmfs, primaries, np.array([10, 0, 0]) 

156 ), 

157 CVD_MATRICES_MACHADO2010["Protanomaly"][0.5], 

158 atol=0.0001, 

159 ) 

160 

161 np.testing.assert_allclose( 

162 matrix_anomalous_trichromacy_Machado2009( 

163 cmfs, primaries, np.array([20, 0, 0]) 

164 ), 

165 CVD_MATRICES_MACHADO2010["Protanomaly"][1.0], 

166 atol=0.0001, 

167 ) 

168 

169 np.testing.assert_allclose( 

170 matrix_anomalous_trichromacy_Machado2009( 

171 cmfs, primaries, np.array([0, 2, 0]) 

172 ), 

173 CVD_MATRICES_MACHADO2010["Deuteranomaly"][0.1], 

174 atol=0.0001, 

175 ) 

176 

177 np.testing.assert_allclose( 

178 matrix_anomalous_trichromacy_Machado2009( 

179 cmfs, primaries, np.array([0, 10, 0]) 

180 ), 

181 CVD_MATRICES_MACHADO2010["Deuteranomaly"][0.5], 

182 atol=0.0001, 

183 ) 

184 

185 np.testing.assert_allclose( 

186 matrix_anomalous_trichromacy_Machado2009( 

187 cmfs, primaries, np.array([0, 20, 0]) 

188 ), 

189 CVD_MATRICES_MACHADO2010["Deuteranomaly"][1.0], 

190 atol=0.0001, 

191 ) 

192 

193 np.testing.assert_allclose( 

194 matrix_anomalous_trichromacy_Machado2009( 

195 cmfs, primaries, np.array([0, 0, 5.00056688094503]) 

196 ), 

197 CVD_MATRICES_MACHADO2010["Tritanomaly"][0.1], 

198 atol=0.0001, 

199 ) 

200 

201 np.testing.assert_allclose( 

202 matrix_anomalous_trichromacy_Machado2009( 

203 cmfs, primaries, np.array([0, 0, 29.002939088780934]) 

204 ), 

205 CVD_MATRICES_MACHADO2010["Tritanomaly"][0.5], 

206 atol=0.0001, 

207 ) 

208 

209 np.testing.assert_allclose( 

210 matrix_anomalous_trichromacy_Machado2009( 

211 cmfs, primaries, np.array([0, 0, 59.00590434857581]) 

212 ), 

213 CVD_MATRICES_MACHADO2010["Tritanomaly"][1.0], 

214 atol=0.001, 

215 ) 

216 

217 

218class TestMatrixCvdMachado2009: 

219 """ 

220 Define :func:`colour.blindness.machado2009.matrix_cvd_Machado2009` 

221 definition unit tests methods. 

222 """ 

223 

224 def test_matrix_cvd_Machado2009(self) -> None: 

225 """ 

226 Test :func:`colour.blindness.machado2009.matrix_cvd_Machado2009` 

227 definition. 

228 """ 

229 

230 np.testing.assert_allclose( 

231 matrix_cvd_Machado2009("Protanomaly", 0.0), 

232 np.array( 

233 [ 

234 [1, 0, 0], 

235 [0, 1, 0], 

236 [0, 0, 1], 

237 ] 

238 ), 

239 atol=TOLERANCE_ABSOLUTE_TESTS, 

240 ) 

241 

242 np.testing.assert_allclose( 

243 matrix_cvd_Machado2009("Deuteranomaly", 0.1), 

244 np.array( 

245 [ 

246 [0.86643500, 0.17770400, -0.04413900], 

247 [0.04956700, 0.93906300, 0.01137000], 

248 [-0.00345300, 0.00723300, 0.99622000], 

249 ] 

250 ), 

251 atol=TOLERANCE_ABSOLUTE_TESTS, 

252 ) 

253 

254 np.testing.assert_allclose( 

255 matrix_cvd_Machado2009("Tritanomaly", 1.0), 

256 np.array( 

257 [ 

258 [1.25552800, -0.07674900, -0.17877900], 

259 [-0.07841100, 0.93080900, 0.14760200], 

260 [0.00473300, 0.69136700, 0.30390000], 

261 ] 

262 ), 

263 atol=TOLERANCE_ABSOLUTE_TESTS, 

264 ) 

265 

266 np.testing.assert_allclose( 

267 matrix_cvd_Machado2009("Tritanomaly", 0.55), 

268 np.array( 

269 [ 

270 [1.06088700, -0.01504350, -0.04584350], 

271 [-0.01895750, 0.96774750, 0.05121150], 

272 [0.00317700, 0.27513700, 0.72168600], 

273 ] 

274 ), 

275 atol=TOLERANCE_ABSOLUTE_TESTS, 

276 ) 

277 

278 @ignore_numpy_errors 

279 def test_nan_matrix_cvd_Machado2009(self) -> None: 

280 """ 

281 Test :func:`colour.blindness.machado2009.matrix_cvd_Machado2009` 

282 definition nan support. 

283 """ 

284 

285 for case in [-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]: 

286 matrix_cvd_Machado2009("Tritanomaly", case)