Skip to content

Instantly share code, notes, and snippets.

@Chandler
Last active November 27, 2016 03:21
Show Gist options
  • Save Chandler/ef617aafdb4a4700fecbbdfbc42e6222 to your computer and use it in GitHub Desktop.
Save Chandler/ef617aafdb4a4700fecbbdfbc42e6222 to your computer and use it in GitHub Desktop.
import numpy
# R() is the reflectance of an object at a given band
# E() is the energy of the illuminant at a given band
# x_cmf() is the sensitivitiy of the X primary at a given band
# numpy.trapz(x_values, y_values) cacluated the area under a curve
X_curve = []
Y_curve = []
Z_curve = []
K_curve = []
for band in bands: #380, 385, 390...760
X_curve.append(R(band) * E(band) * x_cmf(band))
Y_curve.append(R(band) * E(band) * y_cmf(band))
Z_curve.append(R(band) * E(band) * z_cmf(band))
# calculate the y curve of a perfectly reflective object
# this is the standard normalization constant.
K_curve.append(1 * E(band) * y_cmf(band))
# calculate the area of a perfectly reflective object
K = numpy.trapz(K_curve, bands)
# normalize the other areas by the area of the perfectly
# reflective object
X = numpy.trapz(X_curve, bands) * (100/K)
Y = numpy.trapz(Y_curve, bands) * (100/K)
Z = numpy.trapz(Z_curve, bands) * (100/K)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment