CoralspeQ | Calibrate for Reflectance Spectra - SK


Pick a spectrum measured against black electrical tape and one against Whatman paper, check for saturation and save it back to the CoralspeQ device.
//============================================
// Macro for data evaluation on PhotosynQ.org
// created: 4/20/2016
//============================================

//Define the output object here
var output = {};

// Number of pixel per spectrum
var pixels = 256;

// Number of spectra collected
var specNum = 6;

// Integration times
var intTimes = [25,50,100,25,50,100];

// Split the rawtrace up into separate spectra
var spectra = [];
for (i=0,j=json.data_raw.length; i<j; i+=pixels) {
    spectra.push(json.data_raw.slice(i,i+pixels));   
}

if(spectra.length != specNum)
	danger('Insufficent number of spectra collected!',output);

//Spectrum to determine black
var SpectrumForBlack = 2;

//Spectrum to determine white
var SpectrumForWhite = 5;

// Pick a non saturated spectrum for black
if(MathMAX(spectra[SpectrumForBlack]) > 40000)
	SpectrumForBlack = 1;

if(MathMAX(spectra[SpectrumForBlack]) > 40000)
	SpectrumForBlack = 0;

// Pick a non saturated spectrum for white
if(MathMAX(spectra[SpectrumForWhite]) > 40000)
	SpectrumForWhite = 4;

if(MathMAX(spectra[SpectrumForWhite]) > 40000)
	SpectrumForWhite = 3;


output.black = SpectrumForBlack +1;
output.white = SpectrumForWhite +1;

// Correct for the integration times
var ReferenceSpectraBlack = [];
var ReferenceSpectraWhite = [];

for(i=0;i<pixels;i++){
	ReferenceSpectraBlack.push(spectra[SpectrumForBlack][i]);
}


for(i=0;i<pixels;i++){
	ReferenceSpectraWhite.push(spectra[SpectrumForWhite][i]);
}

// Output an array with the reference spectra getting saved
// to the device
if(ReferenceSpectraBlack.length != pixels)
	danger('Merged spectra have the wrong number of values',output);

if(ReferenceSpectraWhite.length != pixels)
	danger('Merged spectra have the wrong number of values',output);

output.intTimeBlack = intTimes[SpectrumForBlack];
output.intTimeWhite = intTimes[SpectrumForWhite];

output.toDevice = '["1078+';
output.toDevice += ReferenceSpectraBlack.join('+') + '+",';
output.toDevice += '"1079+';
output.toDevice += ReferenceSpectraWhite.join('+') + '+",';
output.toDevice += '"1020+';
output.toDevice += intTimes[SpectrumForBlack] + '+' + intTimes[SpectrumForWhite] + '+"]';

