v1.0 SPAD ONLY Dan


Calculating SPAD at three light intensities only
// CALCULATIONS FOR PROTON MOTIVE FORCE VIA ECS PORTION OF THE TRACE
//----------------------------

var output = {};
var spad;
var data = json.data_raw;


// CALCULATIONS FOR ABSORBANCE / SPAD PORTION OF THE TRACE
//----------------------------

var abs_starts = 40; // when does the Phi2 measurement start (sub
var data = json.data_raw;
var lights = [2, 6];// define the lights to have absorbance measured
var raw_at_blank1 = [0,0,0,0,0,0,0,0];
var raw_at_blank2 = [0,0,0,0,0,0,0,0];
var raw_at_blank3 = [0,0,0,0,0,0,0,0];
var abs_at_blank1 = [0,0,0,0,0,0,0,0];
var abs_at_blank2 = [0,0,0,0,0,0,0,0];
var abs_at_blank3 = [0,0,0,0,0,0,0,0];
var trans_at_blank1 = [0,0,0,0,0,0,0,0];
var trans_at_blank2 = [0,0,0,0,0,0,0,0];
var trans_at_blank3 = [0,0,0,0,0,0,0,0];
var spad_at_blank1 = [0,0,0,0,0,0,0,0];
var spad_at_blank2 = [0,0,0,0,0,0,0,0];
var spad_at_blank3 = [0,0,0,0,0,0,0,0];
var minolta_spad1 = 0;
var minolta_spad2 = 0;
var minolta_spad3 = 0;
var minolta_spad = 0;
var minolta_spad_averages = 0;
var choose = 0; 
var light;
var wavelengthString;
var pulses = 10;// number of pulses in a cycle


/*
for (var i = 0;i<lights.length;i++) {
  light = lights[i];
  wavelengthString = wavelengths[i];
  var value1 = MathMEDIAN(json.data_raw.slice((abs_starts + i*pulses+2),(abs_starts + i*pulses+8)));
  var value2 = MathMEDIAN(json.data_raw.slice((abs_starts + i*pulses+22),(abs_starts + i*pulses+28)));
  var value3 = MathMEDIAN(json.data_raw.slice((abs_starts + i*pulses+42),(abs_starts + i*pulses+48)));
  raw_at_blank1[light] = value1;
  raw_at_blank2[light] = value2;
  raw_at_blank3[light] = value3;
  if (json.recall["colorcal_blank1["+light+"]"] != 0 && raw_at_blank1[light] > 500 && raw_at_blank1[light] < 65534) {
    abs_at_blank1[light] = MathROUND(-1*MathLOG(raw_at_blank1[light]/json.recall["colorcal_blank1["+light+"]"]),3);
//    trans_at_blank1[light] = MathROUND(raw_at_blank1[light]/json.recall["colorcal_blank1["+light+"]"],3);
//	output ["light".concat(light.toString(),"_transmittance")]  = trans_at_blank1[light];
    output ["absorbance_".concat(wavelengthString)]  = abs_at_blank1[light];
//	output ["light".concat(light.toString(),"_blank1")]  = json.recall["colorcal_blank1["+light+"]"];
  }
}
*/


for (var i = 0;i<2;i++) { // loop through and save one averaged 'point' for each of the cycles
  light = lights[i];
  raw_at_blank1[light] = MathMEDIAN(json.data_raw.slice((abs_starts + i*pulses+2),(abs_starts + i*pulses+8)));
  raw_at_blank2[light] = MathMEDIAN(json.data_raw.slice((abs_starts + i*pulses+22),(abs_starts + i*pulses+28)));
  raw_at_blank3[light] = MathMEDIAN(json.data_raw.slice((abs_starts + i*pulses+42),(abs_starts + i*pulses+48)));
  if (json.recall["colorcal_blank1["+light+"]"] != 0 && raw_at_blank1[light] > 500 && raw_at_blank1[light] < 65534) {
    abs_at_blank1[light] = MathROUND(-1*MathLOG(raw_at_blank1[light]/json.recall["colorcal_blank1["+light+"]"]),3);
//    trans_at_blank1[light] = MathROUND(raw_at_blank1[light]/json.recall["colorcal_blank1["+light+"]"],3);
//	output ["light".concat(light.toString(),"_transmittance")]  = trans_at_blank1[light];
    output ["light".concat(light.toString(),"_absorbance")]  = abs_at_blank1[light];
//	output ["light".concat(light.toString(),"_raw1")]  = raw_at_blank1[light];
//	output ["light".concat(light.toString(),"_blank1")]  = json.recall["colorcal_blank1["+light+"]"];
  }
}



