v1 Fv/Fm calc from LP RG - hugh SP intensity


includes ECS, Phi2, and other similar protocols.
// CALCULATIONS FOR PROTON MOTIVE FORCE VIA ECS PORTION OF THE TRACE
//----------------------------

var output = {};
var spad;
var data = json.data_raw;
var vhplus;
var tau;
var ECSt;
var quality_flag = 0;
var i = 0;
var j = 0;
var h = 0;
var k = 0;
var smooth1 = data.slice(300,600);
var smooth0 = data.slice(300,600);

///*

// CALCULATIONS FOR PHI2 PORTION OF THE TRACE
//----------------------------

// calculate the ir baseline for LED 3 which is used as the measuring light.  This subtract IR generated by the LED from the IR generated by the plant
//----------------------------
var sample_cal = json.detector_read1;//es para la luz 940

var shinyness = (sample_cal-json.recall["ir_baseline_yint[5]"])/json.recall["ir_baseline_slope[5]"]; // where 0 is dull black electrical tape, and 1 is shiny aluminum
var baseline = json.recall["ir_baseline_slope[3]"]*shinyness+json.recall["ir_baseline_yint[3]"];

if (!baseline || !json.recall["ir_baseline_yint[5]"] || sample_cal == 65535) {						// if it hasn't been calibrated or there's an error or it's maxed, set baseline == 0
  baseline = 0;
}

/*
output["shinyness"] = shinyness;
output["baseline"] = baseline;
output["recall led slope"] = json.recall["ir_baseline_slope[3]"];
output["recall led yint"] = json.recall["ir_baseline_yint[3]"];
output["recall cal slope"] = json.recall["ir_baseline_slope[5]"];
output["recall cal yint"] = json.recall["ir_baseline_yint[5]"];
output["sample led"] = json.detector_read1;
*/

//var sample_cal = MathMEAN(data.slice(2,18));

var inverse_intensity = [1/6000,1/5500,1/5000,1/4700];
var ps2_starts = 0; // when does the Phi2 measurement start - usando el nuevo protocolo

// Set our Apparent FmPrime, 3 FmPrime steps, and Fs to calculate both traditional fv/fm and new Multi-phase flash fv/fm
//----------------------------
var Fs = MathMEAN(data.slice(ps2_starts + 1,ps2_starts + 4)) - baseline; // take only the first 4 values in the Fs range, excluding the very first
var Fs_std = MathSTDEV(data.slice(ps2_starts + 1,ps2_starts + 4)); // create standard deviation for this value for error checking

var sat_vals = data.slice(ps2_starts + 25,ps2_starts + 48).sort();  // sort the saturating light values from low to high
var AFmP = MathMEAN(sat_vals.slice(2,20)) - baseline; // take the 18 largest values and average them
var AFmP_std = MathSTDEV(sat_vals); // create standard deviation for this value for error checkingjson.data_raw.slice(953,955)

sat_vals = data.slice(ps2_starts + 84,ps2_starts + 110).sort();  // sort the saturating light values from low to high
var FmP_end = MathMEAN(sat_vals.slice(2,23)) - baseline; // take the 21 largest values and average them
var FmP_end_std = MathSTDEV(sat_vals); // create standard deviation for this value for error checking

sat_vals = data.slice(ps2_starts + 52,ps2_starts + 60).sort();  // sort the saturating light values from low to high
var FmP_step1 = MathMEAN(sat_vals.slice(2,6)) - baseline; // take the 4 largest values and average them
var FmP_step1_std = MathSTDEV(sat_vals); // create standard deviation for this value for error checking

sat_vals = data.slice(ps2_starts + 62,ps2_starts + 70).sort();  // sort the saturating light values from low to high
var FmP_step2 = MathMEAN(sat_vals.slice(2,6)) - baseline; // take the 4 largest values and average them
var FmP_step2_std = MathSTDEV(sat_vals); // create standard deviation for this value for error checking

sat_vals = data.slice(ps2_starts + 72,ps2_starts + 80).sort();  // sort the saturating light values from low to high
var FmP_step3 = MathMEAN(sat_vals.slice(2,6)) - baseline; // take the 4 largest values and average them
var FmP_step3_std = MathSTDEV(sat_vals); // create standard deviation for this value for error checking

