The One v3.0 (Phi2, NPQt, using multi-phase flash) - Hz edition


The One Protocol to rule them all! Phi2, NPQt combined. Changes from previous The One protocol: - Removed the Phi1 measurement, which was producing a lot of invalid data (removed by Dan and Frank) - Implemented the multi-phase flash protocol created by Tom Avenson
var data = json.data_raw;
var output = {};
//output["flag"] = {"info":[],"warning":[],"danger":[]};
var sample_cal = MathMEAN(data.slice(2,18));

var inverse_intensity = [1/692,1/614,1/537,1/460];

// retrieve the baseline information from the data JSON and save (using measuring light 15, calibrating light 14)
//----------------------------
for (i in json.get_ir_baseline) {	
	if (json.get_ir_baseline[i][0] == 15) {
		var slope_light = json.get_ir_baseline[i][1];
		var yint_light = json.get_ir_baseline[i][2];
	}
	if (json.get_ir_baseline[i][0] == 14) {
		var slope_cal = json.get_ir_baseline[i][1];
		var yint_cal = json.get_ir_baseline[i][2];
	}
}

// calculate the baseline
//----------------------------
var shinyness = (sample_cal-yint_cal)/slope_cal; // where 0 is dull black electrical tape, and 1 is shiny aluminum
var baseline = slope_light*shinyness+yint_light;

if (!baseline) {
  baseline = 0;
}

// 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(21,24)) - baseline; // take only the first 4 values in the Fs range, excluding the very first
var Fs_std = MathSTDEV(data.slice(21,24)); // create standard deviation for this value for error checking

var sat_vals = data.slice(45,68).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 checking

