Leaf photo 2


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

var output = {};

var abs_starts = 0; // when does the SPAD measurement start 
var data = json.data_raw;
var lights = [1,2,3,4,6];// define the lights to have absorbance measured. 波長1,2,3,4,6,8,9,10=nm "530","650","605","420","","850","730","880"
var wavelengths = ["530","650","605","420","940"];// define the lights to have absorbance measured
var raw_at_blank1 = [0,0,0,0];
var raw_at_blank2 = [0,0,0,0];
var raw_at_blank3 = [0,0,0,0];
var abs_at_blank1 = [0,0,0,0];
var abs_at_blank2 = [0,0,0,0];
var abs_at_blank3 = [0,0,0,0];
var trans_at_blank1 = [0,0,0,0];
var trans_at_blank2 = [0,0,0,0];
var trans_at_blank3 = [0,0,0,0];
var spad_at_blank1 = [0,0,0,0];
var spad_at_blank2 = [0,0,0,0];
var spad_at_blank3 = [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


//output["lights.length"] = lights.length;


/* // 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+82),(abs_starts + i*pulses+88)));
  var value3 = MathMEDIAN(json.data_raw.slice((abs_starts + i*pulses+162),(abs_starts + i*pulses+168)));
  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+"]"];
  }
}

// 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





// ◯回平均?
// 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
for (var i = 0;i<4;i++) {
  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);
  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);
  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);
  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] > 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 = (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] > 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 = (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) {
  danger("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) {
  danger("Chlorophyll Content SPAD is very high.  If this value is associated with a typical leaf, consider recalibrating device.", output);
}

/*
    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_spad1 >= 100) {
      info("Chlorophyll Content SPAD is very high.  If this value is associated with a typical leaf, consider recalibrating device.", output);
    }
*/

// calculate chlorophyll content SPAD values with Minolta SPAD calibration -->

/*
if (choose == 0) {
    output ["SPAD"]  = 0;
    output ["SPAD intensity"]  = 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 (choose == 1) {
    output ["SPAD"]  = MathROUND(minolta_spad1,2);
    output ["SPAD intensity"]  = 1;
    if (minolta_spad1 <= 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_spad1 >= 100) {
      info("Chlorophyll Content SPAD is very high.  If this value is associated with a typical leaf, consider recalibrating device.", output);
    }
}
else if (choose == 2) {
    output ["SPAD"]  = MathROUND(minolta_spad2,2);
    output ["SPAD intensity"]  = 2;
	if (minolta_spad2 <= 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_spad2 >= 100) {
      info("Chlorophyll Content SPAD is very high.  If this value is associated with a typical leaf, consider recalibrating device.", output);
    }
}
else if (choose == 3) {
    output ["SPAD"]  = MathROUND(minolta_spad3,2);
    output ["SPAD intensity"]  = 3;
	if (minolta_spad3 <= 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_spad3 >= 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["Light Intensity (PAR)"] = json.light_intensity;
//output["Leaf Temp Differential"] = json.contactless_temp - json.temperature;
//output["Leaf Temp Differential"] = MathROUND(json.contactless_temp - json.temperature,4);
//output ["Rel Chl intensity"]  = choose;  	
//output["Ambient Temperature"] = MathROUND(json.temperature,2);
//output["Ambient Humidity"] = MathROUND(json.humidity,2);
//output["Leaf Angle"] = json.angle;
//output["Thickness"] = json.thickness; //json.thickness_raw; 

output["Relative Chlorophyll"] = MathROUND(minolta_spad,2);

output["order"] = ["Relative Chlorophyll"];

//output["order"] = ["Thickness","Phi2","PhiNPQ","PhiNO","Relative Chlorophyll","Leaf Temp Differential", "Light Intensity (PAR)","Ambient Temperature","Ambient Humidity","Leaf Angle"];
return output;
{
  "time_offset": -540,
  "time": 1497939695900,
  "device_name": "MultispeQ",
  "device_version": "1",
  "device_id": "01:12:52:58",
  "device_battery": 38,
  "device_firmware": 1.17,
  "sample": [
    {
      "time": 1497939696002,
      "protocol_id": 1,
      "detector_read1": 7026,
      "detector_read2": 4347,
      "light_intensity": 52,
      "r": 61,
      "g": 24,
      "b": 22,
      "light_intensity_raw": 97,
      "temperature": 30.879999,
      "humidity": 44.901367,
      "pressure": 1005.610413,
      "temperature2": 30.77,
      "humidity2": 45.545898,
      "pressure2": 1005.250488,
      "contactless_temp": 30.28,
      "thickness": 0.37,
      "compass_direction": "E",
      "compass": "90.00",
      "angle": 4.22,
      "angle_direction": "S",
      "pitch": 4.22,
      "roll": 0.17,
      "recall": {
        "time": 1497939727328,
        "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": [
        1669,
        1506,
        1510,
        1508,
        1515,
        1512,
        1508,
        1507,
        1508,
        1519,
        363,
        447,
        443,
        449,
        447,
        447,
        445,
        444,
        449,
        446,
        990,
        1307,
        1305,
        1311,
        1311,
        1311,
        1306,
        1309,
        1312,
        1310,
        119,
        193,
        195,
        191,
        190,
        191,
        193,
        193,
        192,
        191,
        39319,
        11147,
        10864,
        10835,
        10823,
        10815,
        10803,
        10811,
        10797,
        10791,
        65535,
        12058,
        11467,
        11409,
        11392,
        11372,
        11366,
        11371,
        11350,
        11349,
        18869,
        13271,
        13207,
        13202,
        13193,
        13196,
        13194,
        13195,
        13191,
        13187,
        22069,
        13537,
        13427,
        13416,
        13409,
        13412,
        13411,
        13408,
        13406,
        13403,
        10488,
        12580,
        12591,
        12589,
        12591,
        12593,
        12595,
        12595,
        12586,
        12591,
        2122,
        2599,
        2602,
        2598,
        2605,
        2606,
        2606,
        2603,
        2602,
        2606,
        7570,
        9563,
        9571,
        9573,
        9575,
        9576,
        9574,
        9568,
        9573,
        9572,
        622,
        767,
        767,
        771,
        774,
        773,
        769,
        769,
        774,
        771,
        35198,
        45304,
        45409,
        45415,
        45417,
        45421,
        45413,
        45416,
        45417,
        45409,
        38086,
        48877,
        48982,
        48985,
        48992,
        48999,
        48998,
        48997,
        49007,
        49008,
        36262,
        45780,
        45865,
        45877,
        45881,
        45883,
        45875,
        45873,
        45886,
        45883,
        36233,
        46777,
        46880,
        46890,
        46885,
        46882,
        46869,
        46867,
        46874,
        46867,
        41208,
        50576,
        50651,
        50659,
        50657,
        50651,
        50650,
        50647,
        50651,
        50651,
        4638,
        5639,
        5652,
        5657,
        5659,
        5659,
        5654,
        5657,
        5660,
        5658,
        34881,
        48646,
        48755,
        48748,
        48736,
        48723,
        48705,
        48698,
        48692,
        48683,
        2087,
        2790,
        2798,
        2802,
        2803,
        2803,
        2797,
        2802,
        2802,
        2803,
        45419,
        45420,
        45419,
        45418,
        45426,
        45425,
        45415,
        45417,
        45427,
        45419,
        49040,
        48987,
        48998,
        48990,
        48993,
        48991,
        48986,
        48986,
        48995,
        48996,
        45918,
        45909,
        45914,
        45912,
        45913,
        45911,
        45904,
        45905,
        45909,
        45911,
        47036,
        46891,
        46889,
        46886,
        46878,
        46873,
        46864,
        46856,
        46861,
        46851
      ]
    }
  ],
  "app_os": "win",
  "app_name": "PhotosynQ",
  "app_version": "0.3.8",
  "app_device": "x86-64",
  "location": [
    "35.1552268",
    "136.9706446"
  ],
  "ConsoleMacro": "209"
}
Default avatar
Created by

DS


Protocol connections:
1
Latest Update:
Jun 2017