// Calculations for F0'
// ----------------------------
var FoPrime_values = json.data_raw.slice(131,200).sort();
var FoPrime = MathMEAN(FoPrime_values.slice(2,10)) - baseline;
var FoPrime_std = MathSTDEV(FoPrime_values); // create standard deviation for this value for error checking

// Calculations for corrected FmPrime using multi-phase flash
// ----------------------------
var reg = MathLINREG(inverse_intensity, [AFmP,FmP_step1,FmP_step2,FmP_step3]);

// Calculate Phi2 w/ and w/out multi-phase flash
// ----------------------------
var fvfm_noMPF = (AFmP-Fs)/AFmP;
var fvfm_MPF = (reg.b-Fs)/reg.b;
var fvfm = fvfm_MPF;
var FmPrime = reg.b;

/*
// Calculate NPQt, PhiNPQ, PhiNO, qL w/ and w/out multi-phase flash
// ----------------------------
var npqt_MPF = (4.88 / ((reg.b / FoPrime) -1) )-1;
var npqt_noMPF = (4.88 / ((AFmP / FoPrime) -1) )-1;
var qL_MPF = ((reg.b - Fs)*FoPrime)/((reg.b-FoPrime)*Fs);
var qL_noMPF = ((AFmP - Fs)*FoPrime)/((AFmP-FoPrime)*Fs);
var PhiNO_MPF = 1/(npqt_MPF + 1 + qL_MPF*4.88); //based on equation 52 in Kramer et al., 2004 PRES
var PhiNO_noMPF = 1/(npqt_noMPF + 1 + qL_noMPF*4.88); //based on equation 52 in Kramer et al., 2004 PRES
var PhiNPQ_MPF = 1-fvfm_MPF-PhiNO_MPF; //based on equation 53 in Kramer et al., 2004 PRES 
var PhiNPQ_noMPF = 1-fvfm_noMPF-PhiNO_noMPF; //based on equation 53 in Kramer et al., 2004 PRES 

var qP_MPF = (reg.b - Fs)/(reg.b - FoPrime);
var qP_noMPF = (FmPrime - Fs)/(FmPrime - FoPrime);
var FvP_FmP_MPF = (reg.b-FoPrime)/reg.b;
var FvP_FmP_noMPF = (AFmP-FoPrime)/AFmP;

// Create the variables to be printed (assume to use the MPF values unless there is a good reason not to)
// ----------------------------

var b = json.b;
var r = json.r;
var g = json.g;

*/
/****************OUTPUT VALUES FROM MACRO *******************/

// If multi-phase flash steps are flat or positive slope, then just use the normal Phi2, NPQt, PhiNPQ, PhiNO... etc.
// If Phi2 or NPQt is less than zero, make zero and give user warning.  If Phi2 is higher than .85, give user danger flag.
// ----------------------------