sat_vals = data.slice(104,130).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(72,80).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(82,90).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(92,100).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(180,290).sort();
var FoPrime = MathMEAN(FoPrime_values.slice(5,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;


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

// Create the variables to be printed (assume to use the MPF values unless there is a good reason not to)
// ----------------------------
var fvfm = fvfm_MPF
var npqt = npqt_MPF
var PhiNO = PhiNO_MPF
var PhiNPQ = PhiNPQ_MPF
var qL = qL_MPF
var FmPrime = reg.b
/****************OUTPUT VALUES FROM MACRO *******************/

// if any of the flag conditions are true, then create the 'flag' object.  Otherwise, do not create the flag object.
// for now since flag system isn't fully implemented, also create as separate objects so they will be displayed
// ----------------------------

// 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
  npqt = npqt_noMPF
  PhiNO = PhiNO_noMPF
  PhiNPQ = PhiNPQ_noMPF
  qL = qL_noMPF
  FmPrime = AFmP
  
  if (fvfm <= 0) {
    output["Phi2"] 			= 0;
  //  	output.flag.warning.push("Phi2 is negative (should be positive).  It has been set to zero, but check raw trace and consider excluding this point.  To see original negative value, see Phi2_noMPF variable");
    output["warning 2"] = "Phi2 is negative (should be positive).  It has been set to zero, but check raw trace and consider excluding this point.  To see original negative value, see Phi2_noMPF variable";
  }
  if (fvfm >=.85) {
//  	output.flag.danger.push("Phi2 above the normal range (0 - 0.85).  Please check the raw trace and consider excluding this point.");
	output["danger 5"] = "Phi2 above the normal range (0 - 0.85).  Please check the raw trace and consider excluding this point.";
  }
  else {
	  output["Phi2"] 		= MathROUND(fvfm,3);
  }
  
  if (npqt <= 0) {
    output["NPQt"] 			= 0;
//  	output.flag.warning.push("NPQt is negative (should be positive)!  It has been set to zero, but check raw trace and consider excluding this point.  To see original negative NPQt value, see NPQt_noMPF variable");
	output["warning 1"] = "NPQt is negative (should be positive).  It has been set to zero, but check raw trace and consider excluding this point.  To see original negative value, see NPQt_noMPF variable";
  }
  else {
	  output['NPQt']		= MathROUND(npqt,3);
  }
	  output['qL']		    = MathROUND(qL,3);
	  output['PhiNPQ']		= MathROUND(PhiNPQ,3);
	  output['PhiNO']		= MathROUND(PhiNO,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;
//  	output.flag.warning.push("Phi2 is negative (should be positive).  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["warning 2"] = "Phi2 is negative (should be positive).  It has been set to zero, but check raw trace and consider excluding this point.  To see original negative value, see Phi2_MPF variable";
  }
  if (fvfm >=.85) {
//  	output.flag.danger.push("Phi2 above the normal range (0 - 0.85).  Please check the raw trace and consider excluding this point.");
	output["danger 5"] = "Phi2 above the normal range (0 - 0.85).  Please check the raw trace and consider excluding this point.";
  }
  else {
  	output["Phi2"] 			= MathROUND(fvfm,3);
  }
  if (npqt <= 0) {
    output["NPQt"] 			= 0;
//  	output.flag.warning.push("NPQt is negative (should be positive)!  It has been set to zero, but check raw trace and consider excluding this point.  To see original negative NPQt value, see NPQt_MPF variable");
	output["warning 3"] = "NPQt value is negative (should be positive).  It has been set to zero, but check raw trace and consider excluding this point.  To see original negative value, see NPQt_MPF variable";
  }
  else {
	  output['NPQt']		= MathROUND(npqt,3);
  }
	  output['qL']		= MathROUND(qL,3);
	  output['PhiNPQ']		= MathROUND(PhiNPQ,3);
	  output['PhiNO']		= MathROUND(PhiNO,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);
}

output["testOutput"] 		= MathROUND(FmPrime,1);
output["FmPrime"] 		= MathROUND(FmPrime,3);
output["Fs"] 			= MathROUND(Fs,1);
output['FoPrime']		= MathROUND(FoPrime,0);
output["RFd"]           = Number(MathROUND(((FmPrime/Fs)-1),3));
//output["FvPrime/FmPrime"] = Number(MathROUND(((FmPrime-FoPrime)/FmPrime),3)); // effectiveness of open reaction centers PSII
//output["qP"]           = Number(MathROUND(((FmPrime-Fs)/(FmPrime-FoPrime)),3)); //qP - photochemical quenching 
//output["Fm"]           = Number(MathROUND((reg.b),3)); //Fm 

output["Phi2_MPF"] 		= MathROUND(fvfm_MPF,3);
output["Phi2_noMPF"] 	= MathROUND(fvfm,3);
output['ratio adjusted to regular phi2'] = MathROUND(fvfm_MPF / fvfm,5);
output['NPQt_MPF']			= MathROUND(npqt_MPF,3);
output["NPQt_noMPF"] 	= MathROUND(npqt,3);
output['ratio adjusted to regular NPQt'] = MathROUND(npqt_MPF / npqt,5);
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["MPF_slope"] 	= MathROUND(reg.m,3);
output["MPF_rsquared"] 	= MathROUND(reg.r,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 ;

if (baseline != 0) {
  output["baseline"] 	= baseline;
}
else {
  output["baseline"] 	= 0;
}

//if (reg.m > 0 | FmP_end/AFmP - AFmP/AFmP > .1 | FmP_end/AFmP - AFmP/AFmP < -.1) {
//}

// Calculate Standard Deviation for Warning or Danger flags (out of bounds measurement)
// ----------------------------

if (Fs_std > 100	) {
//  	output.flag.danger.push("noisy Fs");
	output["danger 1"] = "noisy Fs";
}
if (AFmP_std > 200) {
//  	output.flag.danger.push("noisy FmPrime");
	output["danger 2"] = "noisy FmPrime";
}
if (FmP_step1_std > 60 | FmP_step2_std > 60 | FmP_step3_std > 60 | FmP_end_std > 200) {
//  	output.flag.danger.push("noisy multi-phase flash steps");
	output["danger 3"] = "noisy  multi-phase flash steps";
}
if (FoPrime_std > 150) {
//  	output.flag.danger.push("noisy FoPrime");
	output["danger 4"] = "noisy FoPrime";
}

if (reg.m > 0) {
//	output.flag.info.push("Used Phi2 and not Phi2 MPF - ambient light level was too low to apply MPF calculation");
	output["info 1"] = "Used Phi2 and not Phi2 MPF - ambient light level was too low to apply MPF calculation";
}

if (FmP_end/AFmP - AFmP/AFmP > .1) {
//	output.flag.info.push("FmPrime slopes down.  This may mean that saturating flash is not bright enough... consider using a protocol with lower saturating lightf on these samples");
	output["info 2"] = "FmPrime slopes down.  This may mean that saturating flash is not bright enough... consider using a protocol with lower saturating light on these samples";
}

if (FmP_end/AFmP - AFmP/AFmP < -.1) {
//	output.flag.info.push("FmPrime slopes up.  This may mean that saturating flash is too bright... consider using a protocol with higher saturating light on these samples");
	output["info 3"] = "FmPrime slopes up.  This may mean that saturating flash is too bright... consider using a protocol with higher saturating light on these samples";
}



return output;
{
  "sample": [
    [
      {
        "protocol_id": 1,
        "g": 341,
        "get_ir_baseline": [
          [
            15,
            139.85,
            233.2
          ],
          [
            14,
            5465.04,
            6387.31
          ]
        ],
        "time": "1439974223289",
        "b": 316,
        "r": 780,
        "relative_humidity": 35.47,
        "data_raw": [
          4136,
          4162,
          4109,
          4129,
          4178,
          4072,
          4115,
          4140,
          4134,
          4034,
          4073,
          4106,
          4162,
          4049,
          4119,
          4156,
          4069,
          4095,
          4158,
          4152,
          4543,
          4553,
          4549,
          4591,
          4590,
          4595,
          4576,
          4611,
          4597,
          4592,
          4593,
          4602,
          4612,
          4605,
          4612,
          4621,
          4616,
          4625,
          4608,
          4598,
          12731,
          14806,
          15528,
          15890,
          16210,
          16519,
          16750,
          16940,
          17061,
          17173,
          17264,
          17310,
          17342,
          17352,
          17368,
          17371,
          17378,
          17388,
          17367,
          17361,
          17363,
          17348,
          17317,
          17319,
          17295,
          17325,
          17312,
          17286,
          17285,
          17267,
          17222,
          17228,
          17248,
          17213,
          17223,
          17201,
          17206,
          17196,
          17173,
          17189,
          17157,
          17133,
          17151,
          17120,
          17141,
          17125,
          17102,
          17100,
          17078,
          17096,
          17030,
          17039,
          17017,
          17001,
          17032,
          17017,
          17012,
          17014,
          17047,
          16998,
          17070,
          17137,
          17045,
          17072,
          17046,
          17035,
          17063,
          17034,
          16999,
          17035,
          17017,
          17048,
          16990,
          16994,
          17010,
          16979,
          16994,
          16983,
          16963,
          16985,
          16966,
          16938,
          16965,
          16964,
          16955,
          16966,
          16921,
          16913,
          16911,
          16938,
          16900,
          11909,
          9831,
          8673,
          7977,
          7562,
          7267,
          7081,
          6953,
          6864,
          6776,
          6715,
          6628,
          6617,
          6575,
          6540,
          6477,
          6459,
          6435,
          6396,
          6179,
          4871,
          4806,
          4736,
          4701,
          4679,
          4637,
          4614,
          4591,
          4592,
          4588,
          4566,
          4559,
          4554,
          4543,
          4532,
          4512,
          4528,
          4523,
          4506,
          4478,
          4487,
          4497,
          4514,
          4493,
          4501,
          4481,
          4481,
          4479,
          4494,
          4494,
          4505,
          4496,
          4485,
          4495,
          4475,
          4481,
          4478,
          4505,
          4484,
          4489,
          4486,
          4487,
          4480,
          4486,
          4495,
          4470,
          4495,
          4486,
          4491,
          4504,
          4479,
          4506,
          4479,
          4509,
          4506,
          4498,
          4528,
          4510,
          4500,
          4502,
          4529,
          4512,
          4517,
          4490,
          4516,
          4499,
          4508,
          4517,
          4529,
          4540,
          4543,
          4516,
          4535,
          4521,
          4539,
          4508,
          4512,
          4542,
          4541,
          4527,
          4520,
          4523,
          4527,
          4539,
          4532,
          4535,
          4519,
          4526,
          4529,
          4514,
          4528,
          4512,
          4525,
          4519,
          4533,
          4523,
          4519,
          4515,
          4529,
          4535,
          4540,
          4535,
          4519,
          4536,
          4525,
          4522,
          4541,
          4538,
          4533,
          4520,
          4539,
          4530,
          4532,
          4541,
          4535,
          4524,
          4537,
          4538,
          4530,
          4537,
          4536,
          4539,
          4538,
          4552,
          4523,
          4520,
          4550,
          4534,
          4532,
          4541,
          4529,
          4504,
          4551,
          4513,
          4548,
          4523,
          4572,
          4534,
          4539,
          4540,
          4532,
          4539,
          4525,
          4551,
          4544,
          4514,
          4532,
          4533,
          4552,
          4034,
          4106,
          4123,
          4060,
          4116,
          4079,
          4066,
          4099,
          4007,
          4147,
          4088,
          4057,
          4158,
          4078,
          4066,
          4060,
          4110,
          4156,
          4117,
          4122,
          3847,
          3923,
          3944,
          3979,
          3995,
          4030,
          4062,
          4087,
          4125,
          4146,
          4165,
          4205,
          4204,
          4235,
          4245,
          4286,
          4274,
          4293,
          4323,
          4339,
          4351,
          13785,
          14880,
          15168,
          15450,
          15751,
          16102,
          16441,
          16714,
          16957,
          17121,
          17232,
          17288,
          17350,
          17358,
          17387,
          17404,
          17374,
          17394,
          17404,
          17402,
          17392,
          17402,
          17378,
          17368,
          17388,
          17386,
          17359,
          17371,
          17364,
          17389,
          17350,
          17331,
          17327,
          17340,
          17308,
          17314,
          17326,
          17312,
          17309,
          17292,
          17294,
          17287,
          17276,
          17294,
          17285,
          17294,
          17250,
          17239,
          17280,
          17221,
          17219,
          17231,
          17230,
          17245,
          17258,
          17221,
          17193,
          17192,
          17209,
          17250,
          17208,
          17205,
          17205,
          17195,
          17191,
          17171,
          17154,
          17159,
          17131,
          17125,
          17128,
          17133,
          17100,
          17106,
          17063,
          17069,
          17073,
          17051,
          17052,
          17041,
          17041,
          17044,
          17033,
          17015,
          17035,
          17004,
          17014,
          17029,
          17006,
          16988,
          12377,
          10810,
          9944,
          9429,
          9073,
          8792,
          8594,
          8427,
          8306,
          8188,
          8082,
          7969,
          7901,
          7839,
          7743,
          7659,
          7599,
          7546,
          7501,
          7351,
          4630,
          4589,
          4533,
          4487,
          4469,
          4458,
          4427,
          4411,
          4415,
          4390,
          4367,
          4382,
          4379,
          4376,
          4388,
          4351,
          4348,
          4339,
          4338,
          4328,
          4315,
          4314,
          4312,
          4312,
          4317,
          4329,
          4317,
          4327,
          4323,
          4339,
          4315,
          4324,
          4322,
          4325,
          4321,
          4313,
          4321,
          4296,
          4315,
          4310,
          4322,
          4337,
          4332,
          4330,
          4325,
          4350,
          4314,
          4317,
          4313,
          4327,
          4322,
          4306,
          4317,
          4327,
          4304,
          4297,
          4301,
          4313,
          4310,
          4297,
          4323,
          4320,
          4329,
          4299,
          4330,
          4322,
          4298,
          4294,
          4314,
          4303,
          4298,
          4304,
          4302,
          4300,
          4349,
          4309,
          4313,
          4298,
          4330,
          4299,
          4315,
          4291,
          4310,
          4299,
          4326,
          4309,
          4315,
          4323,
          4299,
          4334,
          4290,
          4317,
          4305,
          4330,
          4316,
          4357,
          4327,
          4316,
          4329,
          4324,
          4298,
          4321,
          4310,
          4318,
          4306,
          4333,
          4300,
          4315,
          4320,
          4307,
          4319,
          4329,
          4297,
          4316,
          4313,
          4288,
          4302,
          4298,
          4298,
          4300,
          4297,
          4311,
          4281,
          4302,
          4297,
          4323,
          4300,
          4305,
          4286,
          4318,
          4321,
          4309,
          4289,
          4307,
          4311,
          4292,
          4291,
          4292,
          4302,
          4303,
          4302,
          4314,
          4302,
          4309,
          4310,
          4308,
          4310,
          4311,
          4303
        ],
        "temperature": 31.31,
        "light_intensity": 1201
      }
    ]
  ],
  "location": "-14.2599624,34.5787035",
  "firmware_version": "0.420",
  "time": 1439974223256,
  "device_id": "75"
}

Protocol connections:
0
Latest Update:
Dec 2016