v1.0 SPAD ONLY 2


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;
var ECSt;
var quality_flag = 0;
var i = 0;
var j = 0;
var h = 0;
var k = 0;

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

var abs_starts = 0; // 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 light;
var pulses = 10;// number of pulses in a cycle

// this is what the recall object looks like --> 
/*
"recall":{"colorcal_blank1[1]":0.000000,"colorcal_blank1[2]":0.000000,"colorcal_blank1[3]":0.000000,"colorcal_blank1[4]":0.00000
0,"colorcal_blank1[6]":0.000000,"colorcal_blank1[8]":0.000000,"colorcal_blank1[9]":0.000000,"colorcal_blank1[10]":0.000000,"colo
rcal_blank2[1]":0.000000,"colorcal_blank2[2]":0.000000,"colorcal_blank2[3]":0.000000,"colorcal_blank2[4]":0.000000,"colorcal_bla
nk2[6]":0.000000,"colorcal_blank2[8]":0.000000,"colorcal_blank2[9]":0.000000,"colorcal_blank2[10]":0.000000,"colorcal_blank3[1]"
:0.000000,"colorcal_blank3[2]":0.000000,"colorcal_blank3[3]":0.000000,"colorcal_blank3[4]":0.000000,"colorcal_blank3[6]":0.00000
0,"colorcal_blank3[8]":0.000000,"colorcal_blank3[9]":0.000000,"colorcal_blank3[10]":0.000000},
*/



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+"]"];
  }
}

/*
output ["colorcal_intensity1_slope[2]"]  = json.recall["colorcal_intensity1_slope[2]"];
output ["colorcal_intensity1_yint[2]"]  = json.recall["colorcal_intensity1_yint[2]"];
output ["colorcal_intensity2_slope[2]"]  = json.recall["colorcal_intensity2_slope[2]"];
output ["colorcal_intensity2_yint[2]"]  = json.recall["colorcal_intensity2_yint[2]"];
output ["colorcal_intensity3_slope[2]"]  = json.recall["colorcal_intensity3_slope[2]"];
output ["colorcal_intensity3_yint[2]"]  = json.recall["colorcal_intensity3_yint[2]"];


output ["ir at blank 1"]  = raw_at_blank1[6];
output ["led at blank 1"]  = raw_at_blank1[2];
output ["ir at blank 2"]  = raw_at_blank2[6];
output ["led at blank 2"]  = raw_at_blank2[2];
output ["ir at blank 3"]  = raw_at_blank3[6];
output ["led at blank 3"]  = raw_at_blank3[2];
*/

// 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] > 2000 && raw_at_blank1[light] < 65534 
    && raw_at_blank1[6] > 5000 && 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] > 750 && 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": 240,
  "time": 1464281852304,
  "device_version": "1",
  "device_id": "d4:f5:00:00:00:00",
  "device_battery": 89,
  "device_firmware": "0.55",
  "firmware_version": "0.55",
  "device_time": 1464180335,
  "sample": [
    [
      {
        "time": 1464281852317,
        "protocol_id": 1,
        "light_intensity": 10,
        "r": 24,
        "g": 12,
        "b": 6,
        "light_intensity_raw": 42,
        "temperature2": 0,
        "humidity2": 0,
        "pressure2": 0,
        "contactless_temp": 30.47,
        "thickness_raw": 42657,
        "compass_direction": "NW",
        "compass": 328.88,
        "angle": 3.26,
        "angle_direction": "NE",
        "pitch": 3.14,
        "roll": -0.87,
        "recall": {
          "time": 1464281852395,
          "colorcal_blank1[2]": 15776,
          "colorcal_blank1[6]": 15774.5,
          "colorcal_blank2[2]": 26583,
          "colorcal_blank2[6]": 25199.5,
          "colorcal_blank3[2]": 21768.5,
          "colorcal_blank3[6]": 13551.5,
          "colorcal_intensity1_slope[2]": 2.579,
          "colorcal_intensity2_slope[2]": 2.606,
          "colorcal_intensity3_slope[2]": 2.47,
          "colorcal_intensity1_yint[2]": 0,
          "colorcal_intensity2_yint[2]": -27.299999,
          "colorcal_intensity3_yint[2]": 24.200001
        },
        "data_raw": [
          734,
          734,
          735,
          734,
          734,
          734,
          735,
          734,
          734,
          736,
          2522,
          1702,
          1694,
          1693,
          1692,
          1690,
          1691,
          1690,
          1690,
          1691,
          5958,
          5957,
          5959,
          5957,
          5958,
          5959,
          5958,
          5957,
          5958,
          5959,
          13650,
          13660,
          13652,
          13653,
          13653,
          13649,
          13649,
          13653,
          13650,
          13649,
          6455,
          6490,
          6491,
          6488,
          6492,
          6489,
          6489,
          6487,
          6488,
          6489,
          42778,
          43133,
          43124,
          43126,
          43135,
          43123,
          43125,
          43131,
          43125,
          43124
        ]
      }
    ]
  ],
  "app_os": "linux",
  "app_name": "PhotosynQ",
  "app_version": "0.3.3",
  "app_device": "x86-64",
  "location": [
    "42.7369792",
    "-84.4838654"
  ],
  "ConsoleMacro": "176",
  "notes": "actually works"
}
Default avatar
Created by

Kevin Bi


Protocol connections:
3
Latest Update:
May 2016