Chl Fl 1500,2000 umol JRP v1.0


for use with PHi2_protocal_1500, 2000
//============================================
// Macro for data evaluation on PhotosynQ.org
// created: 7/18/2017
//============================================






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


var inverse_intensity = [1/4500,1/4050,1/3600,1/3150];


//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;
//}
baseline = 0;



//    -----------------------------  //
//    -----------------------------  //
//    -----------------------------  //
//        ps2_1500  
//    -----------------------------  //
//    -----------------------------  //
//    -----------------------------  //
var ps2_1500_start = 150; // when does the Phi2 measurement start - usando el nuevo protocolo
// Set our Apparent Fm_1500_Prime, 3 Fm_1500_Prime steps, and Fs_1500 to calculate both traditional fv/fm and new Multi-phase flash fv/fm
//----------------------------
var Fs_1500 = MathMEAN(data.slice(ps2_1500_start + 1,ps2_1500_start + 4)) - baseline; // take only the first 4 values in the Fs range, excluding the very first
var Fs_1500_std = MathSTDEV(data.slice(ps2_1500_start + 1,ps2_1500_start + 4)); // create standard deviation for this value for error checking

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

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

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

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

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

// Calculations for F0'
// ----------------------------
var Fo_1500_Prime_1500_values = json.data_raw.slice(ps2_1500_start + 160,ps2_1500_start + 270).sort();
var Fo_1500_Prime = MathMEAN(Fo_1500_Prime_1500_values.slice(5,10)) - baseline;
var Fo_1500_Prime_std = MathSTDEV(Fo_1500_Prime_1500_values); // create standard deviation for this value for error checking

// Calculations for corrected Fm_1500_Prime using multi-phase flash
// ----------------------------
var reg_1500 = MathLINREG(inverse_intensity, [A0FmP,Fm_1500_P_step1,Fm_1500_P_step2,Fm_1500_P_step3]);

// Calculate Phi2 w/ and w/out multi-phase flash
// ----------------------------
var fv_1500_fm_noMPF = (A0FmP-Fs_1500)/A0FmP;
var fv_1500_fm_MPF = (reg_1500.b-Fs_1500)/reg_1500.b;


// Calculate NPQt,PhiNPQ_1500, PhiNO_1500, qL w/ and w/out multi-phase flash
// ----------------------------
var npqt_1500_MPF = (4.88 / ((reg_1500.b / Fo_1500_Prime) -1) )-1;
var npqt_1500_noMPF = (4.88 / ((A0FmP / Fo_1500_Prime) -1) )-1;
var qL_1500_MPF = ((reg_1500.b - Fs_1500)*Fo_1500_Prime)/((reg_1500.b-Fo_1500_Prime)*Fs_1500);
var qL_1500_noMPF = ((A0FmP - Fs_1500)*Fo_1500_Prime)/((A0FmP-Fo_1500_Prime)*Fs_1500);
var PhiNO_1500_MPF = 1/(npqt_1500_MPF + 1 + qL_1500_MPF*4.88); //based on equation 52 in Kramer et al., 2004 PRES
var PhiNO_1500_noMPF = 1/(npqt_1500_noMPF + 1 + qL_1500_noMPF*4.88); //based on equation 52 in Kramer et al., 2004 PRES
var PhiNPQ_1500_MPF = 1-fv_1500_fm_MPF-PhiNO_1500_MPF; //based on equation 53 in Kramer et al., 2004 PRES 
var PhiNPQ_1500_noMPF = 1-fv_1500_fm_noMPF-PhiNO_1500_noMPF; //based on equation 53 in Kramer et al., 2004 PRES 

var qP_1500_MPF = (reg_1500.b - Fs_1500)/(reg_1500.b - Fo_1500_Prime);
var qP_1500_noMPF = (Fm_1500_Prime - Fs_1500)/(Fm_1500_Prime - Fo_1500_Prime);
var FvP_Fm_1500_P_MPF = (reg_1500.b-Fo_1500_Prime)/reg_1500.b;
var FvP_Fm_1500_P_noMPF = (A0FmP-Fo_1500_Prime)/A0FmP;

// Create the variables to be printed (assume to use the MPF values unless there is a good reason not to)
// ----------------------------
var fv_1500_fm = fv_1500_fm_MPF;
var npqt_1500  = npqt_1500_MPF;
var PhiNO_1500 = PhiNO_1500_MPF;
var PhiNPQ_1500 = PhiNPQ_1500_MPF;
var qL_1500 = qL_1500_MPF;
var Fm_1500_Prime = reg_1500.b;
var qP_1500 = qP_1500_MPF;
var FvP_Fm_1500_P = FvP_Fm_1500_P_MPF;
var b = json.b;
var r = json.r;
var g = json.g;



