Leaf photo 3


only SPAD
var output = {};
var spad;
var data = json.data_raw;
var quality_flag = 0;


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

var abs_starts = 0; // when does the SPAD measurement start
var data = json.data_raw;
var lights = [2,6];// define the lights to have absorbance measured
var wavelengths = ["650","940"];// 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

/* // 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},
*/

/*
** Loop through the lights.  If it's zero, skip it.  If it's not in the acceptable range (>500 but <65534 (max)) skip it.
** Then choose the first blank (starting with 1 moving to 3) which fulfills this criteria
** Otherwise, calculate absorbance and transmittance and a 'spad'-like value using LED 6 (940 on clamp) to calibrate thickness
*/
//----------------------------

for (var i = 0;i<lights.length;i++) { // loop through and save one averaged 'point' for each of the cycles
  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] > 100 && 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+"]"];
  }
}

// so the raw value needs to be >~2000, while the 940 needs to be greater than ~5000, otherwise it's out of range
// the acceptable range is different for each blank (1,2,3) thus a separate if statement for each blank.
// once you hit an intensity which is within the acceptable range, then keep that value and skip the rest

for (var i = 0;i<8;i++) { // loop through and save one averaged SPAD value for each of the cycles.  If we have additional calibration values (like minolta spad) use those and output that value
  light = lights[i];
  wavelengthString = wavelengths[i];
  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(String(),"_minolta_spad2")]  = MathROUND(minolta_spad2,2);
  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(String(),"_minolta_spad1")]  = MathROUND(minolta_spad1,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(String(),"_minolta_spad3")]  = MathROUND(minolta_spad3,2);
  
  if (light == 2) { // if it's the red light, the also calculate minolta spad
    /*
    output ["light".concat(light.toString(),"_raw1")]  = raw_at_blank1[light];
    output ["light6_raw1"]  = raw_at_blank1[6];
    output ["spad_raw1"]  = spad_at_blank1[2];
    output ["light".concat(light.toString(),"_raw2")]  = raw_at_blank2[light];
    output ["light6_raw2"]  = raw_at_blank2[6];
    output ["spad_raw2"]  = spad_at_blank2[2];
    output ["light".concat(light.toString(),"_raw3")]  = raw_at_blank3[light];
    output ["light6_raw3"]  = raw_at_blank3[6];
    output ["spad_raw3"]  = spad_at_blank3[2];
    */
  }
  if (json.recall["colorcal_blank1["+light+"]"] != 0 && raw_at_blank1[light] > 500 && 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 = (spad_at_blank1[2] - json.recall["colorcal_intensity1_yint[2]"]) / json.recall["colorcal_intensity1_slope[2]"];	
      output ["SPAD_".concat(wavelengthString)]  = MathROUND(minolta_spad,2);
      output ["SPAD_".concat(wavelengthString,"_intensity")]  = 1;
        choose = 1;
      continue;
    }
    else if (light != 6) {
      output ["SPAD_".concat(wavelengthString)] = MathROUND(spad_at_blank1[light],2);
      output ["SPAD_".concat(wavelengthString,"_intensity")] = 1;
//      output ["SPAD1_".concat(wavelengthString)] = MathROUND(spad_at_blank1[light],2);
//      output ["SPAD1_".concat(wavelengthString,"_intensity")] = 1;
      continue;
    }
  }
  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 = (spad_at_blank2[2] - json.recall["colorcal_intensity2_yint[2]"]) / json.recall["colorcal_intensity2_slope[2]"];
