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

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

2

3 from __future__ import annotations

4

5 import matplotlib.pyplot as plt

6 import numpy as np

7 from matplotlib.axes import Axes

8 from matplotlib.figure import Figure

9

10 from colour.plotting import (

11 plot_multi_layer_stack,

12 plot_multi_layer_thin_film,

13 plot_ray,

14 plot_single_layer_thin_film,

15 plot_single_sd_rayleigh_scattering,

16 plot_the_blue_sky,

17 plot_thin_film_comparison,

18 plot_thin_film_iridescence,

19 plot_thin_film_reflectance_map,

20 plot_thin_film_spectrum,

21)

22

23 __author__ = "Colour Developers"

24 __copyright__ = "Copyright 2013 Colour Developers"

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

26 __maintainer__ = "Colour Developers"

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

28 __status__ = "Production"

29

30 __all__ = [

31 "TestPlotSingleSdRayleighScattering",

32 "TestPlotTheBlueSky",

33 "TestPlotSingleLayerThinFilm",

34 "TestPlotMultiLayerThinFilm",

35 "TestPlotThinFilmComparison",

36 "TestPlotThinFilmSpectrum",

37 "TestPlotThinFilmIridescence",

38 "TestPlotThinFilmReflectanceMap",

39 "TestPlotMultiLayerStack",

40 "TestPlotRay",

41]

42

43

44 class TestPlotSingleSdRayleighScattering:

45 """

46 Define :func:`colour.plotting.phenomena.\

47 plot_single_sd_rayleigh_scattering` definition unit tests methods.

48 """

49

50 def test_plot_single_sd_rayleigh_scattering(self) -> None:

51 """

52 Test :func:`colour.plotting.phenomena.\

53 plot_single_sd_rayleigh_scattering` definition.

54 """

55

56 figure, axes = plot_single_sd_rayleigh_scattering()

57

58 assert isinstance(figure, Figure)

59 assert isinstance(axes, Axes)

60

61

62 class TestPlotTheBlueSky:

63 """

64 Define :func:`colour.plotting.phenomena.plot_the_blue_sky` definition unit

65 tests methods.

66 """

67

68 def test_plot_the_blue_sky(self) -> None:

69 """Test :func:`colour.plotting.phenomena.plot_the_blue_sky` definition."""

70

71 figure, axes = plot_the_blue_sky()

72

73 assert isinstance(figure, Figure)

74 assert isinstance(axes, Axes)

75

76

77 class TestPlotSingleLayerThinFilm:

78 """

79 Define :func:`colour.plotting.phenomena.plot_single_layer_thin_film`

80 definition unit tests methods.

81 """

82

83 def test_plot_single_layer_thin_film(self) -> None:

84 """

85 Test :func:`colour.plotting.phenomena.plot_single_layer_thin_film`

86 definition.

87 """

88

89 figure, axes = plot_single_layer_thin_film([1.0, 1.46, 1.5], 100)

90

91 assert isinstance(figure, Figure)

92 assert isinstance(axes, Axes)

93

94

95 class TestPlotMultiLayerThinFilm:

96 """

97 Define :func:`colour.plotting.phenomena.plot_multi_layer_thin_film`

98 definition unit tests methods.

99 """

100

101 def test_plot_multi_layer_thin_film(self) -> None:

102 """

103 Test :func:`colour.plotting.phenomena.plot_multi_layer_thin_film`

104 definition.

105 """

106

107 figure, axes = plot_multi_layer_thin_film([1.0, 1.46, 2.4, 1.5], [100, 50])

108

109 assert isinstance(figure, Figure)

110 assert isinstance(axes, Axes)

111

112 figure, axes = plot_multi_layer_thin_film(

113 [1.0, 1.46, 2.4, 1.5], [100, 50], method="Transmittance"

114 )

115 assert isinstance(figure, Figure)

116 assert isinstance(axes, Axes)

117

118 figure, axes = plot_multi_layer_thin_film(

119 [1.0, 1.46, 2.4, 1.5], [100, 50], method="Both"

120 )

121 assert isinstance(figure, Figure)

122 assert isinstance(axes, Axes)

123

124 figure, axes = plot_multi_layer_thin_film(

125 [1.0, 1.46, 2.4, 1.5], [100, 50], polarisation="S"

126 )

127 assert isinstance(figure, Figure)

128 assert isinstance(axes, Axes)

129

130 figure, axes = plot_multi_layer_thin_film(

131 [1.0, 1.46, 2.4, 1.5], [100, 50], polarisation="P"

132 )

133 assert isinstance(figure, Figure)

134 assert isinstance(axes, Axes)

135

136

137 class TestPlotThinFilmComparison:

138 """

139 Define :func:`colour.plotting.phenomena.plot_thin_film_comparison`

140 definition unit tests methods.

141 """

142

143 def test_plot_thin_film_comparison(self) -> None:

144 """

145 Test :func:`colour.plotting.phenomena.plot_thin_film_comparison`

146 definition.

147 """

148

149 configurations = [

150 {

151 "type": "single",

152 "n_film": 1.46,

153 "t": 100,

154 "n_substrate": 1.5,

155 "label": "MgF2 100nm",

156 },

157 {

158 "type": "single",

159 "n_film": 2.4,

160 "t": 25,

161 "n_substrate": 1.5,

162 "label": "TiO2 25nm",

163 },

164 ]

165

166 figure, axes = plot_thin_film_comparison(configurations)

