Coverage for plotting/tests/test_colorimetry.py: 100%

1"""Define the unit tests for the :mod:`colour.plotting.colorimetry` module."""

2

3 from __future__ import annotations

4

5 from matplotlib.axes import Axes

6 from matplotlib.figure import Figure

7

8 from colour.colorimetry import SpectralDistribution

9 from colour.plotting import (

10 plot_blackbody_colours,

11 plot_blackbody_spectral_radiance,

12 plot_multi_cmfs,

13 plot_multi_illuminant_sds,

14 plot_multi_lightness_functions,

15 plot_multi_luminance_functions,

16 plot_multi_sds,

17 plot_single_cmfs,

18 plot_single_illuminant_sd,

19 plot_single_lightness_function,

20 plot_single_luminance_function,

21 plot_single_sd,

22 plot_visible_spectrum,

23)

24

25 __author__ = "Colour Developers"

26 __copyright__ = "Copyright 2013 Colour Developers"

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

28 __maintainer__ = "Colour Developers"

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

30 __status__ = "Production"

31

32 __all__ = [

33 "TestPlotSingleSd",

34 "TestPlotMultiSds",

35 "TestPlotSingleCmfs",

36 "TestPlotMultiCmfs",

37 "TestPlotSingleIlluminantSd",

38 "TestPlotMultiIlluminantSds",

39 "TestPlotVisibleSpectrum",

40 "TestPlotSingleLightnessFunction",

41 "TestPlotMultiLightnessFunctions",

42 "TestPlotSingleLuminanceFunction",

43 "TestPlotMultiLuminanceFunctions",

44 "TestPlotBlackbodySpectralRadiance",

45 "TestPlotBlackbodyColours",

46]

47

48

49 class TestPlotSingleSd:

50 """

51 Define :func:`colour.plotting.colorimetry.plot_single_sd` definition unit

52 tests methods.

53 """

54

55 def test_plot_single_sd(self) -> None:

56 """Test :func:`colour.plotting.colorimetry.plot_single_sd` definition."""

57

58 sd = SpectralDistribution(

59 {

60 500: 0.004900,

61 510: 0.009300,

62 520: 0.063270,

63 530: 0.165500,

64 540: 0.290400,

65 550: 0.433450,

66 560: 0.594500,

67 },

68 name="Custom 1",

69 )

70

71 figure, axes = plot_single_sd(

72 sd,

73 out_of_gamut_clipping=False,

74 modulate_colours_with_sd_amplitude=True,

75 equalize_sd_amplitude=True,

76 )

77

78 assert isinstance(figure, Figure)

79 assert isinstance(axes, Axes)

80

81

82 class TestPlotMultiSds:

83 """

84 Define :func:`colour.plotting.colorimetry.plot_multi_sds` definition unit

85 tests methods.

86 """

87

88 def test_plot_multi_sds(self) -> None:

89 """Test :func:`colour.plotting.colorimetry.plot_multi_sds` definition."""

90

91 sd_1 = SpectralDistribution(

92 {

93 500: 0.004900,

94 510: 0.009300,

95 520: 0.063270,

96 530: 0.165500,

97 540: 0.290400,

98 550: 0.433450,

99 560: 0.594500,

100 },

101 name="Custom 1",

102 )

103 sd_2 = SpectralDistribution(

104 {

105 500: 0.323000,

106 510: 0.503000,

107 520: 0.710000,

108 530: 0.862000,

109 540: 0.954000,

110 550: 0.994950,

111 560: 0.995000,

112 },

113 name="Custom 2",

114 )

115

116 figure, axes = plot_multi_sds(

117 [sd_1, sd_2],

118 plot_kwargs={"use_sd_colours": True, "normalise_sd_colours": True},

119 )

120

121 assert isinstance(figure, Figure)

122 assert isinstance(axes, Axes)

123

124 figure, axes = plot_multi_sds(

125 [sd_1, sd_2],

126 plot_kwargs=[{"use_sd_colours": True, "normalise_sd_colours": True}] * 2,

127 )

128

129 assert isinstance(figure, Figure)

130 assert isinstance(axes, Axes)

131

132

133 class TestPlotSingleCmfs:

134 """

135 Define :func:`colour.plotting.colorimetry.plot_single_cmfs` definition

136 unit tests methods.

137 """

138

139 def test_plot_single_cmfs(self) -> None:

140 """Test :func:`colour.plotting.colorimetry.plot_single_cmfs` definition."""

141

142 figure, axes = plot_single_cmfs()

143

144 assert isinstance(figure, Figure)

145 assert isinstance(axes, Axes)

146

147

148 class TestPlotMultiCmfs:

149 """

150 Define :func:`colour.plotting.colorimetry.plot_multi_cmfs` definition unit

151 tests methods.

152 """

153

154 def test_plot_multi_cmfs(self) -> None:

155 """Test :func:`colour.plotting.colorimetry.plot_multi_cmfs` definition."""

156

157 figure, axes = plot_multi_cmfs(

158 [

159 "CIE 1931 2 Degree Standard Observer",

160 "CIE 1964 10 Degree Standard Observer",

161 ]

162 )

163

164 assert isinstance(figure, Figure)

165 assert isinstance(axes, Axes)

166

167

168 class TestPlotSingleIlluminantSd:

