summaryrefslogtreecommitdiff
path: root/color/chromaticity.py
diff options
context:
space:
mode:
authorAnthony LaTorre <tlatorre9@gmail.com>2011-06-18 00:12:09 -0400
committerAnthony LaTorre <tlatorre9@gmail.com>2011-06-18 00:12:09 -0400
commitab54917bceb4943f6750f589ffe6a032b2770fb1 (patch)
treee76ede76a1344820c424f2c07bc44ef22201864c /color/chromaticity.py
parent34ff4d6c734e5adf3aa8a0e7ca89031effdb1489 (diff)
downloadchroma-ab54917bceb4943f6750f589ffe6a032b2770fb1.tar.gz
chroma-ab54917bceb4943f6750f589ffe6a032b2770fb1.tar.bz2
chroma-ab54917bceb4943f6750f589ffe6a032b2770fb1.zip
moved class definitions for Solid, Mesh, Material, and Surface into geometry.py and moved instances of these classes into separate folders. the Solid object no longer contains a rotation, displacement, or id variable; instead, they are passed to a geometry object when calling add_solid().
Diffstat (limited to 'color/chromaticity.py')
-rw-r--r--color/chromaticity.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/color/chromaticity.py b/color/chromaticity.py
new file mode 100644
index 0000000..6229b51
--- /dev/null
+++ b/color/chromaticity.py
@@ -0,0 +1,34 @@
+import numpy as np
+
+f = open('sbrgb10w.csv')
+
+color_map = []
+for line in f:
+ color_map.append([float(s) for s in line.split(',')])
+
+f.close()
+
+color_map = np.array(color_map)
+
+# zero negative coefficients
+color_map[color_map < 0] = 0
+
+# normalize coefficients
+for i in range(len(color_map)):
+ color_map[i,1:] /= np.sum(color_map[i,1:])
+
+def map_wavelength(wavelength):
+ r = np.interp(wavelength, color_map[:,0], color_map[:,1])
+ g = np.interp(wavelength, color_map[:,0], color_map[:,2])
+ b = np.interp(wavelength, color_map[:,0], color_map[:,3])
+
+ if np.iterable(wavelength):
+ rgb = np.empty((len(wavelength),3))
+
+ rgb[:,0] = r
+ rgb[:,1] = g
+ rgb[:,2] = b
+
+ return rgb
+ else:
+ return np.array([r,g,b])