summaryrefslogtreecommitdiff
path: root/firmware/Spectrum Measurement.ipynb
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/Spectrum Measurement.ipynb')
-rw-r--r--firmware/Spectrum Measurement.ipynb95
1 files changed, 92 insertions, 3 deletions
diff --git a/firmware/Spectrum Measurement.ipynb b/firmware/Spectrum Measurement.ipynb
index 6d904c3..c77709a 100644
--- a/firmware/Spectrum Measurement.ipynb
+++ b/firmware/Spectrum Measurement.ipynb
@@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
- "execution_count": 1,
+ "execution_count": 277,
"metadata": {
"collapsed": false
},
@@ -13,6 +13,7 @@
"from IPython import display\n",
"from datetime import datetime\n",
"import scipy.interpolate as inter\n",
+ "from scipy import integrate\n",
"\n",
"import numpy as np\n",
"from matplotlib import pyplot as plt\n",
@@ -6652,12 +6653,100 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 271,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [],
+ "source": [
+ "# CIE XYZ Color matching functions\n",
+ "# rows are: λ[nm], x, y, z\n",
+ "CMFs = { fn[:-4]: np.genfromtxt(fn, delimiter=',')\n",
+ " for fn in ['cie_xyz_1931.csv', 'cie_xyz_judd_1951.csv', 'cie_xyz_judd_vos_1978.csv'] }\n",
+ "CMFs = { name: np.hstack([inter.interp1d(d[:,0], d[:,i]) for i in range(1,4)])\n",
+ " for name, d in CMFs.items() }"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 285,
"metadata": {
"collapsed": true
},
"outputs": [],
- "source": []
+ "source": [
+ "def integrate_tristimulus_response(data, colorspace='cie_xyz_1931'):\n",
+ " a = np.array([[\n",
+ " integrate.simps(\n",
+ " np.multiply(CMFs[colorspace][j](data[i][0]), data[i][1]),\n",
+ " data[i][0])\n",
+ " for j in range(3) ]\n",
+ " for i in range(len(data)) ])\n",
+ " # normalize by largest component\n",
+ " return a / np.max(np.sum(a, axis=0))"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 289,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "array([[ 3.46142003e-01, 1.73335974e-01, -7.18827590e-05],\n",
+ " [ 9.01721797e-02, 1.69512416e-01, 2.15830281e-02],\n",
+ " [ 1.75128165e-01, 2.49230694e-01, 9.78488855e-01]])"
+ ]
+ },
+ "execution_count": 289,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "tristimulus_data = integrate_tristimulus_response(data_rgb)\n",
+ "tristimulus_data"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 330,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [],
+ "source": [
+ "def led_setpoint_from_xyz(x, y, z):\n",
+ " # returns [r, g, b] array.\n",
+ " # Note that many xyz tristimulus values cannot be produced because one component is outside [0, 1]\n",
+ " #return np.linalg.solve(tristimulus_data.T, np.array([x, y, z]))\n",
+ " return np.dot(np.linalg.inv(tristimulus_data.T), np.array([x, y, z]))"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 332,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "array([ 0.72869072, 0.1386238 , 0.20139265])"
+ ]
+ },
+ "execution_count": 332,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "led_setpoint_from_xyz(0.3, 0.2, 0.2)"
+ ]
}
],
"metadata": {