//    -----------------------------  //
//    -----------------------------  //
//    -----------------------------  //
//        ps2_2000  
//    -----------------------------  //
//    -----------------------------  //
//    -----------------------------  //
var ps2_2000_start = 430; // when does the Phi2 measurement start - usando el nuevo protocolo
// Set our Apparent Fm_2000_Prime, 3 Fm_2000_Prime steps, and Fs_2000 to calculate both traditional fv/fm and new Multi-phase flash fv/fm
//----------------------------
var Fs_2000 = MathMEAN(data.slice(ps2_2000_start + 1,ps2_2000_start + 4)) - baseline; // take only the first 4 values in the Fs range, excluding the very first
var Fs_2000_std = MathSTDEV(data.slice(ps2_2000_start + 1,ps2_2000_start + 4)); // create standard deviation for this value for error checking

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

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

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

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

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

// Calculations for F0'
// ----------------------------
var Fo_2000_Prime_2000_values = json.data_raw.slice(ps2_2000_start + 160,ps2_2000_start + 270).sort();
var Fo_2000_Prime = MathMEAN(Fo_2000_Prime_2000_values.slice(5,10)) - baseline;
var Fo_2000_Prime_std = MathSTDEV(Fo_2000_Prime_2000_values); // create standard deviation for this value for error checking

// Calculations for corrected Fm_2000_Prime using multi-phase flash
// ----------------------------
var reg_2000 = MathLINREG(inverse_intensity, [A0FmP,Fm_2000_P_step1,Fm_2000_P_step2,Fm_2000_P_step3]);

// Calculate Phi2 w/ and w/out multi-phase flash
// ----------------------------
var fv_2000_fm_noMPF = (A0FmP-Fs_2000)/A0FmP;
var fv_2000_fm_MPF = (reg_2000.b-Fs_2000)/reg_2000.b;


// Calculate NPQt,PhiNPQ_2000, PhiNO_2000, qL w/ and w/out multi-phase flash
// ----------------------------
var npqt_2000_MPF = (4.88 / ((reg_2000.b / Fo_2000_Prime) -1) )-1;
var npqt_2000_noMPF = (4.88 / ((A0FmP / Fo_2000_Prime) -1) )-1;
var qL_2000_MPF = ((reg_2000.b - Fs_2000)*Fo_2000_Prime)/((reg_2000.b-Fo_2000_Prime)*Fs_2000);
var qL_2000_noMPF = ((A0FmP - Fs_2000)*Fo_2000_Prime)/((A0FmP-Fo_2000_Prime)*Fs_2000);
var PhiNO_2000_MPF = 1/(npqt_2000_MPF + 1 + qL_2000_MPF*4.88); //based on equation 52 in Kramer et al., 2004 PRES
var PhiNO_2000_noMPF = 1/(npqt_2000_noMPF + 1 + qL_2000_noMPF*4.88); //based on equation 52 in Kramer et al., 2004 PRES
var PhiNPQ_2000_MPF = 1-fv_2000_fm_MPF-PhiNO_2000_MPF; //based on equation 53 in Kramer et al., 2004 PRES 
var PhiNPQ_2000_noMPF = 1-fv_2000_fm_noMPF-PhiNO_2000_noMPF; //based on equation 53 in Kramer et al., 2004 PRES 

var qP_2000_MPF = (reg_2000.b - Fs_2000)/(reg_2000.b - Fo_2000_Prime);
var qP_2000_noMPF = (Fm_2000_Prime - Fs_2000)/(Fm_2000_Prime - Fo_2000_Prime);
var FvP_Fm_2000_P_MPF = (reg_2000.b-Fo_2000_Prime)/reg_2000.b;
var FvP_Fm_2000_P_noMPF = (A0FmP-Fo_2000_Prime)/A0FmP;

// Create the variables to be printed (assume to use the MPF values unless there is a good reason not to)
// ----------------------------
var fv_2000_fm = fv_2000_fm_MPF;
var npqt_2000  = npqt_2000_MPF;
var PhiNO_2000 = PhiNO_2000_MPF;
var PhiNPQ_2000 = PhiNPQ_2000_MPF;
var qL_2000 = qL_2000_MPF;
var Fm_2000_Prime = reg_2000.b;
var qP_2000 = qP_2000_MPF;
var FvP_Fm_2000_P = FvP_Fm_2000_P_MPF;
var b = json.b;
var r = json.r;
var g = json.g;



























///   OUT PUT VALUES


// 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["Leaf Angle"] = json.angle;



output["order"] = ["Phi2_250","PhiNPQ_250","PhiNO_250","Leaf Temp Differential","Leaf Angle", "Light Intensity (PAR)","Ambient Temperature","Ambient Humidity"];

//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)];




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