// ok so we need to also include the 940 signal requirements here, like -->

//  if (json.recall["colorcal_blank1["+light+"]"] != 0 && raw_at_blank1[light] > 500 && raw_at_blank1[light] < 65534
//		&& raw_at_blank1[6] > 500 && raw_at_blank1[6] < 65534 ) {


// so the raw value needs to be >2000, while the 940 needs to be greater than 5000, otherwise it's out of range
// may need to include an out of range flag high and low here.
// maybe set this up so it chooses the best one (optimal range), and includes an output stating the quality of the range fit... (?)


  light = 2;
  var averages = 0;

	spad_at_blank1[light] = MathROUND(100*MathLOG((raw_at_blank1[6] / json.recall["colorcal_blank1[6]"])/(raw_at_blank1[light] / json.recall["colorcal_blank1["+light+"]"])),2);
    minolta_spad1 = (spad_at_blank1[2] - json.recall["colorcal_intensity1_yint[2]"]) / json.recall["colorcal_intensity1_slope[2]"];	
   	output ["light".concat(light.toString(),"_minolta_spad1")]  = MathROUND(minolta_spad1,2);
    output ["light".concat(light.toString(),"_spad1")]  = MathROUND(spad_at_blank1[light],2);

	spad_at_blank2[light] = MathROUND(100*MathLOG((raw_at_blank2[6] / json.recall["colorcal_blank2[6]"])/(raw_at_blank2[light] / json.recall["colorcal_blank2["+light+"]"])),2);
    minolta_spad2 = (spad_at_blank2[2] - json.recall["colorcal_intensity2_yint[2]"]) / json.recall["colorcal_intensity2_slope[2]"];
    output ["light".concat(light.toString(),"_minolta_spad2")]  = MathROUND(minolta_spad2,2);
    output ["light".concat(light.toString(),"_spad2")]  = MathROUND(spad_at_blank2[light],2);

	spad_at_blank3[light] = MathROUND(100*MathLOG((raw_at_blank3[6] / json.recall["colorcal_blank3[6]"])/(raw_at_blank3[light] / json.recall["colorcal_blank3["+light+"]"])),2);
    minolta_spad3 = (spad_at_blank3[2] - json.recall["colorcal_intensity3_yint[2]"]) / json.recall["colorcal_intensity3_slope[2]"];
    output ["light".concat(light.toString(),"_minolta_spad3")]  = MathROUND(minolta_spad3,2);
    output ["light".concat(light.toString(),"_spad3")]  = MathROUND(spad_at_blank3[light],2);
      

  if (json.recall["colorcal_blank1["+light+"]"] != 0 && raw_at_blank1[light] > 30 && raw_at_blank1[light] < 65534 
    && raw_at_blank1[6] > 4500 && raw_at_blank1[6] < 65534) {
	if (light == 2) { // if it's the red light, the also calculate minolta spad
      minolta_spad = minolta_spad + minolta_spad1;
      averages++;
    }
  }
  else if (json.recall["colorcal_blank2["+light+"]"] != 0 && raw_at_blank2[light] > 500 && raw_at_blank2[light] < 65534 
    && raw_at_blank2[6] > 3000 && raw_at_blank2[6] < 65534) {
	if (light == 2) { // if it's the red light, the also calculate minolta spad
     
      minolta_spad = minolta_spad + minolta_spad2;
      averages++;
    }
  }
  else if (json.recall["colorcal_blank3["+light+"]"] != 0 && raw_at_blank3[light] > 750 && raw_at_blank3[light] < 65534 
    && raw_at_blank3[6] > 3000 && raw_at_blank3[6] < 65534) {
	if (light == 2) { // if it's the red light, the also calculate minolta spad
      minolta_spad = minolta_spad + minolta_spad3;
//      minolta_spad_averages = averages + 1;							// need a global variable for SPAD to output the averaged value
      averages++;
    }
  }
  //output ["light".concat(light.toString(),"_spad")]  = MathROUND((spad_at_blank1[light] + spad_at_blank2[light] + spad_at_blank3[light])/averages,2);