169 """

170 Define :func:`colour.plotting.colorimetry.plot_single_illuminant_sd`

171 definition unit tests methods.

172 """

173

174 def test_plot_single_illuminant_sd(self) -> None:

175 """

176 Test :func:`colour.plotting.colorimetry.plot_single_illuminant_sd`

177 definition.

178 """

179

180 figure, axes = plot_single_illuminant_sd("A")

181

182 assert isinstance(figure, Figure)

183 assert isinstance(axes, Axes)

184

185

186 class TestPlotMultiIlluminantSds:

187 """

188 Define :func:`colour.plotting.colorimetry.plot_multi_illuminant_sds`

189 definition unit tests methods.

190 """

191

192 def test_plot_multi_illuminant_sds(self) -> None:

193 """

194 Test :func:`colour.plotting.colorimetry.plot_multi_illuminant_sds`

195 definition.

196 """

197

198 figure, axes = plot_multi_illuminant_sds(["A", "B", "C"])

199

200 assert isinstance(figure, Figure)

201 assert isinstance(axes, Axes)

202

203 figure, axes = plot_multi_illuminant_sds(

204 ["A", "B", "C"],

205 plot_kwargs=[{"use_sd_colours": True, "normalise_sd_colours": True}] * 3,

206 )

207

208 assert isinstance(figure, Figure)

209 assert isinstance(axes, Axes)

210

211

212 class TestPlotVisibleSpectrum:

213 """

214 Define :func:`colour.plotting.colorimetry.plot_visible_spectrum`

215 definition unit tests methods.

216 """

217

218 def test_plot_visible_spectrum(self) -> None:

219 """

220 Test :func:`colour.plotting.colorimetry.plot_visible_spectrum`

221 definition.

222 """

223

224 figure, axes = plot_visible_spectrum()

225

226 assert isinstance(figure, Figure)

227 assert isinstance(axes, Axes)

228

229

230 class TestPlotSingleLightnessFunction:

231 """

232 Define :func:`colour.plotting.colorimetry.plot_single_lightness_function`

233 definition unit tests methods.

234 """

235

236 def test_plot_single_lightness_function(self) -> None:

237 """

238 Test :func:`colour.plotting.colorimetry.\

239 plot_single_lightness_function` definition.

240 """

241

242 figure, axes = plot_single_lightness_function("CIE 1976")

243

244 assert isinstance(figure, Figure)

245 assert isinstance(axes, Axes)

246

247

248 class TestPlotMultiLightnessFunctions:

249 """

250 Define :func:`colour.plotting.colorimetry.plot_multi_lightness_functions`

251 definition unit tests methods.

252 """

253

254 def test_plot_multi_lightness_functions(self) -> None:

255 """

256 Test :func:`colour.plotting.colorimetry.\

257 plot_multi_lightness_functions` definition.

258 """

259

260 figure, axes = plot_multi_lightness_functions(["CIE 1976", "Wyszecki 1963"])

261

262 assert isinstance(figure, Figure)

263 assert isinstance(axes, Axes)

264

265

266 class TestPlotSingleLuminanceFunction:

267 """

268 Define :func:`colour.plotting.colorimetry.plot_single_luminance_function`

269 definition unit tests methods.

270 """

271

272 def test_plot_single_luminance_function(self) -> None:

273 """

274 Test :func:`colour.plotting.colorimetry.\

275 plot_single_luminance_function` definition.

276 """

277

278 figure, axes = plot_single_luminance_function("CIE 1976")

279

280 assert isinstance(figure, Figure)

281 assert isinstance(axes, Axes)

282

283

284 class TestPlotMultiLuminanceFunctions:

285 """

286 Define :func:`colour.plotting.colorimetry.plot_multi_luminance_functions`

287 definition unit tests methods.

288 """

289

290 def test_plot_multi_luminance_functions(self) -> None:

291 """

292 Test :func:`colour.plotting.colorimetry.\

293 plot_multi_luminance_functions` definition.

294 """

295

296 figure, axes = plot_multi_luminance_functions(["CIE 1976", "Newhall 1943"])

297

298 assert isinstance(figure, Figure)

299 assert isinstance(axes, Axes)

300

301

302 class TestPlotBlackbodySpectralRadiance:

303 """

304 Define :func:`colour.plotting.colorimetry.\

305 plot_blackbody_spectral_radiance` definition unit tests methods.

306 """

307

308 def test_plot_blackbody_spectral_radiance(self) -> None:

309 """

310 Test :func:`colour.plotting.colorimetry.\

311 plot_blackbody_spectral_radiance` definition.

312 """

313

314 figure, axes = plot_blackbody_spectral_radiance()

315

316 assert isinstance(figure, Figure)

317 assert isinstance(axes, Axes)

318

319

320 class TestPlotBlackbodyColours:

321 """

322 Define :func:`colour.plotting.colorimetry.plot_blackbody_colours`

323 definition unit tests methods.

324 """

325

326 def test_plot_blackbody_colours(self) -> None:

327 """

328 Test :func:`colour.plotting.colorimetry.plot_blackbody_colours`

329 definition.

330 """

331

332 figure, axes = plot_blackbody_colours()

333

334 assert isinstance(figure, Figure)

335 assert isinstance(axes, Axes)