167

168 assert isinstance(figure, Figure)

169 assert isinstance(axes, Axes)

170

171 configurations_multi = [

172 {

173 "type": "multilayer",

174 "refractive_indices": [1.46, 2.4],

175 "t": [100, 50],

176 "n_substrate": 1.5,

177 "label": "Multilayer",

178 },

179 ]

180

181 figure, axes = plot_thin_film_comparison(configurations_multi)

182

183 assert isinstance(figure, Figure)

184 assert isinstance(axes, Axes)

185

186

187 class TestPlotThinFilmSpectrum:

188 """

189 Define :func:`colour.plotting.phenomena.plot_thin_film_spectrum`

190 definition unit tests methods.

191 """

192

193 def test_plot_thin_film_spectrum(self) -> None:

194 """

195 Test :func:`colour.plotting.phenomena.plot_thin_film_spectrum`

196 definition.

197 """

198

199 figure, axes = plot_thin_film_spectrum([1.0, 1.33, 1.0], 200)

200

201 assert isinstance(figure, Figure)

202 assert isinstance(axes, Axes)

203

204

205 class TestPlotThinFilmIridescence:

206 """

207 Define :func:`colour.plotting.phenomena.plot_thin_film_iridescence`

208 definition unit tests methods.

209 """

210

211 def test_plot_thin_film_iridescence(self) -> None:

212 """

213 Test :func:`colour.plotting.phenomena.plot_thin_film_iridescence`

214 definition.

215 """

216

217 figure, axes = plot_thin_film_iridescence([1.0, 1.33, 1.0])

218

219 assert isinstance(figure, Figure)

220 assert isinstance(axes, Axes)

221

222

223 class TestPlotThinFilmReflectanceMap:

224 """

225 Define :func:`colour.plotting.phenomena.plot_thin_film_reflectance_map`

226 definition unit tests methods.

227 """

228

229 def test_plot_thin_film_reflectance_map(self) -> None:

230 """

231 Test :func:`colour.plotting.phenomena.plot_thin_film_reflectance_map`

232 definition.

233 """

234

235 figure, axes = plot_thin_film_reflectance_map(

236 [1.0, 1.33, 1.0], method="Thickness"

237 )

238

239 assert isinstance(figure, Figure)

240 assert isinstance(axes, Axes)

241

242 figure, axes = plot_thin_film_reflectance_map(

243 [1.0, 1.33, 1.0], method="Thickness", polarisation="S"

244 )

245

246 assert isinstance(figure, Figure)

247 assert isinstance(axes, Axes)

248

249 figure, axes = plot_thin_film_reflectance_map(

250 [1.0, 1.33, 1.0], method="Thickness", polarisation="P"

251 )

252

253 assert isinstance(figure, Figure)

254 assert isinstance(axes, Axes)

255

256 figure, axes = plot_thin_film_reflectance_map(

257 [1.0, 1.33, 1.0], method="Angle", t=300, theta=np.linspace(0, 80, 20)

258 )

259

260 assert isinstance(figure, Figure)

261 assert isinstance(axes, Axes)

262

263 figure, axes = plot_thin_film_reflectance_map(

264 [1.0, 1.33, 1.0],

265 method="Angle",

266 t=300,

267 theta=np.linspace(0, 80, 20),

268 polarisation="S",

269 )

270

271 assert isinstance(figure, Figure)

272 assert isinstance(axes, Axes)

273

274 figure, axes = plot_thin_film_reflectance_map(

275 [1.0, 1.33, 1.0],

276 method="Angle",

277 t=300,

278 theta=np.linspace(0, 80, 20),

279 polarisation="P",

280 )

281

282 assert isinstance(figure, Figure)

283 assert isinstance(axes, Axes)

284

285 figure, axes = plot_thin_film_reflectance_map(

286 [1.0, 1.46, 2.4, 1.5], method="Thickness", t=np.linspace(50, 500, 100)

287 )

288

289 assert isinstance(figure, Figure)

290 assert isinstance(axes, Axes)

291

292

293 class TestPlotMultiLayerStack:

294 """

295 Define :func:`colour.plotting.phenomena.plot_multi_layer_stack`

296 definition unit tests methods.

297 """

298

299 def test_plot_multi_layer_stack(self) -> None:

300 """

301 Test :func:`colour.plotting.phenomena.plot_multi_layer_stack`

302 definition.

303 """

304

305 configurations = [

306 {"t": 100, "n": 1.46},

307 {"t": 200, "n": 2.4},

308 {"t": 80, "n": 1.46},

309 {"t": 150, "n": 2.4},

310 ]

311

312 figure, axes = plot_multi_layer_stack(configurations, theta=45)

313

314 assert isinstance(figure, Figure)

315 assert isinstance(axes, Axes)

316

317

318 class TestPlotRay:

319 """

320 Define :func:`colour.plotting.common.plot_ray` definition unit tests methods.

321 """

322

323 def test_plot_ray(self) -> None:

324 """Test :func:`colour.plotting.common.plot_ray` definition."""

325

326 figure, axes = plt.subplots()

327 x = np.array([0, 1, 2])

328 y = np.array([0, 1, 0])

329

330 plot_ray(

331 axes, x, y, style="solid", label="Ray", show_arrow=True, show_dots=True

332 )

333

334 plt.close(figure)

335

336 # plot_ray returns None, so we just check it didn't raise an exception

337 assert True