//	output ["averages"] = averages;

// calculate chlorophyll content SPAD values with Minolta SPAD calibration -->
if (averages > 0) {
	output ["SPAD"] = MathROUND(minolta_spad / averages,2);
    if (minolta_spad <= 2) {
    //	info("Chlorophyll Content SPAD is very low.  If leaf is visibly green, ensure leaf completely covers the light guide and retry.  If still too low, consider recalibrating device.", output);
    }
    else if (minolta_spad >= 100) {
    //	info("Chlorophyll Content SPAD is very high.  If this value is associated with a typical leaf, consider recalibrating device.", output);
    }
}
else {
//	danger("Chlorophyll content outside the normal range.  Unable to get an acceptable spad value", output);
	output ["SPAD"] = -99;
}

output["order"] = ["SPAD","averages","light2_minolta_spad1","light2_minolta_spad2","light2_minolta_spad3"];

return output;
{
  "time_offset": 300,
  "time": 1480606860475,
  "device_version": "1",
  "device_id": "d4:f5:00:00:00:05",
  "device_battery": 93,
  "device_firmware": "1.13",
  "firmware_version": "1.13",
  "device_time": 1478774024,
  "sample": [
    [
      {
        "time": 1480606860489,
        "protocol_id": 1,
        "light_intensity": 12,
        "r": 18,
        "g": 8,
        "b": 4,
        "light_intensity_raw": 30,
        "contactless_temp": 25.43,
        "thickness_raw": 50149,
        "compass_direction": "E",
        "compass": "90.00",
        "angle": 0.95,
        "angle_direction": "SE",
        "pitch": 0.86,
        "roll": 0.4,
        "recall": {
          "time": 1480606860610,
          "colorcal_blank1[2]": 30146.5,
          "colorcal_blank1[6]": 31921,
          "colorcal_blank2[2]": 26341.5,
          "colorcal_blank2[6]": 16295,
          "colorcal_blank3[2]": 15552.5,
          "colorcal_blank3[6]": 5908,
          "colorcal_intensity1_slope[2]": 2.637,
          "colorcal_intensity2_slope[2]": 2.605,
          "colorcal_intensity3_slope[2]": 2.954,
          "colorcal_intensity1_yint[2]": 2.6,
          "colorcal_intensity2_yint[2]": 3.8,
          "colorcal_intensity3_yint[2]": -18.1
        },
        "data_raw": [
          3479,
          2631,
          2063,
          1711,
          1463,
          1311,
          1151,
          1023,
          959,
          871,
          823,
          775,
          726,
          685,
          631,
          615,
          591,
          549,
          533,
          507,
          487,
          473,
          455,
          442,
          419,
          413,
          394,
          382,
          373,
          359,
          351,
          344,
          332,
          324,
          313,
          313,
          304,
          294,
          290,
          278,
          276,
          271,
          264,
          260,
          259,
          257,
          256,
          259,
          260,
          255,
          5202,
          1523,
          1482,
          1479,
          1476,
          1477,
          1473,
          1474,
          1474,
          1471,
          1218,
          1447,
          1455,
          1457,
          1459,
          1454,
          1451,
          1456,
          1456,
          1455,
          4619,
          5223,
          5238,
          5239,
          5236,
          5234,
          5229,
          5238,
          5234,
          5237,
          2633,
          2967,
          2981,
          2980,
          2982,
          2983,
          2979,
          2982,
          2981,
          2983,
          5236,
          5231,
          5237,
          5233,
          5239,
          5238,
          5241,
          5237,
          5233,
          5239
        ]
      }
    ]
  ],
  "app_os": "win",
  "app_name": "PhotosynQ",
  "app_version": "0.3.5",
  "app_device": "x86-32",
  "location": [
    "42.7225928",
    "-84.4746718"
  ],
  "ConsoleMacro": "177"
}
Sam 0645   copy   copy  2
Created by

Dan TerAvest


Protocol connections:
0
Latest Update:
Dec 2016