//      output ["SPAD_".concat(wavelengthString)] = MathROUND(minolta_spad,2);
//      output ["SPAD_".concat(wavelengthString,"_intensity")] = 2;
        choose = 2;
      continue;
    }
    else if (light != 6) {
      output ["SPAD_".concat(wavelengthString)] = MathROUND(spad_at_blank2[light],2);
      output ["SPAD_".concat(wavelengthString,"_intensity")] = 2;
//      output ["SPAD2_".concat(wavelengthString)] = MathROUND(spad_at_blank2[light],2);
//      output ["SPAD2_".concat(wavelengthString,"_intensity")] = 2;
      continue;
    }
  }
  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 = (spad_at_blank3[2] - json.recall["colorcal_intensity3_yint[2]"]) / json.recall["colorcal_intensity3_slope[2]"];
      output ["SPAD_".concat(wavelengthString)]  = MathROUND(minolta_spad,2);
      output ["SPAD_".concat(wavelengthString,"_intensity")]  = 3;
      choose = 3;
      continue;
    }
    else if (light != 6) {
      output ["SPAD_".concat(wavelengthString)] = MathROUND(spad_at_blank3[light],2);
      output ["SPAD_".concat(wavelengthString,"_intensity")] = 3;
      output ["SPAD3_".concat(wavelengthString)] = MathROUND(spad_at_blank3[light],2);
      output ["SPAD3_".concat(wavelengthString,"_intensity")] = 3;
      continue;
    }
  }
}

/*
if (choose == 0) {
  output ["SPAD_650"]  = 0;
  danger("Chlorophyll content SPAD is outside the acceptable range.  The leaf may be too thick, too thin, or have holes in it.", output);
}
else 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);
}
*/
// Finally, use the "order" object to define the order of the outputs (focus on the top 6 most important for the user to see)
//----------------------------
//output ["Rel Chl intensity"]  = choose; 

output["SPAD1"] = MathROUND(minolta_spad1,2);
output["SPAD2"] = MathROUND(minolta_spad2,2);
output["SPAD3"] = MathROUND(minolta_spad3,2);


output["Rel Chl"] = MathROUND(minolta_spad1,2);

output["order"] = ["Rel Chl"];