// If multi-phase flash steps are flat or positive slope, then just use the normal Phi2, NPQt, PhiNPQ_1500, PhiNO_1500... 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_1500.m > 0) {
  fv_1500_fm = fv_1500_fm_noMPF;
  npqt_1500 = npqt_1500_noMPF;
  PhiNO_1500 = PhiNO_1500_noMPF;
  PhiNPQ_1500 = PhiNPQ_1500_noMPF;
  qL_1500 = qL_1500_noMPF;
  Fm_1500_Prime = A0FmP;
  qP = qP_1500_noMPF;
  FvP_Fm_1500_P = fv_1500_fm_noMPF;
  
  if (fv_1500_fm <= 0) {
    output["Phi2_1500"] 			= 0;
	warning('Phi2_1500 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_noMPF variable',output);
	output["Phi2_1500_noMPF"] 	= MathROUND(npqt_1500,3);
  }
  if (fv_1500_fm >=.85) {
    output["Phi2_1500"] 			= -1;
	danger("Phi2_1500 above the normal range (0 - 0.85).  Please check the raw trace and seriously consider excluding this point.", output);

  }
  else {
	  output["Phi2_1500"] 		= MathROUND(fv_1500_fm,3);
  }
  
  if (npqt_1500 <= 0) {
	output["PhiNPQ_1500"]		= 0;
    output["NPQt_1500"]			= 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_1500_noMPF and PhiNPQ_noMPF variable",output);
	output["PhiNPQ_1500_noMPF"]  = MathROUND(PhiNPQ_1500,3);
	output["npqt_1500_noMPF"]	= MathROUND(npqt_1500,3);
  }
  else {
	output["PhiNPQ_1500"]  = MathROUND(PhiNPQ_1500,3);
	output["NPQt_1500"]		= MathROUND(npqt_1500,3);
  }
	output["PhiNO_1500"]		= MathROUND(PhiNO_1500,3);
	output["qL_1500"]		= MathROUND(qL_1500,3);
    output['FvP/Fm_1500_P']		= MathROUND(FvP_Fm_1500_P,3);
    output['qP_1500']			= MathROUND(qP_1500,3);
}

// Otherwise, use the multi-phase flash calculation for Phi2, NPQt, PhiNPQ, PhiNO_1500... 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 (fv_1500_fm <= 0) {
    output["Phi2_1500"] 			= 0;
	warning("Phi2_1500 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_1500_MPF"] 	= MathROUND(npqt_1500,3);
  }
  if (fv_1500_fm >=.85) {
    output["Phi2_1500"] 			= -1;
	danger("Phi2_1500 above the normal range (0 - 0.85).  Please check the raw trace and seriously consider excluding this point.", output);
  }
  else {
    output["Phi2_1500"]			= MathROUND(fv_1500_fm,3);
  }
  if (npqt_1500 <= 0) {
	output["PhiNPQ_1500"]		= 0;
    output["NPQt_1500"]			= 0;
	warning("NPQt_1500 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_1500_MPF and PhiNPQ_MPF variables",output);
	output["PhiNPQ_1500_MPF"]  = MathROUND(PhiNPQ_1500_MPF,3);
	output["npqt_1500_MPF"]		= MathROUND(npqt_1500,3);
  }
  else {
	output["PhiNPQ_1500"]  = MathROUND(PhiNPQ_1500,3);
	output["NPQt_1500"]		= MathROUND(npqt_1500,3);
  }
	output["PhiNO_1500"]		= MathROUND(PhiNO_1500,3);
	output["qL_1500"]			= MathROUND(qL_1500,3);
    output['FvP/Fm_1500_P']		= MathROUND(FvP_Fm_1500_P,3);
    output['qP_1500']			= MathROUND(qP_1500,3);
}

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

if (Fs_1500_std > 100) {
	danger("noisy Fs_1500", output);
}
/*
if (A0FmP_std > 300) {
	danger("noisy Fm_1500_Prime", output);
}
*/
if (Fm_1500_P_step1_std > 120 | Fm_1500_P_step2_std > 120 | Fm_1500_P_step3_std > 120 | Fm_1500_P_end_std > 300) {
	danger("noisy  multi-phase flash steps",output);
}

if (Fo_1500_Prime_std > 150) {
	danger("noisy Fo_1500_Prime", output);
}
/*
if (reg_1500.m > 0) {
	info("Used Phi2_1500 and not Phi2_1500 MPF - ambient light level was too low to apply MPF calculation", output);
}
if (Fm_1500_P_end/A0FmP - A0FmP/A0FmP > .1) {	
	info("Fm_1500_Prime 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 (Fm_1500_P_end/A0FmP - A0FmP/A0FmP < -.1) {
	info("Fm_1500_Prime slopes up.  This may mean that saturating flash is too bright... consider using a protocol with higher saturating light on these samples",output);
}
*/