if (reg.m > 0) {
  fvfm = fvfm_noMPF;
}
  else {
    output["Phi2"]= MathROUND(fvfm,3);
  }
 /* 
  if (npqt <= 0) {
	output["PhiNPQ"]		= 0;
    output["NPQt"]			= 0;
	warning("NPQt is negative (should be positive).  This may be due to a sample that is not doing photosynthesis, or you may have missed the leaf.  It has been set to zero, but check raw trace and consider excluding this point.  To see original negative value, see NPQt_noMPF and PhiNPQ_noMPF variable",output);
	output["PhiNPQ_noMPF"]  = MathROUND(PhiNPQ,3);
	output["NPQt_noMPF"]	= MathROUND(npqt,3);
  }
  else {
	output["PhiNPQ"]  = MathROUND(PhiNPQ,3);
	output["NPQt"]		= MathROUND(npqt,3);
  }
	output["PhiNO"]		= MathROUND(PhiNO,3);
	output["qL"]		= MathROUND(qL,3);
    output['FvP/FmP']		= MathROUND(FvP_FmP,3);
    output['qP']			= MathROUND(qP,3);
}

// Otherwise, use the multi-phase flash calculation for Phi2, NPQt, PhiNPQ, PhiNO... etc.
// If Phi2 or NPQt is less than zero, make zero and give user warning.  If Phi2 is higher than .85, give user danger flag.
// ----------------------------
else {
  if (fvfm <= 0) {
    output["Phi2"] 			= 0;
	warning("Phi2 is negative (should be positive).  This may be due to a sample that is not doing photosynthesis, or you may have missed the leaf.  It has been set to zero, but check raw trace and consider excluding this point.  To see original negative value, see Phi2_MPF variable",output);
	output["Phi2_MPF"] 	= MathROUND(npqt,3);
  }
  if (fvfm >=.85) {
    output["Phi2"] 			= -1;
	danger("Phi2 above the normal range (0 - 0.85).  Please check the raw trace and seriously consider excluding this point.", output);
  }
  else {
    output["Phi2"]			= MathROUND(fvfm,3);
  }
  if (npqt <= 0) {
	output["PhiNPQ"]		= 0;
    output["NPQt"]			= 0;
	warning("NPQt is negative (should be positive).  This may be due to a sample that is not doing photosynthesis, or you may have missed the leaf.  It has been set to zero, but check raw trace and consider excluding this point.  To see original negative value, see NPQt_MPF and PhiNPQ_MPF variables",output);
	output["PhiNPQ_MPF"]  = MathROUND(PhiNPQ,3);
	output["NPQt_MPF"]		= MathROUND(npqt,3);
  }
  else {
	output["PhiNPQ"]  = MathROUND(PhiNPQ,3);
	output["NPQt"]		= MathROUND(npqt,3);
  }
	output["PhiNO"]		= MathROUND(PhiNO,3);
	output["qL"]			= MathROUND(qL,3);
    output['FvP/FmP']		= MathROUND(FvP_FmP,3);
    output['qP']			= MathROUND(qP,3);
}

// only display LEF if there is a light intensity measurement > 0 
// ----------------------------
if (typeof json.light_intensity != "undefined" && json.light_intensity > 0) {
	output["LEF"] 		= MathROUND((fvfm  * 0.45 * json.light_intensity),3);
}

if (Fs_std > 100) {
	danger("noisy Fs", output);
}


if (AFmP_std > 300) {
	danger("noisy FmPrime", output);
}


if (FmP_step1_std > 120 | FmP_step2_std > 120 | FmP_step3_std > 120 | FmP_end_std > 300) {
	danger("noisy  multi-phase flash steps",output);
}

if (FoPrime_std > 150) {
	danger("noisy FoPrime", output);
}

if (reg.m > 0) {
	info("Used Phi2 and not Phi2 MPF - ambient light level was too low to apply MPF calculation", output);
}
if (FmP_end/AFmP - AFmP/AFmP > .1) {	
	info("FmPrime slopes down.  This may mean that saturating flash is not bright enough... consider using a protocol with lower saturating light on these samples", output);
}
if (FmP_end/AFmP - AFmP/AFmP < -.1) {
	info("FmPrime slopes up.  This may mean that saturating flash is too bright... consider using a protocol with higher saturating light on these samples",output);
}
*/
output["Fv/Fm"] 		= MathROUND(fvfm_MPF,3);

output["FmPrime"] = MathROUND(FmPrime,3);
output["Fs"] = MathROUND(Fs,1);
output['FoPrime']= MathROUND(FoPrime,0);
/*output["RFd"]           = Number(MathROUND(((FmPrime/Fs)-1),3));
output["ratio MPF/noMPF, Phi2"] = MathROUND(fvfm_MPF / fvfm_noMPF,5);
output["ratio MPF/noMPF, PhiNPQ"] = MathROUND(PhiNPQ_MPF / PhiNPQ_noMPF,5);
output["ratio MPF/noMPF, PhiNO"] = MathROUND(PhiNO_MPF / PhiNO_noMPF,5);
output["ratio MPF/noMPF, PhiNO"] = MathROUND(npqt_MPF / npqt_noMPF,5);
output["MPF_slope"] 	= MathROUND(reg.m,3);
output["MPF_rsquared"] 	= MathROUND(reg.r,3);


output["Phi2_noMPF"] 	= MathROUND(fvfm,3);
output["FmPrime_MPF"] 	= MathROUND(reg.b,3);
output["FmPrime_noMPF"] = MathROUND(AFmP,1);
output['qL_MPF']		= MathROUND(qL_MPF,3);
output['qL_noMPF']      = MathROUND(qL,3);
output['PhiNPQ_MPF']    = MathROUND(PhiNPQ_MPF,3);
output['PhiNPQ_noMPF']  = MathROUND(PhiNPQ,3);
output['PhiNO_MPF']		= MathROUND(PhiNO_MPF,3);
output['PhiNO_noMPF']	= MathROUND(PhiNO,3);
output["Fs_std"] 			= MathROUND(Fs_std,1);
output["AFmP_std"] 			= MathROUND(AFmP_std,1);
output["FmP_step1_std"] 	= MathROUND(FmP_step1_std,1);
output["FmP_step2_std"] 	= MathROUND(FmP_step2_std,1);
output["FmP_step3_std"] 	= MathROUND(FmP_step3_std,1);
output["FmP_end_std"] 		= MathROUND(FmP_end_std,1);
output["FoPrime_std"] 			= MathROUND(FoPrime_std,1);
*/

