PAOFLOW.graphics.color#

Derive the perceived visible color of a material from its optical spectra.

This module turns a normal-incidence reflectivity spectrum R(E) (as written by PAOFLOW.response.do_epsilon.refractive_index() into refl_*.dat files) into an sRGB color, following the standard colorimetric pipeline:

R(lambda) x illuminant -> CIE XYZ tristimulus -> linear sRGB -> gamma sRGB.

The CIE 1931 2-deg color-matching functions are evaluated with the compact multi-lobe Gaussian analytic fit of Wyman, Sloan & Shirley, Simple Analytic Approximations to the CIE XYZ Color Matching Functions (JCGT, 2013), so no tabulated data files are required.

Functions#

cie_cmf(lam)

CIE 1931 2-deg color-matching functions x-bar, y-bar, z-bar.

illuminant_spd(lam[, illuminant])

Relative spectral power distribution of the chosen illuminant.

xyz_to_srgb(xyz)

Convert a CIE XYZ tristimulus triple to gamma-encoded sRGB in [0, 1].

reflectance_to_srgb(ene, refl[, illuminant])

Perceived sRGB color of an opaque material from its reflectivity.

visible_grid_covered(ene)

Return True if the energy grid spans the full visible range.

Module Contents#

PAOFLOW.graphics.color.cie_cmf(lam)[source]#

CIE 1931 2-deg color-matching functions x-bar, y-bar, z-bar.

Multi-lobe Gaussian analytic approximation (Wyman, Sloan & Shirley, 2013).

Parameters:

lam (ndarray) – Wavelength grid in nanometers.

Returns:

xbar, ybar, zbar – Color-matching function values on lam.

Return type:

ndarray

PAOFLOW.graphics.color.illuminant_spd(lam, illuminant='E')[source]#

Relative spectral power distribution of the chosen illuminant.

Parameters:
  • lam (ndarray) – Wavelength grid in nanometers.

  • illuminant ({'E', 'D65'} or float) – 'E' equal-energy (flat) illuminant – the material’s intrinsic color. 'D65' a 6504 K Planckian daylight approximation. A float is treated as a blackbody temperature in kelvin.

Returns:

Relative SPD on lam (arbitrary overall scale).

Return type:

ndarray

PAOFLOW.graphics.color.xyz_to_srgb(xyz)[source]#

Convert a CIE XYZ tristimulus triple to gamma-encoded sRGB in [0, 1].

Out-of-gamut negative components are clipped to zero before encoding.

PAOFLOW.graphics.color.reflectance_to_srgb(ene, refl, illuminant='E')[source]#

Perceived sRGB color of an opaque material from its reflectivity.

Parameters:
  • ene (array_like, shape (n,)) – Photon-energy grid in eV (monotonically increasing).

  • refl (array_like, shape (n,)) – Normal-incidence reflectivity on ene (values in [0, 1]).

  • illuminant ({'E', 'D65'} or float, optional) – Illuminant under which the color is observed (see illuminant_spd()). Default equal-energy 'E'.

Returns:

  • rgb01 (ndarray, shape (3,)) – Gamma-encoded sRGB components in [0, 1].

  • rgb255 (ndarray, shape (3,)) – 8-bit integer sRGB components in [0, 255].

  • hexstr (str) – Hex color string, e.g. '#rrggbb'.

Notes

The energy grid should span the visible range (about 1.59-3.26 eV, i.e. 380-780 nm). Reflectivity outside the supplied grid is held at the edge value; a truncated grid biases the color.

PAOFLOW.graphics.color.visible_grid_covered(ene)[source]#

Return True if the energy grid spans the full visible range.