output["Fm_1500_Prime"] 		= MathROUND(Fm_1500_Prime,3);
output["Fs_1500"] 			= MathROUND(Fs_1500,1);
output['Fo_1500_Prime']		= MathROUND(Fo_1500_Prime,0);
output["RFd"]           = Number(MathROUND(((Fm_1500_Prime/Fs_1500)-1),3));
//output["ratio MPF/noMPF, Phi2_1500"] = MathROUND(fv_1500_fm_MPF / fv_1500_fm_noMPF,5);
//output["ratio MPF/noMPF, PhiNPQ_1500"] = MathROUND(PhiNPQ_1500_MPF / PhiNPQ_1500_noMPF,5);
//output["ratio MPF/noMPF, PhiNO_1500"] = MathROUND(PhiNO_1500_MPF / PhiNO_1500_noMPF,5);
//output["ratio MPF/noMPF, PhiNO_1500"] = MathROUND(npqt_1500_MPF / npqt_1500_noMPF,5);
output["MPF_slope_1500"] 	= MathROUND(reg_1500.m,3);
output["MPF_rsquared_1500"] 	= MathROUND(reg_1500.r,3);
/*
output["Phi2_1500_MPF"] 		= MathROUND(fv_1500_fm_MPF,3);
output["Phi2_1500_noMPF"] 	= MathROUND(fv_1500_fm,3);
output["Fm_1500_Prime_MPF"] 	= MathROUND(reg_1500.b,3);
output["Fm_1500_Prime_noMPF"] = MathROUND(A0FmP,1);
output['qL_1500_MPF']		= MathROUND(qL_1500_MPF,3);
output['qL_1500_noMPF']      = MathROUND(qL,3);
output['PhiNPQ_MPF']    = MathROUND(PhiNPQ_MPF,3);
output['PhiNPQ_noMPF']  = MathROUND(PhiNPQ_noMPF,3);
output['PhiNO_1500_MPF']		= MathROUND(PhiNO_1500_MPF,3);
output['PhiNO_1500_noMPF']	= MathROUND(PhiNO_1500,3);
output["Fs_1500_std"] 			= MathROUND(Fs_1500_std,1);
output["A0FmP_std"] 			= MathROUND(A0FmP_std,1);
output["Fm_1500_P_step1_std"] 	= MathROUND(Fm_1500_P_step1_std,1);
output["Fm_1500_P_step2_std"] 	= MathROUND(Fm_1500_P_step2_std,1);
output["Fm_1500_P_step3_std"] 	= MathROUND(Fm_1500_P_step3_std,1);
output["Fm_1500_P_end_std"] 		= MathROUND(Fm_1500_P_end_std,1);
output["Fo_1500_Prime_std"] 			= MathROUND(Fo_1500_Prime_std,1);
*/

//output["Fm_1500_P_step1"] = MathROUND(Fm_1500_P_step1,3);
//output["Fm_1500_P_step2"] = MathROUND(Fm_1500_P_step2,3);
//output["Fm_1500_P_step3"] = MathROUND(Fm_1500_P_step3,3);
//output["intensity inverse"] = inverse_intensity;
//output["steps"] = [A0FmP,Fm_1500_P_step1,Fm_1500_P_step2,Fm_1500_P_step3];
//output["slopey"] = Fm_1500_P_end/A0FmP - A0FmP/A0FmP ;

  output["baseline"] 	= baseline;



// 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["Leaf Angle"] = json.angle;

output["order"] = ["Phi2_1500","PhiNPQ_1500","PhiNO_1500","Leaf Temp Differential","Leaf Angle", "Light Intensity (PAR)","Ambient Temperature","Ambient Humidity"];

//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)];

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

// If multi-phase flash steps are flat or positive slope, then just use the normal Phi2, NPQt, PhiNPQ_2000, PhiNO_2000... 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_2000.m > 0) {
  fv_2000_fm = fv_2000_fm_noMPF;
  npqt_2000 = npqt_2000_noMPF;
  PhiNO_2000 = PhiNO_2000_noMPF;
  PhiNPQ_2000 = PhiNPQ_2000_noMPF;
  qL_2000 = qL_2000_noMPF;
  Fm_2000_Prime = A0FmP;
  qP = qP_2000_noMPF;
  FvP_Fm_2000_P = fv_2000_fm_noMPF;
  
  if (fv_2000_fm <= 0) {
    output["Phi2_2000"] 			= 0;
	warning('Phi2_2000 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_noMPF variable',output);
	output["Phi2_2000_noMPF"] 	= MathROUND(npqt_2000,3);
  }
  if (fv_2000_fm >=.85) {
    output["Phi2_2000"] 			= -1;
	danger("Phi2_2000 above the normal range (0 - 0.85).  Please check the raw trace and seriously consider excluding this point.", output);

  }
  else {
	  output["Phi2_2000"] 		= MathROUND(fv_2000_fm,3);
  }
  
  if (npqt_2000 <= 0) {
	output["PhiNPQ_2000"]		= 0;
    output["NPQt_2000"]			= 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_2000_noMPF and PhiNPQ_noMPF variable",output);
	output["PhiNPQ_2000_noMPF"]  = MathROUND(PhiNPQ_2000,3);
	output["npqt_2000_noMPF"]	= MathROUND(npqt_2000,3);
  }
  else {
	output["PhiNPQ_2000"]  = MathROUND(PhiNPQ_2000,3);
	output["NPQt_2000"]		= MathROUND(npqt_2000,3);
  }
	output["PhiNO_2000"]		= MathROUND(PhiNO_2000,3);
	output["qL_2000"]		= MathROUND(qL_2000,3);
    output['FvP/Fm_2000_P']		= MathROUND(FvP_Fm_2000_P,3);
    output['qP_2000']			= MathROUND(qP_2000,3);
}

