summaryrefslogtreecommitdiff
path: root/firmware
diff options
context:
space:
mode:
authorjaseg <git@jaseg.net>2018-05-05 23:22:28 +0200
committerjaseg <git@jaseg.net>2018-05-05 23:22:28 +0200
commit9b7475f8c002a666b6bed4093d277b8141f8d3b5 (patch)
tree1f09f9fdd7cb1ee10a2200d4cfda8a33591ca743 /firmware
parentaf0e5cabbc4a841f412ae5a20de87d028c6f53b8 (diff)
downloadolsndot-9b7475f8c002a666b6bed4093d277b8141f8d3b5.tar.gz
olsndot-9b7475f8c002a666b6bed4093d277b8141f8d3b5.tar.bz2
olsndot-9b7475f8c002a666b6bed4093d277b8141f8d3b5.zip
Added LED setpoint calculation
Diffstat (limited to 'firmware')
-rw-r--r--firmware/Spectrum Measurement.ipynb95
-rw-r--r--firmware/cie_xyz_1931.csv95
-rw-r--r--firmware/cie_xyz_judd_1951.csv41
-rw-r--r--firmware/cie_xyz_judd_vos_1978.csv90
4 files changed, 318 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": {
diff --git a/firmware/cie_xyz_1931.csv b/firmware/cie_xyz_1931.csv
new file mode 100644
index 0000000..5f2c229
--- /dev/null
+++ b/firmware/cie_xyz_1931.csv
@@ -0,0 +1,95 @@
+360,0.000129900000,0.000003917000,0.000606100000
+365,0.000232100000,0.000006965000,0.001086000000
+370,0.000414900000,0.000012390000,0.001946000000
+375,0.000741600000,0.000022020000,0.003486000000
+380,0.001368000000,0.000039000000,0.006450001000
+385,0.002236000000,0.000064000000,0.010549990000
+390,0.004243000000,0.000120000000,0.020050010000
+395,0.007650000000,0.000217000000,0.036210000000
+400,0.014310000000,0.000396000000,0.067850010000
+405,0.023190000000,0.000640000000,0.110200000000
+410,0.043510000000,0.001210000000,0.207400000000
+415,0.077630000000,0.002180000000,0.371300000000
+420,0.134380000000,0.004000000000,0.645600000000
+425,0.214770000000,0.007300000000,1.039050100000
+430,0.283900000000,0.011600000000,1.385600000000
+435,0.328500000000,0.016840000000,1.622960000000
+440,0.348280000000,0.023000000000,1.747060000000
+445,0.348060000000,0.029800000000,1.782600000000
+450,0.336200000000,0.038000000000,1.772110000000
+455,0.318700000000,0.048000000000,1.744100000000
+460,0.290800000000,0.060000000000,1.669200000000
+465,0.251100000000,0.073900000000,1.528100000000
+470,0.195360000000,0.090980000000,1.287640000000
+475,0.142100000000,0.112600000000,1.041900000000
+480,0.095640000000,0.139020000000,0.812950100000
+485,0.057950010000,0.169300000000,0.616200000000
+490,0.032010000000,0.208020000000,0.465180000000
+495,0.014700000000,0.258600000000,0.353300000000
+500,0.004900000000,0.323000000000,0.272000000000
+505,0.002400000000,0.407300000000,0.212300000000
+510,0.009300000000,0.503000000000,0.158200000000
+515,0.029100000000,0.608200000000,0.111700000000
+520,0.063270000000,0.710000000000,0.078249990000
+525,0.109600000000,0.793200000000,0.057250010000
+530,0.165500000000,0.862000000000,0.042160000000
+535,0.225749900000,0.914850100000,0.029840000000
+540,0.290400000000,0.954000000000,0.020300000000
+545,0.359700000000,0.980300000000,0.013400000000
+550,0.433449900000,0.994950100000,0.008749999000
+555,0.512050100000,1.000000000000,0.005749999000
+560,0.594500000000,0.995000000000,0.003900000000
+565,0.678400000000,0.978600000000,0.002749999000
+570,0.762100000000,0.952000000000,0.002100000000
+575,0.842500000000,0.915400000000,0.001800000000
+580,0.916300000000,0.870000000000,0.001650001000
+585,0.978600000000,0.816300000000,0.001400000000
+590,1.026300000000,0.757000000000,0.001100000000
+595,1.056700000000,0.694900000000,0.001000000000
+600,1.062200000000,0.631000000000,0.000800000000
+605,1.045600000000,0.566800000000,0.000600000000
+610,1.002600000000,0.503000000000,0.000340000000
+615,0.938400000000,0.441200000000,0.000240000000
+620,0.854449900000,0.381000000000,0.000190000000
+625,0.751400000000,0.321000000000,0.000100000000
+630,0.642400000000,0.265000000000,0.000049999990
+635,0.541900000000,0.217000000000,0.000030000000
+640,0.447900000000,0.175000000000,0.000020000000
+645,0.360800000000,0.138200000000,0.000010000000
+650,0.283500000000,0.107000000000,0.000000000000
+655,0.218700000000,0.081600000000,0.000000000000
+660,0.164900000000,0.061000000000,0.000000000000
+665,0.121200000000,0.044580000000,0.000000000000
+670,0.087400000000,0.032000000000,0.000000000000
+675,0.063600000000,0.023200000000,0.000000000000
+680,0.046770000000,0.017000000000,0.000000000000
+685,0.032900000000,0.011920000000,0.000000000000
+690,0.022700000000,0.008210000000,0.000000000000
+695,0.015840000000,0.005723000000,0.000000000000
+700,0.011359160000,0.004102000000,0.000000000000
+705,0.008110916000,0.002929000000,0.000000000000
+710,0.005790346000,0.002091000000,0.000000000000
+715,0.004109457000,0.001484000000,0.000000000000
+720,0.002899327000,0.001047000000,0.000000000000
+725,0.002049190000,0.000740000000,0.000000000000
+730,0.001439971000,0.000520000000,0.000000000000
+735,0.000999949300,0.000361100000,0.000000000000
+740,0.000690078600,0.000249200000,0.000000000000
+745,0.000476021300,0.000171900000,0.000000000000
+750,0.000332301100,0.000120000000,0.000000000000
+755,0.000234826100,0.000084800000,0.000000000000
+760,0.000166150500,0.000060000000,0.000000000000
+765,0.000117413000,0.000042400000,0.000000000000
+770,0.000083075270,0.000030000000,0.000000000000
+775,0.000058706520,0.000021200000,0.000000000000
+780,0.000041509940,0.000014990000,0.000000000000
+785,0.000029353260,0.000010600000,0.000000000000
+790,0.000020673830,0.000007465700,0.000000000000
+795,0.000014559770,0.000005257800,0.000000000000
+800,0.000010253980,0.000003702900,0.000000000000
+805,0.000007221456,0.000002607800,0.000000000000
+810,0.000005085868,0.000001836600,0.000000000000
+815,0.000003581652,0.000001293400,0.000000000000
+820,0.000002522525,0.000000910930,0.000000000000
+825,0.000001776509,0.000000641530,0.000000000000
+830,0.000001251141,0.000000451810,0.000000000000 \ No newline at end of file
diff --git a/firmware/cie_xyz_judd_1951.csv b/firmware/cie_xyz_judd_1951.csv
new file mode 100644
index 0000000..288ec18
--- /dev/null
+++ b/firmware/cie_xyz_judd_1951.csv
@@ -0,0 +1,41 @@
+370,0.0008,0.0001,0.0046
+380,0.0045,0.0004,0.0224
+390,0.0201,0.0015,0.0925
+400,0.0611,0.0045,0.2799
+410,0.1267,0.0093,0.5835
+420,0.2285,0.0175,1.0622
+430,0.3081,0.0273,1.4526
+440,0.3312,0.0379,1.6064
+450,0.2888,0.0468,1.4717
+460,0.2323,0.0600,1.2880
+470,0.1745,0.0910,1.1133
+480,0.0920,0.1390,0.7552
+490,0.0318,0.2080,0.4461
+500,0.0048,0.3230,0.2644
+510,0.0093,0.5030,0.1541
+520,0.0636,0.7100,0.0763
+530,0.1668,0.8620,0.0412
+540,0.2926,0.9540,0.0200
+550,0.4364,0.9950,0.0088
+560,0.5970,0.9950,0.0039
+570,0.7642,0.9520,0.0020
+580,0.9159,0.8700,0.0016
+590,1.0225,0.7570,0.0011
+600,1.0544,0.6310,0.0007
+610,0.9922,0.5030,0.0003
+620,0.8432,0.3810,0.0002
+630,0.6327,0.2650,0.0001
+640,0.4404,0.1750,0.0000
+650,0.2787,0.1070,0.0000
+660,0.1619,0.0610,0.0000
+670,0.0858,0.0320,0.0000
+680,0.0459,0.0170,0.0000
+690,0.0222,0.0082,0.0000
+700,0.0113,0.0041,0.0000
+710,0.0057,0.0021,0.0000
+720,0.0028,0.0011,0.0000
+730,0.0015,0.0005,0.0000
+740,0.0005,0.0002,0.0000
+750,0.0003,0.0001,0.0000
+760,0.0002,0.0001,0.0000
+770,0.0001,0.0000,0.0000 \ No newline at end of file
diff --git a/firmware/cie_xyz_judd_vos_1978.csv b/firmware/cie_xyz_judd_vos_1978.csv
new file mode 100644
index 0000000..8ab7bc0
--- /dev/null
+++ b/firmware/cie_xyz_judd_vos_1978.csv
@@ -0,0 +1,90 @@
+380,2.689900e-003,2.000000e-004,1.226000e-002
+385,5.310500e-003,3.955600e-004,2.422200e-002
+390,1.078100e-002,8.000000e-004,4.925000e-002
+395,2.079200e-002,1.545700e-003,9.513500e-002
+400,3.798100e-002,2.800000e-003,1.740900e-001
+405,6.315700e-002,4.656200e-003,2.901300e-001
+410,9.994100e-002,7.400000e-003,4.605300e-001
+415,1.582400e-001,1.177900e-002,7.316600e-001
+420,2.294800e-001,1.750000e-002,1.065800e+000
+425,2.810800e-001,2.267800e-002,1.314600e+000
+430,3.109500e-001,2.730000e-002,1.467200e+000
+435,3.307200e-001,3.258400e-002,1.579600e+000
+440,3.333600e-001,3.790000e-002,1.616600e+000
+445,3.167200e-001,4.239100e-002,1.568200e+000
+450,2.888200e-001,4.680000e-002,1.471700e+000
+455,2.596900e-001,5.212200e-002,1.374000e+000
+460,2.327600e-001,6.000000e-002,1.291700e+000
+465,2.099900e-001,7.294200e-002,1.235600e+000
+470,1.747600e-001,9.098000e-002,1.113800e+000
+475,1.328700e-001,1.128400e-001,9.422000e-001
+480,9.194400e-002,1.390200e-001,7.559600e-001
+485,5.698500e-002,1.698700e-001,5.864000e-001
+490,3.173100e-002,2.080200e-001,4.466900e-001
+495,1.461300e-002,2.580800e-001,3.411600e-001
+500,4.849100e-003,3.230000e-001,2.643700e-001
+505,2.321500e-003,4.054000e-001,2.059400e-001
+510,9.289900e-003,5.030000e-001,1.544500e-001
+515,2.927800e-002,6.081100e-001,1.091800e-001
+520,6.379100e-002,7.100000e-001,7.658500e-002
+525,1.108100e-001,7.951000e-001,5.622700e-002
+530,1.669200e-001,8.620000e-001,4.136600e-002
+535,2.276800e-001,9.150500e-001,2.935300e-002
+540,2.926900e-001,9.540000e-001,2.004200e-002
+545,3.622500e-001,9.800400e-001,1.331200e-002
+550,4.363500e-001,9.949500e-001,8.782300e-003
+555,5.151300e-001,1.000100e+000,5.857300e-003
+560,5.974800e-001,9.950000e-001,4.049300e-003
+565,6.812100e-001,9.787500e-001,2.921700e-003
+570,7.642500e-001,9.520000e-001,2.277100e-003
+575,8.439400e-001,9.155800e-001,1.970600e-003
+580,9.163500e-001,8.700000e-001,1.806600e-003
+585,9.770300e-001,8.162300e-001,1.544900e-003
+590,1.023000e+000,7.570000e-001,1.234800e-003
+595,1.051300e+000,6.948300e-001,1.117700e-003
+600,1.055000e+000,6.310000e-001,9.056400e-004
+605,1.036200e+000,5.665400e-001,6.946700e-004
+610,9.923900e-001,5.030000e-001,4.288500e-004
+615,9.286100e-001,4.417200e-001,3.181700e-004
+620,8.434600e-001,3.810000e-001,2.559800e-004
+625,7.398300e-001,3.205200e-001,1.567900e-004
+630,6.328900e-001,2.650000e-001,9.769400e-005
+635,5.335100e-001,2.170200e-001,6.894400e-005
+640,4.406200e-001,1.750000e-001,5.116500e-005
+645,3.545300e-001,1.381200e-001,3.601600e-005
+650,2.786200e-001,1.070000e-001,2.423800e-005
+655,2.148500e-001,8.165200e-002,1.691500e-005
+660,1.616100e-001,6.100000e-002,1.190600e-005
+665,1.182000e-001,4.432700e-002,8.148900e-006
+670,8.575300e-002,3.200000e-002,5.600600e-006
+675,6.307700e-002,2.345400e-002,3.954400e-006
+680,4.583400e-002,1.700000e-002,2.791200e-006
+685,3.205700e-002,1.187200e-002,1.917600e-006
+690,2.218700e-002,8.210000e-003,1.313500e-006
+695,1.561200e-002,5.772300e-003,9.151900e-007
+700,1.109800e-002,4.102000e-003,6.476700e-007
+705,7.923300e-003,2.929100e-003,4.635200e-007
+710,5.653100e-003,2.091000e-003,3.330400e-007
+715,4.003900e-003,1.482200e-003,2.382300e-007
+720,2.825300e-003,1.047000e-003,1.702600e-007
+725,1.994700e-003,7.401500e-004,1.220700e-007
+730,1.399400e-003,5.200000e-004,8.710700e-008
+735,9.698000e-004,3.609300e-004,6.145500e-008
+740,6.684700e-004,2.492000e-004,4.316200e-008
+745,4.614100e-004,1.723100e-004,3.037900e-008
+750,3.207300e-004,1.200000e-004,2.155400e-008
+755,2.257300e-004,8.462000e-005,1.549300e-008
+760,1.597300e-004,6.000000e-005,1.120400e-008
+765,1.127500e-004,4.244600e-005,8.087300e-009
+770,7.951300e-005,3.000000e-005,5.834000e-009
+775,5.608700e-005,2.121000e-005,4.211000e-009
+780,3.954100e-005,1.498900e-005,3.038300e-009
+785,2.785200e-005,1.058400e-005,2.190700e-009
+790,1.959700e-005,7.465600e-006,1.577800e-009
+795,1.377000e-005,5.259200e-006,1.134800e-009
+800,9.670000e-006,3.702800e-006,8.156500e-010
+805,6.791800e-006,2.607600e-006,5.862600e-010
+810,4.770600e-006,1.836500e-006,4.213800e-010
+815,3.355000e-006,1.295000e-006,3.031900e-010
+820,2.353400e-006,9.109200e-007,2.175300e-010
+825,1.637700e-006,6.356400e-007,1.547600e-010 \ No newline at end of file