//output["FmP_step1"] = MathROUND(FmP_step1,3);
//output["FmP_step2"] = MathROUND(FmP_step2,3);
//output["FmP_step3"] = MathROUND(FmP_step3,3);
//output["intensity inverse"] = inverse_intensity;
//output["steps"] = [AFmP,FmP_step1,FmP_step2,FmP_step3];
//output["slopey"] = FmP_end/AFmP - AFmP/AFmP ;

 

// Check for data quality issues and add warning or danger flags
//----------------------------

// 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["Ambient Temperature"] = json.temperature;
output["Ambient Humidity"] = json.humidity;

output["baseline"] 	= baseline;
//output["Leaf Angle"] = json.angle;

//output["order"] = ["Phi2","PhiNPQ","PhiNO","Relative Chlorophyll","Leaf Temp Differential","Leaf Angle", "Light Intensity (PAR)","Ambient Temperature","Ambient Humidity","ECSt","vH+","gH+"];

//maxvalue = MathMAX([json.r,json.g,json.b]);
//output["R"] = Number(json.r);
//output["G"] = Number(json.g);
//output["B"] = Number(json.b);
//output["rval"] = json.r*(255/maxvalue);
//output["gval"] = json.g*(255/maxvalue);
//output["bval"] = json.b*(255/maxvalue);

//output["Color"] = [MathROUND(json.r*(255/maxvalue),2),MathROUND(json.g*(255/maxvalue),2),MathROUND(json.b*(255/maxvalue),2)];