// Otherwise, use the multi-phase flash calculation for Phi2, NPQt, PhiNPQ, PhiNO_2000... 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 (fv_2000_fm <= 0) {
    output["Phi2_2000"] 			= 0;
	warning("Phi2_2000 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_2000_MPF"] 	= MathROUND(npqt_2000,3);
  }
  if (fv_2000_fm >=.85) {
    output["Phi2_2000"] 			= -1;
	danger("Phi2_2000 above the normal range (0 - 0.85).  Please check the raw trace and seriously consider excluding this point.", output);
  }
  else {
    output["Phi2_2000"]			= MathROUND(fv_2000_fm,3);
  }
  if (npqt_2000 <= 0) {
	output["PhiNPQ_2000"]		= 0;
    output["NPQt_2000"]			= 0;
	warning("NPQt_2000 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_2000_MPF and PhiNPQ_MPF variables",output);
	output["PhiNPQ_2000_MPF"]  = MathROUND(PhiNPQ_2000_MPF,3);
	output["npqt_2000_MPF"]		= MathROUND(npqt_2000,3);
  }
  else {
	output["PhiNPQ_2000"]  = MathROUND(PhiNPQ_2000,3);
	output["NPQt_2000"]		= MathROUND(npqt_2000,3);
  }
	output["PhiNO_2000"]		= MathROUND(PhiNO_2000,3);
	output["qL_2000"]			= MathROUND(qL_2000,3);
    output['FvP/Fm_2000_P']		= MathROUND(FvP_Fm_2000_P,3);
    output['qP_2000']			= MathROUND(qP_2000,3);
}

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

if (Fs_2000_std > 100) {
	danger("noisy Fs_2000", output);
}
/*
if (A0FmP_std > 300) {
	danger("noisy Fm_2000_Prime", output);
}
*/
if (Fm_2000_P_step1_std > 120 | Fm_2000_P_step2_std > 120 | Fm_2000_P_step3_std > 120 | Fm_2000_P_end_std > 300) {
	danger("noisy  multi-phase flash steps",output);
}

if (Fo_2000_Prime_std > 150) {
	danger("noisy Fo_2000_Prime", output);
}
/*
if (reg_2000.m > 0) {
	info("Used Phi2_2000 and not Phi2_2000 MPF - ambient light level was too low to apply MPF calculation", output);
}
if (Fm_2000_P_end/A0FmP - A0FmP/A0FmP > .1) {	
	info("Fm_2000_Prime 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 (Fm_2000_P_end/A0FmP - A0FmP/A0FmP < -.1) {
	info("Fm_2000_Prime slopes up.  This may mean that saturating flash is too bright... consider using a protocol with higher saturating light on these samples",output);
}
*/

output["Fm_2000_Prime"] 		= MathROUND(Fm_2000_Prime,3);
output["Fs_2000"] 			= MathROUND(Fs_2000,1);
output['Fo_2000_Prime']		= MathROUND(Fo_2000_Prime,0);
output["RFd"]           = Number(MathROUND(((Fm_2000_Prime/Fs_2000)-1),3));
//output["ratio MPF/noMPF, Phi2_2000"] = MathROUND(fv_2000_fm_MPF / fv_2000_fm_noMPF,5);
//output["ratio MPF/noMPF, PhiNPQ_2000"] = MathROUND(PhiNPQ_2000_MPF / PhiNPQ_2000_noMPF,5);
//output["ratio MPF/noMPF, PhiNO_2000"] = MathROUND(PhiNO_2000_MPF / PhiNO_2000_noMPF,5);
//output["ratio MPF/noMPF, PhiNO_2000"] = MathROUND(npqt_2000_MPF / npqt_2000_noMPF,5);
output["MPF_slope_2000"] 	= MathROUND(reg_2000.m,3);
output["MPF_rsquared_2000"] 	= MathROUND(reg_2000.r,3);
/*
output["Phi2_2000_MPF"] 		= MathROUND(fv_2000_fm_MPF,3);
output["Phi2_2000_noMPF"] 	= MathROUND(fv_2000_fm,3);
output["Fm_2000_Prime_MPF"] 	= MathROUND(reg_2000.b,3);
output["Fm_2000_Prime_noMPF"] = MathROUND(A0FmP,1);
output['qL_2000_MPF']		= MathROUND(qL_2000_MPF,3);
output['qL_2000_noMPF']      = MathROUND(qL,3);
output['PhiNPQ_MPF']    = MathROUND(PhiNPQ_MPF,3);
output['PhiNPQ_noMPF']  = MathROUND(PhiNPQ,3);
output['PhiNO_2000_MPF']		= MathROUND(PhiNO_2000_MPF,3);
output['PhiNO_2000_noMPF']	= MathROUND(PhiNO_2000,3);
output["Fs_2000_std"] 			= MathROUND(Fs_2000_std,1);
output["A0FmP_std"] 			= MathROUND(A0FmP_std,1);
output["Fm_2000_P_step1_std"] 	= MathROUND(Fm_2000_P_step1_std,1);
output["Fm_2000_P_step2_std"] 	= MathROUND(Fm_2000_P_step2_std,1);
output["Fm_2000_P_step3_std"] 	= MathROUND(Fm_2000_P_step3_std,1);
output["Fm_2000_P_end_std"] 		= MathROUND(Fm_2000_P_end_std,1);
output["Fo_2000_Prime_std"] 			= MathROUND(Fo_2000_Prime_std,1);
*/

//output["Fm_2000_P_step1"] = MathROUND(Fm_2000_P_step1,3);
//output["Fm_2000_P_step2"] = MathROUND(Fm_2000_P_step2,3);
//output["Fm_2000_P_step3"] = MathROUND(Fm_2000_P_step3,3);
//output["intensity inverse"] = inverse_intensity;
//output["steps"] = [A0FmP,Fm_2000_P_step1,Fm_2000_P_step2,Fm_2000_P_step3];
//output["slopey"] = Fm_2000_P_end/A0FmP - A0FmP/A0FmP ;

  output["baseline"] 	= baseline;

// 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["Leaf Angle"] = json.angle;

output["order"] = ["Phi2_2000","PhiNPQ_2000","PhiNO_2000","Leaf Temp Differential","Leaf Angle", "Light Intensity (PAR)","Ambient Temperature","Ambient Humidity"];