//Return data
return output;
{
  "time_offset": 240,
  "time": 1462387476368,
  "device_id": 145,
  "firmware_version": "0.457",
  "sample": [
    [
      {
        "time": 1462387476375,
        "protocol_id": 1,
        "light_intensity": 0,
        "r": 0,
        "g": 0,
        "b": 0,
        "message": [
          [
            "alert",
            "Hold CoralspeQ against black electrical tape",
            "ok"
          ],
          [
            "0",
            "0",
            ""
          ],
          [
            "0",
            "0",
            ""
          ],
          [
            "0",
            "0",
            ""
          ],
          [
            "0",
            "0",
            ""
          ],
          [
            "0",
            "0",
            ""
          ],
          [
            "0",
            "0",
            ""
          ],
          [
            "alert",
            "Hold CoralspeQ against white Whatman Paper",
            "ok"
          ],
          [
            "0",
            "0",
            ""
          ],
          [
            "0",
            "0",
            ""
          ],
          [
            "0",
            "0",
            ""
          ],
          [
            "0",
            "0",
            ""
          ]
        ],
        "data_raw": [
          6113,
          6126,
          6116,
          6093,
          6100,
          6082,
          6103,
          5958,
          6159,
          6090,
          6093,
          6108,
          6110,
          6091,
          6097,
          6107,
          6109,
          6101,
          6097,
          6093,
          6093,
          6100,
          6132,
          6161,
          6139,
          6134,
          5876,
          6359,
          6196,
          6220,
          6283,
          6503,
          7054,
          8427,
          11299,
          16087,
          22267,
          28323,
          32320,
          33477,
          31843,
          28555,
          24660,
          20903,
          17572,
          14816,
          14029,
          11114,
          9854,
          9111,
          8617,
          8334,
          8269,
          8390,
          8708,
          9194,
          9853,
          10547,
          11120,
          12092,
          11119,
          10914,
          10160,
          9744,
          9374,
          8617,
          8582,
          8540,
          8436,
          8357,
          8298,
          8282,
          8359,
          8488,
          8634,
          8789,
          8924,
          9056,
          9165,
          9280,
          9390,
          9480,
          9573,
          9607,
          9635,
          9788,
          9733,
          9826,
          9901,
          9971,
          10050,
          10165,
          10268,
          10339,
          10433,
          10496,
          10548,
          10592,
          10652,
          10749,
          10864,
          10968,
          11099,
          11242,
          11034,
          11318,
          11653,
          11749,
          11881,
          12045,
          12175,
          12328,
          12494,
          12653,
          12779,
          12908,
          12999,
          13093,
          13198,
          13299,
          13386,
          13495,
          13617,
          13567,
          13538,
          13975,
          14090,
          14166,
          14230,
          14294,
          14310,
          14316,
          14369,
          14350,
          14327,
          14343,
          14360,
          14327,
          14311,
          14307,
          14260,
          14189,
          14094,
          13699,
          13759,
          13710,
          13593,
          13495,
          13354,
          13200,
          13135,
          13010,
          12925,
          13163,
          12546,
          12539,
          12283,
          12267,
          12081,
          11881,
          11704,
          11522,
          11133,
          11335,
          11028,
          10844,
          10647,
          10477,
          10322,
          10150,
          9999,
          9835,
          9708,
          9561,
          9425,
          9258,
          9136,
          8986,
          8854,
          8732,
          8586,
          8491,
          8656,
          8323,
          8156,
          8073,
          7982,
          7880,
          7795,
          7715,
          7631,
          7556,
          7446,
          7389,
          7305,
          7218,
          7160,
          7121,
          7025,
          6980,
          6931,
          6556,
          6914,
          6766,
          6757,
          6679,
          6670,
          6654,
          6615,
          6570,
          6568,
          6543,
          6552,
          6536,
          6513,
          6497,
          6474,
          6473,
          6475,
          6447,
          6422,
          7568,
          6512,
          6374,
          6355,
          6327,
          6325,
          6315,
          6325,
          6317,
          6301,
          6304,
          6284,
          6273,
          6268,
          6255,
          6227,
          6242,
          6234,
          6215,
          5875,
          6026,
          6183,
          6231,
          6206,
          6200,
          6230,
          6440,
          6126,
          6132,
          6083,
          6227,
          6179,
          6175,
          6146,
          6147,
          6242,
          6243,
          6108,
          6307,
          6241,
          6232,
          6249,
          6260,
          6234,
          6250,
          6247,
          6251,
          6236,
          6241,
          6255,
          6264,
          6248,
          6274,
          6268,
          6272,
          6285,
          6040,
          6475,
          6337,
          6306,
          6320,
          6348,
          6363,
          6431,
          6487,
          6668,
          7085,
          8180,
          10848,
          16389,
          25993,
          44599,
          46138,
          46572,
          46742,
          46653,
          47602,
          46052,
          37450,
          28738,
          23180,
          18895,
          15701,
          13521,
          12063,
          11152,
          10646,
          10534,
          10751,
          11384,
          12328,
          13567,
          14873,
          15958,
          17034,
          15794,
          15352,
          14281,
          13307,
          12580,
          11914,
          11511,
          11144,
          10869,
          10662,
          10539,
          10537,
          10683,
          10910,
          11177,
          11466,
          11742,
          12024,
          12285,
          12479,
          12753,
          12823,
          12965,
          13068,
          13164,
          13222,
          13324,
          13447,
          13575,
          13744,
          13892,
          14086,
          14277,
          14424,
          14584,
          14673,
          14760,
          14856,
          14994,
          14793,
          15158,
          15601,
          15859,
          16144,
          16402,
          16598,
          16846,
          17096,
          17329,
          17588,
          17861,
          18148,
          18410,
          18699,
          18958,
          19195,
          19407,
          19580,
          19589,
          19633,
          20153,
          20324,
          20530,
          20754,
          21001,
          21244,
          21454,
          21677,
          21798,
          21881,
          21923,
          21956,
          21959,
          21948,
          21938,
          21952,
          21957,
          21922,
          21620,
          21775,
          21743,
          21626,
          21451,
          21232,
          20987,
          20730,
          20478,
          20205,
          19989,
          19762,
          19573,
          19373,
          19190,
          19644,
          18565,
          18517,
          18080,
          17674,
          17691,
          17213,
          16855,
          16524,
          16211,
          15889,
          15585,
          15228,
          14900,
          14556,
          14207,
          13911,
          13601,
          13328,
          13077,
          12847,
          12583,
          12327,
          12073,
          12083,
          11605,
          11266,
          11027,
          10802,
          10571,
          10410,
          10197,
          10050,
          9831,
          9699,
          9502,
          9322,
          9144,
          8967,
          8799,
          8611,
          8473,
          8334,
          7881,
          8164,
          7969,
          7848,
          7778,
          7660,
          7563,
          7493,
          7412,
          7332,
          7270,
          7205,
          7161,
          7114,
          7076,
          7037,
          7028,
          7002,
          6970,
          6945,
          8067,
          6990,
          6823,
          6792,
          6760,
          6725,
          6711,
          6705,
          6692,
          6650,
          6638,
          6605,
          6598,
          6587,
          6552,
          6541,
          6522,
          6497,
          6498,
          6111,
          6264,
          6395,
          6424,
          6404,
          6389,
          6353,
          6358,
          6339,
          6336,
          6308,
          6336,
          6766,
          6156,
          6320,
          6188,
          6308,
          6323,
          6308,
          6262,
          6344,
          6512,
          6491,
          6486,
          6478,
          6487,
          6471,
          6475,
          6453,
          6453,
          6459,
          6484,
          6167,
          6403,
          6488,
          6487,
          6505,
          6496,
          6492,
          6524,
          6542,
          6528,
          6535,
          6547,
          6584,
          6612,
          6615,
          6667,
          6719,
          6788,
          6952,
          7064,
          8426,
          10580,
          17288,
          44997,
          45942,
          46453,
          46739,
          46922,
          47021,
          46938,
          46757,
          46598,
          46308,
          45906,
          45289,
          38632,
          25128,
          20686,
          17823,
          16581,
          15167,
          14781,
          15262,
          16405,
          18234,
          20626,
          23191,
          25482,
          26346,
          25950,
          24328,
          22186,
          20261,
          18566,
          17429,
          16611,
          15932,
          15363,
          14663,
          14810,
          14767,
          15038,
          15508,
          16030,
          16585,
          17137,
          17643,
          18104,
          18533,
          18889,
          19161,
          19430,
          19602,
          19808,
          19946,
          20137,
          20357,
          20640,
          21852,
          21319,
          21584,
          21931,
          22239,
          22522,
          22760,
          22933,
          23128,
          23368,
          23669,
          24093,
          24577,
          25120,
          25630,
          26133,
          26599,
          27059,
          27505,
          27669,
          28335,
          29017,
          29629,
          30168,
          30716,
          31217,
          31677,
          32097,
          32457,
          32777,
          33156,
          33537,
          33890,
          34366,
          34815,
          35259,
          35753,
          36194,
          36541,
          36720,
          37005,
          37097,
          37134,
          37137,
          37133,
          37138,
          37119,
          37109,
          37090,
          36999,
          36880,
          36704,
          36458,
          36116,
          35669,
          35234,
          34689,
          34184,
          33320,
          33002,
          32761,
          32390,
          31947,
          32154,
          30996,
          30710,
          30051,
          29543,
          28964,
          28299,
          27605,
          26991,
          26348,
          25728,
          25072,
          24428,
          23742,
          22903,
          22116,
          21804,
          21199,
          20635,
          20122,
          19618,
          19130,
          18616,
          18116,
          17613,
          17105,
          16597,
          16105,
          15638,
          15206,
          14815,
          14451,
          14102,
          13768,
          13134,
          12985,
          12756,
          12419,
          12090,
          11743,
          11432,
          11148,
          10846,
          10576,
          10327,
          10070,
          9868,
          9656,
          9457,
          9254,
          9081,
          8892,
          8735,
          8322,
          8643,
          8409,
          8256,
          8162,
          8095,
          7984,
          7944,
          7871,
          7821,
          7784,
          7723,
          7690,
          7625,
          7558,
          7502,
          7415,
          7386,
          7328,
          7307,
          7846,
          7328,
          7160,
          7124,
          7087,
          7053,
          7033,
          6996,
          6942,
          6920,
          6882,
          6822,
          6806,
          6777,
          6743,
          6720,
          6689,
          6654,
          6660,
          6312,
          6661,
          7310,
          6411,
          6632,
          6457,
          6574,
          6611,
          6556,
          6529,
          6510,
          6522,
          6340,
          6328,
          6322,
          6324,
          6323,
          6308,
          6309,
          6297,
          6290,
          6294,
          6300,
          6466,
          6407,
          6333,
          6341,
          6353,
          6341,
          6322,
          6339,
          6346,
          6346,
          6337,
          6388,
          6396,
          6393,
          6431,
          6439,
          6459,
          6541,
          6608,
          6545,
          6964,
          8291,
          11446,
          22446,
          47053,
          47804,
          48188,
          48401,
          48506,
          48427,
          48238,
          48074,
          47758,
          47280,
          46561,
          30678,
          23514,
          19513,
          16876,
          14940,
          14177,
          14182,
          14653,
          15819,
          17649,
          20013,
          22574,
          24662,
          25649,
          25282,
          23793,
          21728,
          19713,
          18149,
          17040,
          16272,
          15616,
          15063,
          14673,
          15906,
          14660,
          14860,
          15338,
          15897,
          16491,
          17072,
          17806,
          18209,
          18620,
          18931,
          19270,
          19630,
          19815,
          20007,
          20179,
          20417,
          20658,
          20931,
          21005,
          21701,
          21975,
          22347,
          22707,
          23032,
          23287,
          23484,
          23686,
          23961,
          24308,
          24761,
          25254,
          25852,
          26443,
          26984,
          27480,
          28008,
          28480,
          29006,
          29225,
          29949,
          30787,
          31433,
          32096,
          32684,
          33220,
          33680,
          34086,
          34485,
          34852,
          35313,
          35709,
          36284,
          36836,
          37395,
          37968,
          38483,
          38964,
          39292,
          40053,
          39707,
          39726,
          39761,
          39779,
          39814,
          39853,
          39890,
          39887,
          39886,
          39793,
          39657,
          39433,
          39073,
          38625,
          38146,
          37602,
          37078,
          36543,
          35793,
          35801,
          35183,
          34781,
          34363,
          33911,
          33413,
          32924,
          32290,
          31601,
          30890,
          30159,
          29454,
          28751,
          28062,
          27359,
          26647,
          25891,
          25129,
          24378,
          23328,
          23003,
          22425,
          22447,
          21180,
          20822,
          20104,
          19627,
          19109,
          18504,
          17905,
          17336,
          16834,
          16356,
          15913,
          15499,
          15106,
          14720,
          14350,
          13935,
          13163,
          13198,
          12807,
          12440,
          12040,
          11699,
          11377,
          11070,
          10799,
          10528,
          10261,
          10045,
          9804,
          9583,
          9378,
          9176,
          8980,
          8804,
          8675,
          8183,
          8358,
          8290,
          8228,
          8175,
          8104,
          8047,
          7975,
          7910,
          7844,
          7774,
          7712,
          7630,
          7614,
          7502,
          7444,
          7374,
          7329,
          7287,
          7241,
          7013,
          7241,
          7101,
          7076,
          7037,
          7017,
          6956,
          6929,
          6871,
          6849,
          6770,
          6751,
          6695,
          6656,
          6624,
          6604,
          6602,
          6547,
          6551,
          6359,
          6153,
          6527,
          6475,
          6467,
          6469,
          6456,
          6443,
          6419,
          6425,
          6704,
          6469,
          6578,
          6692,
          6672,
          6641,
          6639,
          6632,
          6649,
          6649,
          6655,
          6653,
          6648,
          6670,
          6646,
          6653,
          6690,
          6677,
          6682,
          6703,
          6708,
          6508,
          6755,
          6793,
          6836,
          6879,
          6918,
          6980,
          7068,
          7275,
          7667,
          8589,
          11058,
          37008,
          46501,
          47346,
          47779,
          48034,
          48204,
          48276,
          48226,
          48851,
          48451,
          48192,
          47827,
          47525,
          47074,
          46397,
          44373,
          27808,
          24172,
          22330,
          21881,
          22784,
          25050,
          28689,
          33370,
          39126,
          42529,
          44079,
          44974,
          41133,
          36796,
          32772,
          29625,
          27437,
          25873,
          24624,
          23586,
          22784,
          22396,
          22562,
          23146,
          24042,
          25155,
          26310,
          27444,
          28536,
          29529,
          30177,
          31145,
          31850,
          32431,
          32863,
          33245,
          33571,
          34034,
          34533,
          35070,
          35673,
          36393,
          37137,
          37884,
          38596,
          39211,
          39742,
          40156,
          40544,
          41073,
          42068,
          42665,
          43776,
          44946,
          45784,
          46252,
          46592,
          46789,
          46948,
          47036,
          47088,
          47101,
          47253,
          47301,
          47316,
          47287,
          47286,
          47247,
          47304,
          46945,
          47087,
          47386,
          47417,
          47455,
          47428,
          47436,
          47473,
          47469,
          47524,
          47539,
          47581,
          47546,
          47596,
          47533,
          47481,
          47372,
          47391,
          47358,
          47255,
          46873,
          47315,
          47370,
          47368,
          47334,
          47402,
          47427,
          47370,
          47389,
          47390,
          47371,
          47364,
          47338,
          47332,
          47271,
          47283,
          47253,
          47208,
          47174,
          46842,
          47018,
          47093,
          47015,
          46897,
          46747,
          46503,
          46024,
          44968,
          43192,
          41564,
          40163,
          38884,
          37647,
          36509,
          35436,
          34382,
          33272,
          32163,
          30825,
          29909,
          28759,
          27668,
          26641,
          25685,
          24818,
          24051,
          23269,
          22548,
          21849,
          21137,
          20373,
          19627,
          18916,
          18191,
          17470,
          16816,
          16195,
          15618,
          14926,
          14616,
          14109,
          13662,
          13233,
          12803,
          12433,
          12044,
          11697,
          11386,
          11089,
          10839,
          10620,
          10418,
          10299,
          10151,
          10037,
          9915,
          9820,
          9426,
          9773,
          9511,
          9355,
          9183,
          9051,
          8910,
          8790,
          8682,
          8571,
          8468,
          8385,
          8331,
          8240,
          8138,
          8058,
          7971,
          7891,
          7818,
          7732,
          9092,
          7602,
          7466,
          7410,
          7378,
          7275,
          7206,
          7145,
          7130,
          7111,
          7405,
          6878,
          6979,
          6842,
          6954,
          6918,
          6862,
          6841,
          6836,
          6436,
          6584,
          7304,
          7305,
          7313,
          7275,
          7280,
          7256,
          7234,
          7235,
          7240,
          7247,
          7146,
          6795,
          7262,
          7257,
          7267,
          7282,
          7289,
          7310,
          7313,
          7341,
          7386,
          7404,
          7457,
          7490,
          7580,
          7664,
          7793,
          7929,
          8209,
          8684,
          9287,
          14677,
          45282,
          46293,
          46999,
          47585,
          48027,
          48294,
          48475,
          48565,
          48484,
          48352,
          48217,
          47996,
          47726,
          47493,
          47198,
          46857,
          46443,
          45970,
          45631,
          45059,
          39725,
          44470,
          45411,
          45921,
          46295,
          46533,
          46707,
          46739,
          46719,
          46627,
          46404,
          46288,
          46136,
          45922,
          45559,
          44865,
          41635,
          38846,
          38300,
          38506,
          39706,
          42168,
          44714,
          45459,
          45776,
          45985,
          46028,
          46132,
          46178,
          46255,
          46270,
          46280,
          46295,
          46327,
          46364,
          46453,
          46285,
          46675,
          46564,
          46595,
          46518,
          46635,
          46725,
          46831,
          46851,
          46809,
          46854,
          46891,
          46899,
          46972,
          46915,
          46916,
          46958,
          47006,
          47059,
          47103,
          48455,
          47286,
          47146,
          47279,
          47341,
          47351,
          47324,
          47287,
          47254,
          47307,
          47291,
          47320,
          47398,
          47426,
          47434,
          47438,
          47423,
          47485,
          47509,
          47220,
          47454,
          47573,
          47570,
          47626,
          47532,
          47493,
          47389,
          47414,
          47371,
          47399,
          47356,
          47332,
          47375,
          47369,
          47332,
          47381,
          47400,
          47348,
          47335,
          47755,
          47398,
          47400,
          47370,
          47348,
          47274,
          47285,
          47278,
          47241,
          47218,
          47220,
          47177,
          47184,
          47152,
          47127,
          47087,
          47087,
          47023,
          46952,
          46461,
          46634,
          46753,
          46703,
          46664,
          46589,
          46592,
          46446,
          46401,
          46363,
          46293,
          46157,
          46088,
          45904,
          45584,
          45064,
          43492,
          41336,
          39704,
          38144,
          36421,
          35408,
          33971,
          32468,
          30988,
          29509,
          28129,
          26816,
          25629,
          24485,
          23456,
          22455,
          21575,
          20703,
          19849,
          19069,
          18325,
          17585,
          16916,
          15989,
          15619,
          15267,
          14879,
          14530,
          14258,
          14000,
          13773,
          13557,
          13350,
          13114,
          12911,
          12647,
          12415,
          12162,
          11905,
          11673,
          11414,
          11187,
          10777,
          10825,
          10690,
          10493,
          10320,
          10155,
          9982,
          9833,
          9675,
          9504,
          9365,
          9205,
          9047,
          8908,
          8761,
          8601,
          8493,
          8379,
          8265,
          8181,
          8526,
          7978,
          8006,
          7804,
          7799,
          7838,
          7711,
          7666,
          7613,
          7582,
          7561,
          7527
        ],
        "tcs_dac_values": [
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0
        ]
      }
    ]
  ],
  "app_os": "mac",
  "app_name": "PhotosynQ",
  "app_version": "0.3.2",
  "app_device": "x86-64",
  "location": [
    "42.7369792",
    "-84.4838654"
  ],
  "notes": "Calibration against tape and paper"
}
Sebastian kuhlgert square
Created by

Sebastian


Protocol connections:
1
Latest Update:
Jun 2016