Coverage for temperature/__init__.py: 18%

1"""

2 References

3----------

4- :cite:`AdobeSystems2013` : Adobe Systems. (2013). Adobe DNG Software

5 Development Kit (SDK) - 1.3.0.0 -

6 dng_sdk_1_3/dng_sdk/source/dng_temperature.cpp::dng_temperature::\

7 Set_xy_coord. https://www.adobe.com/support/downloads/dng/dng_sdk.html

8- :cite:`CIETC1-482004i` : CIE TC 1-48. (2004). APPENDIX E. INFORMATION ON

9 THE USE OF PLANCK'S EQUATION FOR STANDARD AIR. In CIE 015:2004 Colorimetry,

10 3rd Edition (pp. 77-82). ISBN:978-3-901906-33-6

11- :cite:`Hernandez-Andres1999a` : Hernández-Andrés, J., Lee, R. L., &

12 Romero, J. (1999). Calculating correlated color temperatures across the

13 entire gamut of daylight and skylight chromaticities. Applied Optics,

14 38(27),

15 5703. doi:10.1364/AO.38.005703

16- :cite:`Kang2002a` : Kang, B., Moon, O., Hong, C., Lee, H., Cho, B., & Kim,

17 Y. (2002). Design of advanced color: Temperature control system for HDTV

18 applications. Journal of the Korean Physical Society, 41(6), 865-871.

19- :cite:`Krystek1985b` : Krystek, M. (1985). An algorithm to calculate

20 correlated colour temperature. Color Research & Application, 10(1), 38-40.

21 doi:10.1002/col.5080100109

22- :cite:`Ohno2014a` : Ohno, Yoshiro. (2014). Practical Use and Calculation of

23 CCT and Duv. LEUKOS, 10(1), 47-55. doi:10.1080/15502724.2014.839020

24- :cite:`Wikipedia2001` : Wikipedia. (2001). Approximation. Retrieved June

25 28, 2014, from http://en.wikipedia.org/wiki/Color_temperature#Approximation

26- :cite:`Wikipedia2001a` : Wikipedia. (2001). Color temperature. Retrieved

27 June 28, 2014, from http://en.wikipedia.org/wiki/Color_temperature

28- :cite:`Wyszecki2000y` : Wyszecki, Günther, & Stiles, W. S. (2000).

29 DISTRIBUTION TEMPERATURE, COLOR TEMPERATURE, AND CORRELATED COLOR

30 TEMPERATURE. In Color Science: Concepts and Methods, Quantitative Data and

31 Formulae (pp. 224-229). Wiley. ISBN:978-0-471-39918-6

32- :cite:`Wyszecki2000z` : Wyszecki, Günther, & Stiles, W. S. (2000). CIE

33 Method of Calculating D-Illuminants. In Color Science: Concepts and

34 Methods, Quantitative Data and Formulae (pp. 145-146). Wiley.

35 ISBN:978-0-471-39918-6

36"""

37

38 from __future__ import annotations

39

40 import typing

41

42 if typing.TYPE_CHECKING:

43 from colour.hints import Any, ArrayLike, NDArrayFloat, Literal

44

45 from colour.utilities import (

46 CanonicalMapping,

47 filter_kwargs,

48 validate_method,

49)

50

51 from .cie_d import CCT_to_xy_CIE_D, xy_to_CCT_CIE_D

52 from .hernandez1999 import CCT_to_xy_Hernandez1999, xy_to_CCT_Hernandez1999

53 from .kang2002 import CCT_to_xy_Kang2002, xy_to_CCT_Kang2002

54 from .krystek1985 import CCT_to_uv_Krystek1985, uv_to_CCT_Krystek1985

55 from .mccamy1992 import CCT_to_xy_McCamy1992, xy_to_CCT_McCamy1992

56 from .planck1900 import CCT_to_uv_Planck1900, uv_to_CCT_Planck1900

57

58# isort: split

59