return output;
{
  "time_offset": 180,
  "time": 1495483578018,
  "device_name": "MultispeQ",
  "device_version": "1",
  "device_id": "01:06:11:88",
  "device_battery": 21,
  "device_firmware": 1.17,
  "sample": [
    {
      "time": 1495483578107,
      "protocol_id": 1,
      "detector_read1": 8582,
      "light_intensity": 5,
      "r": 4,
      "g": 2,
      "b": 1,
      "light_intensity_raw": 6,
      "temperature": 25.17,
      "humidity": 46.24707,
      "pressure": 1011.721558,
      "temperature2": 25.43,
      "humidity2": 45.152344,
      "pressure2": 1012.032043,
      "contactless_temp": 24.71,
      "thickness": 0.16,
      "compass_direction": "E",
      "compass": "90.00",
      "angle": 3.22,
      "angle_direction": "E",
      "pitch": 0.86,
      "roll": 3.1,
      "recall": {
        "time": 1495483585926,
        "colorcal_blank1[1]": 16511.5,
        "colorcal_blank1[2]": 24324.5,
        "colorcal_blank1[3]": 29277.5,
        "colorcal_blank1[4]": 37138,
        "colorcal_blank1[6]": 33194,
        "colorcal_blank1[8]": 28720.5,
        "colorcal_blank1[9]": 31100,
        "colorcal_blank1[10]": 34614,
        "colorcal_blank2[1]": 21662,
        "colorcal_blank2[2]": 18077,
        "colorcal_blank2[3]": 21188.5,
        "colorcal_blank2[4]": 18162,
        "colorcal_blank2[6]": 16493.5,
        "colorcal_blank2[8]": 17087,
        "colorcal_blank2[9]": 18622,
        "colorcal_blank2[10]": 16523.5,
        "colorcal_blank3[1]": 20515.5,
        "colorcal_blank3[2]": 9866,
        "colorcal_blank3[3]": 19621.5,
        "colorcal_blank3[4]": 13418.5,
        "colorcal_blank3[6]": 5898.5,
        "colorcal_blank3[8]": 6295.5,
        "colorcal_blank3[9]": 5582,
        "colorcal_blank3[10]": 6047,
        "colorcal_intensity1_slope[2]": 2.309,
        "colorcal_intensity1_yint[2]": 1.7,
        "colorcal_intensity2_slope[2]": 2.377,
        "colorcal_intensity2_yint[2]": 3,
        "colorcal_intensity3_slope[2]": 2.554,
        "colorcal_intensity3_yint[2]": -17.299999,
        "ir_baseline_slope[5]": 8895,
        "ir_baseline_yint[5]": 13422.5,
        "ir_baseline_slope[3]": 526.5,
        "ir_baseline_yint[3]": 738.5
      },
      "data_raw": [
        5718,
        5794,
        5863,
        5923,
        5970,
        6027,
        6071,
        6117,
        6161,
        6193,
        6231,
        6256,
        6295,
        6326,
        6348,
        6374,
        6389,
        6418,
        6435,
        6457,
        18323,
        20978,
        21967,
        22327,
        22470,
        22556,
        22595,
        22629,
        22644,
        22657,
        22679,
        22694,
        22711,
        22727,
        22740,
        22759,
        22775,
        22789,
        22817,
        22827,
        22838,
        22859,
        22873,
        22891,
        22897,
        22919,
        22928,
        22933,
        22955,
        22964,
        22982,
        22999,
        23009,
        23019,
        23015,
        23035,
        23038,
        23047,
        23051,
        23057,
        23073,
        23071,
        23078,
        23083,
        23082,
        23081,
        23085,
        23085,
        23082,
        23078,
        23089,
        23088,
        23084,
        23087,
        23083,
        23079,
        23068,
        23074,
        23071,
        23067,
        23015,
        23015,
        23009,
        23001,
        22989,
        22991,
        22987,
        22983,
        22975,
        22961,
        22960,
        22959,
        22951,
        22947,
        22939,
        22938,
        22928,
        22923,
        22918,
        22911,
        22901,
        22903,
        22898,
        22892,
        22885,
        22876,
        22876,
        22871,
        22866,
        22861,
        20971,
        19473,
        18317,
        17391,
        16655,
        16049,
        15563,
        15149,
        14790,
        14491,
        14219,
        13979,
        13762,
        13568,
        13385,
        13211,
        13062,
        12921,
        12775,
        12659,
        9861,
        9476,
        9296,
        9151,
        9027,
        8932,
        8846,
        8763,
        8697,
        8637,
        8583,
        8531,
        8486,
        8450,
        8416,
        8382,
        8353,
        8314,
        8290,
        8271,
        8250,
        8231,
        8209,
        8186,
        8173,
        8165,
        8153,
        8142,
        8135,
        8117,
        8113,
        8107,
        8099,
        8095,
        8085,
        8078,
        8080,
        8077,
        8074,
        8073,
        8065,
        8059,
        8064,
        8059,
        8060,
        8059,
        8052,
        8055,
        8059,
        8055,
        8055,
        8052,
        8047,
        8050,
        8052,
        8055,
        8055,
        8045,
        8050,
        8054,
        8059,
        8056,
        8053,
        8053,
        8059,
        8058,
        8063,
        8064,
        8059,
        8062,
        8064,
        8069,
        8068,
        8063,
        8067,
        8069,
        8071,
        8073,
        8067,
        8070,
        8075,
        8075,
        8076,
        8073,
        8074,
        8080,
        8085,
        8084,
        8080,
        8088,
        8087,
        8090,
        8091,
        8087,
        8092,
        8095,
        8097,
        8094,
        8095,
        8100,
        8100,
        8103,
        8099,
        8101,
        8108,
        8107,
        8108,
        8103,
        8112,
        8115,
        8117,
        8109,
        8112,
        8118,
        8118,
        8121,
        8114,
        8122,
        8125,
        8127,
        8119,
        8123,
        8127,
        8129,
        8128,
        8127,
        8133,
        8134,
        8136,
        8130,
        8136,
        8137,
        8138,
        8135,
        8136,
        8144,
        8145,
        8146,
        8140,
        8147,
        8148,
        8153,
        8147,
        8152,
        8154,
        8157,
        8153,
        8158,
        8157,
        8163
      ]
    }
  ],
  "app_os": "win",
  "app_name": "PhotosynQ",
  "app_version": "0.3.7",
  "app_device": "x86-32",
  "location": [
    "-32.9700549",
    "-60.6247549"
  ]
}
Img 20171030 190259
Created by

Rodrigo Gomez


Protocol connections:
1
Latest Update:
May 2017