def spectrum_to_XYZ_emissive(spectrum_dict, cmf='1931_2deg'):
''' Converts a reflective or transmissive spectrum to XYZ coordinates.
Args:
spectrum_dict (`dict`): dictionary with wvl, values keys. Wvl in units of nm.
cmf (`str`): which color matching function to use, defaults to
CIE 1931 2 degree observer.
Returns:
`tuple` containing:
`float`: X
`float`: Y
`float`: Z
'''
wvl, values = spectrum_dict['wvl'], spectrum_dict['values']
cmf = get_cmf(cmf)
wvl_cmf = cmf['wvl']
try:
can_be_direct = np.allclose(wvl_cmf, wvl)
except ValueError as e:
can_be_direct = False
if not can_be_direct:
dat_interpf = interp1d(wvl, values, kind='linear', bounds_error=False, fill_value=0, assume_sorted=True)
values = dat_interpf(wvl_cmf)
dw = wvl_cmf[1] - wvl_cmf[0]
k = 100 / (values * cmf['Y']).sum(axis=0) / dw
X = k * (values * cmf['X']).sum(axis=0)
Y = k * (values * cmf['Y']).sum(axis=0)
Z = k * (values * cmf['Z']).sum(axis=0)
return X, Y, Z
评论列表
文章目录