60 from .ohno2013 import (

61 CCT_to_uv_Ohno2013,

62 CCT_to_XYZ_Ohno2013,

63 XYZ_to_CCT_Ohno2013,

64 uv_to_CCT_Ohno2013,

65)

66 from .robertson1968 import (

67 CCT_to_mired,

68 CCT_to_uv_Robertson1968,

69 mired_to_CCT,

70 uv_to_CCT_Robertson1968,

71)

72

73 __all__ = [

74 "CCT_to_xy_CIE_D",

75 "xy_to_CCT_CIE_D",

76]

77 __all__ += [

78 "CCT_to_xy_Hernandez1999",

79 "xy_to_CCT_Hernandez1999",

80]

81 __all__ += [

82 "CCT_to_xy_Kang2002",

83 "xy_to_CCT_Kang2002",

84]

85 __all__ += [

86 "CCT_to_uv_Krystek1985",

87 "uv_to_CCT_Krystek1985",

88]

89 __all__ += [

90 "CCT_to_xy_McCamy1992",

91 "xy_to_CCT_McCamy1992",

92]

93 __all__ += [

94 "CCT_to_uv_Planck1900",

95 "uv_to_CCT_Planck1900",

96]

97 __all__ += [

98 "CCT_to_uv_Ohno2013",

99 "CCT_to_XYZ_Ohno2013",

100 "XYZ_to_CCT_Ohno2013",

101 "uv_to_CCT_Ohno2013",

102]

103 __all__ += [

104 "CCT_to_mired",

105 "CCT_to_uv_Robertson1968",

106 "mired_to_CCT",

107 "uv_to_CCT_Robertson1968",

108]

109

110 UV_TO_CCT_METHODS: CanonicalMapping = CanonicalMapping(

111 {

112 "Krystek 1985": uv_to_CCT_Krystek1985,

113 "Ohno 2013": uv_to_CCT_Ohno2013,

114 "Planck 1900": uv_to_CCT_Planck1900,

115 "Robertson 1968": uv_to_CCT_Robertson1968,

116 }

117)

118 UV_TO_CCT_METHODS.__doc__ = """

119 Supported *CIE UCS* colourspace *uv* chromaticity coordinates to correlated

120 colour temperature :math:`T_{cp}` computation methods.

121

122 References

123----------

124:cite:`AdobeSystems2013`,

125:cite:`CIETC1-482004i`, :cite:`Krystek1985b`, :cite:`Ohno2014a`,

126:cite:`Wyszecki2000y`

127

128 Aliases:

129

130- 'ohno2013': 'Ohno 2013'

131- 'robertson1968': 'Robertson 1968'

132"""

133 UV_TO_CCT_METHODS["ohno2013"] = UV_TO_CCT_METHODS["Ohno 2013"]

134 UV_TO_CCT_METHODS["robertson1968"] = UV_TO_CCT_METHODS["Robertson 1968"]

135

136

137 def uv_to_CCT(

138 uv: ArrayLike,

139 method: (

140 Literal["Krystek 1985", "Ohno 2013", "Planck 1900", "Robertson 1968"] | str

141 ) = "Ohno 2013",

142 **kwargs: Any,

143) -> NDArrayFloat:

144 """

145 Compute the correlated colour temperature :math:`T_{cp}` and

146 :math:`\\Delta_{uv}` from the specified *CIE UCS* colourspace *uv*

147 chromaticity coordinates using the specified method.

148

149 Parameters

150 ----------

151 uv

152 *CIE UCS* colourspace *uv* chromaticity coordinates.

153 method

154 Computation method.

155

156 Other Parameters

157 ----------------

158 cmfs

159 {:func:`colour.temperature.uv_to_CCT_Ohno2013`,

160 :func:`colour.temperature.uv_to_CCT_Planck1900`},

161 Standard observer colour matching functions.

162 count

163 {:func:`colour.temperature.uv_to_CCT_Ohno2013`},

164 Temperatures count in the planckian tables.

165 end

166 {:func:`colour.temperature.uv_to_CCT_Ohno2013`},

167 Temperature range end in kelvins.

168 iterations

169 {:func:`colour.temperature.uv_to_CCT_Ohno2013`},

170 Number of planckian tables to generate.

171 optimisation_kwargs

172 {:func:`colour.temperature.uv_to_CCT_Krystek1985`},

173 Parameters for :func:`scipy.optimize.minimize` definition.

174 start

175 {:func:`colour.temperature.uv_to_CCT_Ohno2013`},

176 Temperature range start in kelvins.

177

178 Returns

179 -------

180 :class:`numpy.ndarray`

181 Correlated colour temperature :math:`T_{cp}`, :math:`\\Delta_{uv}`.

182

183 References

184 ----------

185 :cite:`AdobeSystems2013`,

186 :cite:`CIETC1-482004i`, :cite:`Krystek1985b`, :cite:`Ohno2014a`,

187 :cite:`Wyszecki2000y`

188

189 Examples

190 --------

191 >>> import numpy as np

192 >>> uv = np.array([0.1978, 0.3122])

193 >>> uv_to_CCT(uv) # doctest: +ELLIPSIS

194 array([ 6.5074747...e+03, 3.2233463...e-03])

195 """

196

197 method = validate_method(method, tuple(UV_TO_CCT_METHODS))

198

199 function = UV_TO_CCT_METHODS[method]

200

201 return function(uv, **filter_kwargs(function, **kwargs))

202

203

204 CCT_TO_UV_METHODS: CanonicalMapping = CanonicalMapping(

205 {

206 "Krystek 1985": CCT_to_uv_Krystek1985,

207 "Ohno 2013": CCT_to_uv_Ohno2013,

208 "Planck 1900": CCT_to_uv_Planck1900,

209 "Robertson 1968": CCT_to_uv_Robertson1968,

210 }

211)

212 CCT_TO_UV_METHODS.__doc__ = """

213 Supported correlated colour temperature :math:`T_{cp}` to *CIE UCS* colourspace

214*uv* chromaticity coordinates computation methods.

215

216 References

217----------

218:cite:`AdobeSystems2013`,

219:cite:`CIETC1-482004i`, :cite:`Krystek1985b`, :cite:`Ohno2014a`,

220:cite:`Wyszecki2000y`

221

222 Aliases:

223

224- 'ohno2013': 'Ohno 2013'

225- 'robertson1968': 'Robertson 1968'

226"""

227 CCT_TO_UV_METHODS["ohno2013"] = CCT_TO_UV_METHODS["Ohno 2013"]

228 CCT_TO_UV_METHODS["robertson1968"] = CCT_TO_UV_METHODS["Robertson 1968"]

229

230

231 def CCT_to_uv(

232 CCT_D_uv: ArrayLike,

233 method: (

234 Literal["Krystek 1985", "Ohno 2013", "Planck 1900", "Robertson 1968"] | str

235 ) = "Ohno 2013",

236 **kwargs: Any,

237) -> NDArrayFloat:

238 """

239 Compute the *CIE UCS* colourspace *uv* chromaticity coordinates from the

240 specified correlated colour temperature :math:`T_{cp}` and

241 :math:`\\Delta_{uv}` using the specified method.

242

243 Parameters

244 ----------

245 CCT_D_uv

246 Correlated colour temperature :math:`T_{cp}`, :math:`\\Delta_{uv}`.

247 method

248 Computation method.

249

250 Other Parameters

251 ----------------

252 cmfs

253 {:func:`colour.temperature.CCT_to_uv_Ohno2013`,

254 :func:`colour.temperature.CCT_to_uv_Planck1900`},

255 Standard observer colour matching functions.

256

257 Returns

258 -------

259 :class:`numpy.ndarray`

260 *CIE UCS* colourspace *uv* chromaticity coordinates.

261

262 References

263 ----------

264 :cite:`AdobeSystems2013`,

265 :cite:`CIETC1-482004i`, :cite:`Krystek1985b`, :cite:`Ohno2014a`,

266 :cite:`Wyszecki2000y`

267

268 Examples

269 --------

270 >>> import numpy as np

271 >>> CCT_D_uv = np.array([6507.47380460, 0.00322335])

272 >>> CCT_to_uv(CCT_D_uv) # doctest: +ELLIPSIS

273 array([ 0.1977999..., 0.3121999...])

274 """

275

276 method = validate_method(method, tuple(CCT_TO_UV_METHODS))

277

278 function = CCT_TO_UV_METHODS[method]

279

280 return function(CCT_D_uv, **filter_kwargs(function, **kwargs))

281

282

283 __all__ += [

284 "UV_TO_CCT_METHODS",

285 "uv_to_CCT",

286]

287 __all__ += [

288 "CCT_TO_UV_METHODS",

289 "CCT_to_uv",

290]

291

292 XY_TO_CCT_METHODS: CanonicalMapping = CanonicalMapping(

293 {

294 "CIE Illuminant D Series": xy_to_CCT_CIE_D,

295 "Hernandez 1999": xy_to_CCT_Hernandez1999,

296 "Kang 2002": xy_to_CCT_Kang2002,

297 "McCamy 1992": xy_to_CCT_McCamy1992,

298 }

299)

300 XY_TO_CCT_METHODS.__doc__ = """

301 Supported *CIE xy* chromaticity coordinates to correlated colour temperature

302:math:`T_{cp}` computation methods.

303

304 References

305----------

306:cite:`Hernandez-Andres1999a`, :cite:`Kang2002a`, :cite:`Wikipedia2001`,

307:cite:`Wikipedia2001a`, :cite:`Wyszecki2000z`

308

309 Aliases:

310

311- 'daylight': 'CIE Illuminant D Series'

312- 'kang2002': 'Kang 2002'

313- 'mccamy1992': 'McCamy 1992'

314- 'hernandez1999': 'Hernandez 1999'

315"""

316 XY_TO_CCT_METHODS["daylight"] = XY_TO_CCT_METHODS["CIE Illuminant D Series"]

317 XY_TO_CCT_METHODS["kang2002"] = XY_TO_CCT_METHODS["Kang 2002"]

318 XY_TO_CCT_METHODS["mccamy1992"] = XY_TO_CCT_METHODS["McCamy 1992"]

319 XY_TO_CCT_METHODS["hernandez1999"] = XY_TO_CCT_METHODS["Hernandez 1999"]

320

321

322 def xy_to_CCT(

323 xy: ArrayLike,

324 method: (

325 Literal[

326 "CIE Illuminant D Series",

327 "Kang 2002",

328 "Hernandez 1999",

329 "McCamy 1992",

330 ]

331 | str

332 ) = "CIE Illuminant D Series",

333) -> NDArrayFloat:

334 """

335 Compute the correlated colour temperature :math:`T_{cp}` from the

336 specified *CIE xy* chromaticity coordinates using the specified method.

337

338 Parameters

339 ----------

340 xy

341 *CIE xy* chromaticity coordinates.

342 method

343 Computation method.

344

345 Other Parameters

346 ----------------

347 optimisation_kwargs

348 {:func:`colour.temperature.xy_to_CCT_CIE_D`,

349 :func:`colour.temperature.xy_to_CCT_Kang2002`},

350 Parameters for :func:`scipy.optimize.minimize` definition.

351

352 Returns

353 -------

354 :class:`numpy.ndarray`

355 Correlated colour temperature :math:`T_{cp}`.

356

357 References

358 ----------

359 :cite:`Hernandez-Andres1999a`, :cite:`Kang2002a`, :cite:`Wikipedia2001`,

360 :cite:`Wikipedia2001a`, :cite:`Wyszecki2000z`

361

362 Examples

363 --------

364 >>> import numpy as np

365 >>> xy_to_CCT(np.array([0.31270, 0.32900])) # doctest: +ELLIPSIS

366 6508.1175148...

367 >>> xy_to_CCT(np.array([0.31270, 0.32900]), "Hernandez 1999")

368 ... # doctest: +ELLIPSIS

369 6500.7420431...

370 """