return output;
{
  "time_offset": -540,
  "time": 1497946640625,
  "device_name": "MultispeQ",
  "device_version": "1",
  "device_id": "01:12:52:58",
  "device_battery": 90,
  "device_firmware": 1.17,
  "sample": [
    {
      "time": 1497946640643,
      "protocol_id": 1,
      "detector_read1": 7097,
      "detector_read2": 4359,
      "light_intensity": 12,
      "r": 10,
      "g": 4,
      "b": 4,
      "light_intensity_raw": 16,
      "temperature": 28.690001,
      "humidity": 52.650391,
      "pressure": 1006.18103,
      "temperature2": 28.559999,
      "humidity2": 52.800781,
      "pressure2": 1005.812683,
      "contactless_temp": 27.53,
      "thickness": 0.35,
      "compass_direction": "E",
      "compass": "90.00",
      "angle": 4.59,
      "angle_direction": "S",
      "pitch": 4.46,
      "roll": -1.09,
      "recall": {
        "time": 1497946671321,
        "colorcal_blank1[1]": 20978,
        "colorcal_blank1[2]": 25386,
        "colorcal_blank1[3]": 30262,
        "colorcal_blank1[4]": 34693.5,
        "colorcal_blank1[6]": 31865,
        "colorcal_blank1[8]": 26552,
        "colorcal_blank1[9]": 30009,
        "colorcal_blank1[10]": 33426,
        "colorcal_blank2[1]": 19350.5,
        "colorcal_blank2[2]": 18002.5,
        "colorcal_blank2[3]": 22659,
        "colorcal_blank2[4]": 17322,
        "colorcal_blank2[6]": 16254,
        "colorcal_blank2[8]": 17067.5,
        "colorcal_blank2[9]": 18651,
        "colorcal_blank2[10]": 16710,
        "colorcal_blank3[1]": 18454,
        "colorcal_blank3[2]": 9577.5,
        "colorcal_blank3[3]": 20198,
        "colorcal_blank3[4]": 12366,
        "colorcal_blank3[6]": 5797.5,
        "colorcal_blank3[8]": 6238,
        "colorcal_blank3[9]": 5510.5,
        "colorcal_blank3[10]": 6057,
        "colorcal_intensity1_slope[2]": 2.183,
        "colorcal_intensity1_yint[2]": 6.2,
        "colorcal_intensity2_slope[2]": 2.32,
        "colorcal_intensity2_yint[2]": 4.8,
        "colorcal_intensity3_slope[2]": 2.547,
        "colorcal_intensity3_yint[2]": -18,
        "ir_baseline_slope[5]": 6044,
        "ir_baseline_yint[5]": 9756,
        "ir_baseline_slope[3]": 686,
        "ir_baseline_yint[3]": 935
      },
      "data_raw": [
        2108,
        1523,
        1521,
        1513,
        1515,
        1517,
        1521,
        1516,
        1514,
        1509,
        127,
        452,
        457,
        463,
        455,
        462,
        457,
        463,
        463,
        455,
        100,
        1336,
        1365,
        1352,
        1359,
        1350,
        1365,
        1360,
        1358,
        1351,
        75,
        195,
        199,
        211,
        201,
        199,
        199,
        202,
        201,
        202,
        65535,
        13622,
        11094,
        10948,
        10929,
        10917,
        10905,
        10896,
        10894,
        10892,
        60717,
        17477,
        11850,
        11573,
        11520,
        11495,
        11475,
        11468,
        11455,
        11457,
        33412,
        13669,
        13150,
        13110,
        13095,
        13096,
        13097,
        13094,
        13101,
        13101,
        42841,
        14599,
        13689,
        13651,
        13635,
        13626,
        13629,
        13623,
        13621,
        13631,
        3329,
        12476,
        12605,
        12599,
        12607,
        12607,
        12618,
        12614,
        12615,
        12615,
        2656,
        2686,
        2690,
        2688,
        2686,
        2690,
        2688,
        2688,
        2700,
        2693,
        9760,
        9914,
        9931,
        9919,
        9926,
        9923,
        9921,
        9926,
        9926,
        9923,
        808,
        824,
        821,
        823,
        829,
        823,
        825,
        823,
        822,
        828,
        44847,
        45739,
        45795,
        45780,
        45786,
        45789,
        45791,
        45794,
        45791,
        45787,
        48548,
        49411,
        49465,
        49479,
        49478,
        49479,
        49488,
        49487,
        49495,
        49479,
        44641,
        45490,
        45528,
        45529,
        45539,
        45538,
        45542,
        45543,
        45537,
        45545,
        46545,
        47586,
        47625,
        47636,
        47631,
        47629,
        47621,
        47624,
        47615,
        47602,
        50051,
        50630,
        50647,
        50658,
        50649,
        50646,
        50637,
        50636,
        50647,
        50630,
        5754,
        5839,
        5842,
        5835,
        5842,
        5838,
        5845,
        5845,
        5849,
        5843,
        49187,
        50395,
        50415,
        50395,
        50385,
        50366,
        50343,
        50341,
        50335,
        50318,
        2917,
        2979,
        2989,
        2989,
        2987,
        2987,
        2985,
        2997,
        2989,
        2995,
        45836,
        45797,
        45795,
        45796,
        45797,
        45802,
        45801,
        45794,
        45802,
        45799,
        49603,
        49477,
        49479,
        49479,
        49483,
        49479,
        49483,
        49480,
        49477,
        49475,
        45581,
        45578,
        45573,
        45582,
        45591,
        45577,
        45582,
        45575,
        45580,
        45574,
        47735,
        47651,
        47654,
        47631,
        47628,
        47616,
        47620,
        47611,
        47607,
        47595
      ]
    }
  ],
  "app_os": "win",
  "app_name": "PhotosynQ",
  "app_version": "0.3.8",
  "app_device": "x86-64",
  "location": [
    "35.1552277",
    "136.9706645"
  ],
  "ConsoleMacro": "348"
}
Default avatar
Created by

DS


Protocol connections:
3
Latest Update:
Jun 2017