//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": 240,
  "time": 1503425851666,
  "device_name": "MultispeQ",
  "device_version": "1",
  "device_id": "01:12:38:86",
  "device_battery": 60,
  "device_firmware": 1.17,
  "sample": [
    {
      "time": 1503425851682,
      "protocol_id": 1,
      "detector_read1": 7859,
      "light_intensity": 21,
      "r": 18,
      "g": 8,
      "b": 7,
      "light_intensity_raw": 29,
      "temperature": 22.959999,
      "humidity": 64.324219,
      "pressure": 986.852966,
      "temperature2": 22.860001,
      "humidity2": 63.108398,
      "pressure2": 987.147522,
      "contactless_temp": 22.57,
      "thickness": 0.39,
      "compass_direction": "E",
      "compass": "90.00",
      "angle": 1.12,
      "angle_direction": "S",
      "pitch": 1.12,
      "roll": 0,
      "recall": {
        "time": 1503425868992,
        "colorcal_blank1[1]": 17542,
        "colorcal_blank1[2]": 25638.5,
        "colorcal_blank1[3]": 30483,
        "colorcal_blank1[4]": 34315,
        "colorcal_blank1[6]": 34899.5,
        "colorcal_blank1[8]": 32270,
        "colorcal_blank1[9]": 31291,
        "colorcal_blank1[10]": 36797.5,
        "colorcal_blank2[1]": 19684.5,
        "colorcal_blank2[2]": 19158.5,
        "colorcal_blank2[3]": 23665.5,
        "colorcal_blank2[4]": 18080,
        "colorcal_blank2[6]": 17409,
        "colorcal_blank2[8]": 17769,
        "colorcal_blank2[9]": 18557.5,
        "colorcal_blank2[10]": 16442,
        "colorcal_blank3[1]": 18085.5,
        "colorcal_blank3[2]": 10236,
        "colorcal_blank3[3]": 21510.5,
        "colorcal_blank3[4]": 12490.5,
        "colorcal_blank3[6]": 6169.5,
        "colorcal_blank3[8]": 6510.5,
        "colorcal_blank3[9]": 5453,
        "colorcal_blank3[10]": 5961,
        "colorcal_intensity1_slope[2]": 2.638,
        "colorcal_intensity1_yint[2]": 1.2,
        "colorcal_intensity2_slope[2]": 2.676,
        "colorcal_intensity2_yint[2]": -4.8,
        "colorcal_intensity3_slope[2]": 2.651,
        "colorcal_intensity3_yint[2]": -20.200001,
        "ir_baseline_slope[5]": 7773.5,
        "ir_baseline_yint[5]": 12514,
        "ir_baseline_slope[3]": 562,
        "ir_baseline_yint[3]": 801
      },
      "data_raw": [
        4505,
        4572,
        4641,
        4695,
        4743,
        4783,
        4822,
        4863,
        4899,
        4927,
        4949,
        4967,
        4987,
        5015,
        5029,
        5043,
        5055,
        5062,
        5070,
        5079,
        5091,
        5098,
        5106,
        5111,
        5117,
        5123,
        5127,
        5128,
        5126,
        5134,
        5133,
        5139,
        5138,
        5141,
        5148,
        5151,
        5157,
        5158,
        5156,
        5159,
        5163,
        5163,
        5164,
        5166,
        5171,
        5170,
        5175,
        5175,
        5175,
        5178,
        5181,
        5183,
        5183,
        5184,
        5187,
        5188,
        5188,
        5190,
        5194,
        5194,
        5197,
        5199,
        5199,
        5202,
        5205,
        5206,
        5207,
        5209,
        5212,
        5214,
        5211,
        5207,
        5211,
        5217,
        5222,
        5223,
        5225,
        5226,
        5228,
        5231,
        5233,
        5234,
        5229,
        5229,
        5242,
        5243,
        5245,
        5246,
        5249,
        5247,
        5243,
        5250,
        5254,
        5255,
        5255,
        5259,
        5259,
        5255,
        5259,
        5266,
        5271,
        5273,
        5271,
        5268,
        5271,
        5279,
        5279,
        5281,
        5279,
        5277,
        5286,
        5290,
        5290,
        5290,
        5286,
        5295,
        5295,
        5298,
        5298,
        5295,
        5305,
        5305,
        5308,
        5300,
        5307,
        5313,
        5313,
        5316,
        5313,
        5319,
        5319,
        5321,
        5318,
        5327,
        5330,
        5327,
        5323,
        5335,
        5335,
        5333,
        5331,
        5339,
        5342,
        5337,
        5343,
        5346,
        5348,
        5342,
        5351,
        5354,
        16934,
        16881,
        16849,
        16831,
        16821,
        16809,
        16807,
        16798,
        16804,
        16793,
        16803,
        16795,
        16802,
        16797,
        16803,
        16803,
        16804,
        16804,
        16798,
        16807,
        17197,
        17287,
        17327,
        17355,
        17369,
        17365,
        17374,
        17375,
        17369,
        17375,
        17374,
        17363,
        17367,
        17371,
        17366,
        17359,
        17366,
        17365,
        17355,
        17361,
        17359,
        17359,
        17349,
        17357,
        17358,
        17349,
        17349,
        17355,
        17351,
        17343,
        17358,
        17357,
        17354,
        17348,
        17354,
        17353,
        17347,
        17339,
        17349,
        17348,
        17349,
        17339,
        17348,
        17346,
        17335,
        17341,
        17345,
        17342,
        17331,
        17343,
        17340,
        17333,
        17329,
        17333,
        17331,
        17322,
        17327,
        17331,
        17331,
        17321,
        17311,
        17319,
        17319,
        17315,
        17321,
        17324,
        17322,
        17309,
        17309,
        17314,
        17313,
        17311,
        17300,
        17309,
        17306,
        17305,
        17298,
        17294,
        17299,
        17297,
        17299,
        17290,
        17282,
        17289,
        17290,
        17289,
        17287,
        17278,
        17283,
        17283,
        15455,
        14055,
        12925,
        12042,
        11358,
        10824,
        10426,
        10115,
        9861,
        9653,
        9489,
        9341,
        9210,
        9111,
        9015,
        8925,
        8858,
        8787,
        8726,
        8671,
        8447,
        8134,
        7987,
        7895,
        7814,
        7751,
        7695,
        7643,
        7610,
        7582,
        7553,
        7527,
        7503,
        7485,
        7467,
        7451,
        7437,
        7426,
        7412,
        7402,
        7395,
        7385,
        7379,
        7369,
        7366,
        7363,
        7357,
        7351,
        7349,
        7347,
        7343,
        7340,
        7336,
        7337,
        7333,
        7330,
        7332,
        7328,
        7329,
        7329,
        7328,
        7325,
        7323,
        7320,
        7321,
        7322,
        7319,
        7319,
        7319,
        7319,
        7318,
        7317,
        7316,
        7315,
        7314,
        7314,
        7315,
        7314,
        7313,
        7311,
        7312,
        7309,
        7309,
        7310,
        7310,
        7307,
        7308,
        7305,
        7303,
        7307,
        7303,
        7303,
        7302,
        7301,
        7303,
        7300,
        7298,
        7295,
        7295,
        7297,
        7294,
        7294,
        7292,
        7291,
        7287,
        7289,
        7287,
        7286,
        7283,
        7283,
        7282,
        7275,
        7271,
        7271,
        7269,
        7271,
        7270,
        7271,
        7271,
        7269,
        7268,
        7269,
        7267,
        7266,
        7265,
        7262,
        7259,
        7259,
        7255,
        7252,
        7254,
        7250,
        7248,
        7246,
        7245,
        7241,
        7234,
        7231,
        7233,
        7231,
        7235,
        7237,
        7235,
        7231,
        7230,
        7227,
        7226,
        7222,
        7222,
        7219,
        7217,
        7217,
        7213,
        7211,
        7205,
        7198,
        7198,
        7197,
        7204,
        7202,
        7196,
        7196,
        7194,
        7193,
        7189,
        7189,
        7187,
        7183,
        7183,
        7175,
        15330,
        15332,
        15331,
        15326,
        15313,
        15314,
        15315,
        15313,
        15308,
        15297,
        15301,
        15300,
        15299,
        15295,
        15285,
        15293,
        15284,
        15285,
        15279,
        15269,
        15306,
        15315,
        15314,
        15303,
        15309,
        15303,
        15295,
        15285,
        15290,
        15279,
        15269,
        15271,
        15266,
        15253,
        15253,
        15244,
        15239,
        15231,
        15233,
        15227,
        15213,
        15213,
        15213,
        15198,
        15198,
        15192,
        15178,
        15179,
        15177,
        15170,
        15172,
        15166,
        15159,
        15147,
        15151,
        15144,
        15135,
        15135,
        15129,
        15120,
        15124,
        15117,
        15113,
        15098,
        15101,
        15095,
        15083,
        15085,
        15080,
        15073,
        15068,
        15063,
        15060,
        15048,
        15054,
        15046,
        15041,
        15031,
        15034,
        15031,
        15006,
        15011,
        15008,
        14999,
        14994,
        14990,
        14978,
        14974,
        14971,
        14961,
        14957,
        14951,
        14941,
        14933,
        14932,
        14926,
        14917,
        14916,
        14906,
        14899,
        14899,
        14890,
        14879,
        14879,
        14870,
        14863,
        14863,
        14850,
        14839,
        14837,
        13913,
        13295,
        12844,
        12485,
        12196,
        11971,
        11794,
        11634,
        11499,
        11375,
        11274,
        11181,
        11094,
        11012,
        10931,
        10862,
        10802,
        10739,
        10684,
        10625,
        7877,
        7653,
        7551,
        7462,
        7377,
        7323,
        7260,
        7219,
        7167,
        7140,
        7102,
        7081,
        7057,
        7031,
        7021,
        6997,
        6991,
        6979,
        6959,
        6959,
        6951,
        6939,
        6939,
        6938,
        6925,
        6929,
        6923,
        6919,
        6923,
        6915,
        6919,
        6919,
        6914,
        6920,
        6919,
        6916,
        6924,
        6927,
        6919,
        6929,
        6931,
        6922,
        6935,
        6936,
        6929,
        6943,
        6943,
        6943,
        6948,
        6951,
        6949,
        6956,
        6954,
        6960,
        6966,
        6965,
        6967,
        6971,
        6965,
        6977,
        6980,
        6973,
        6983,
        6987,
        6982,
        6990,
        6991,
        6995,
        6999,
        6993,
        7005,
        7005,
        7001,
        7007,
        7012,
        7007,
        7015,
        7015,
        7011,
        7017,
        7019,
        7023,
        7026,
        7018,
        7030,
        7031,
        7028,
        7034,
        7035,
        7031,
        7038,
        7036,
        7039,
        7042,
        7039,
        7046,
        7046,
        7038,
        7047,
        7046,
        7045,
        7047,
        7047,
        7048,
        7050,
        7045,
        7055,
        7055,
        7045,
        7053,
        7057,
        7053,
        7057,
        7051,
        7059,
        7059,
        7051,
        7059,
        7055,
        7053,
        7060,
        7056,
        7061,
        7059,
        7053,
        7062,
        7061,
        7055,
        7063,
        7061,
        7058,
        7062,
        7051,
        7059,
        7059,
        7053,
        7061,
        7053,
        7059,
        7058,
        7052,
        7057,
        7057,
        7055,
        7058,
        7047,
        7057,
        7055,
        7047,
        7054
      ]
    }
  ],
  "app_os": "mac",
  "app_name": "PhotosynQ",
  "app_version": "0.3.8",
  "app_device": "x86-64",
  "location": [
    "43.0087375",
    "-78.7836107"
  ],
  "ConsoleMacro": "386"
}
Default avatar
Created by

Jonathan R Pleban


Protocol connections:
1
Latest Update:
Aug 2017