371

372 method = validate_method(method, tuple(XY_TO_CCT_METHODS))

373

374 return XY_TO_CCT_METHODS[method](xy)

375

376

377 CCT_TO_XY_METHODS: CanonicalMapping = CanonicalMapping(

378 {

379 "CIE Illuminant D Series": CCT_to_xy_CIE_D,

380 "Hernandez 1999": CCT_to_xy_Hernandez1999,

381 "Kang 2002": CCT_to_xy_Kang2002,

382 "McCamy 1992": CCT_to_xy_McCamy1992,

383 }

384)

385 CCT_TO_XY_METHODS.__doc__ = """

386 Supported correlated colour temperature :math:`T_{cp}` to *CIE xy* chromaticity

387 coordinates computation methods.

388

389 References

390----------

391:cite:`Hernandez-Andres1999a`, :cite:`Kang2002a`, :cite:`Wikipedia2001`,

392:cite:`Wikipedia2001a`, :cite:`Wyszecki2000z`

393

394 Aliases:

395

396- 'daylight': 'CIE Illuminant D Series'

397- 'kang2002': 'Kang 2002'

398- 'mccamy1992': 'McCamy 1992'

399- 'hernandez1999': 'Hernandez 1999'

400"""

401 CCT_TO_XY_METHODS["daylight"] = CCT_TO_XY_METHODS["CIE Illuminant D Series"]

402 CCT_TO_XY_METHODS["kang2002"] = CCT_TO_XY_METHODS["Kang 2002"]

403 CCT_TO_XY_METHODS["mccamy1992"] = CCT_TO_XY_METHODS["McCamy 1992"]

404 CCT_TO_XY_METHODS["hernandez1999"] = CCT_TO_XY_METHODS["Hernandez 1999"]

405

406

407 def CCT_to_xy(

408 CCT: ArrayLike,

409 method: (

410 Literal[

411 "CIE Illuminant D Series",

412 "Kang 2002",

413 "Hernandez 1999",

414 "McCamy 1992",

415 ]

416 | str

417 ) = "CIE Illuminant D Series",

418) -> NDArrayFloat:

419 """

420 Compute the *CIE xy* chromaticity coordinates from the specified

421 correlated colour temperature :math:`T_{cp}` using the specified method.

422

423 Parameters

424 ----------

425 CCT

426 Correlated colour temperature :math:`T_{cp}`.

427 method

428 Computation method.

429

430 Other Parameters

431 ----------------

432 optimisation_kwargs

433 {:func:`colour.temperature.CCT_to_xy_Hernandez1999`,

434 :func:`colour.temperature.CCT_to_xy_McCamy1992`},

435 Parameters for :func:`scipy.optimize.minimize` definition.

436

437 Returns

438 -------

439 :class:`numpy.ndarray`

440 *CIE xy* chromaticity coordinates.

441

442 References

443 ----------

444 :cite:`Hernandez-Andres1999a`, :cite:`Kang2002a`, :cite:`Wikipedia2001`,

445 :cite:`Wikipedia2001a`, :cite:`Wyszecki2000z`

446

447 Examples

448 --------

449 >>> CCT_to_xy(6504.38938305) # doctest: +ELLIPSIS

450 array([ 0.3127077..., 0.3291128...])

451 >>> CCT_to_xy(6504.38938305, "Kang 2002")

452 ... # doctest: +ELLIPSIS

453 array([ 0.313426 ..., 0.3235959...])

454 """

455

456 method = validate_method(method, tuple(CCT_TO_XY_METHODS))

457

458 return CCT_TO_XY_METHODS[method](CCT)

459

460

461 __all__ += [

462 "XY_TO_CCT_METHODS",

463 "xy_to_CCT",

464]

465 __all__ += [

466 "CCT_TO_XY_METHODS",

467 "CCT_to_xy",

468]