Chl Fl 400-1000 umol JRP v1.0


for use with PHi2_protocal_400,500,600,800,1000
// 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 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;

/*
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/4500,1/4050,1/3600,1/3150];

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

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

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

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

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

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

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

// Calculations for corrected Fm_400_Prime using multi-phase flash
// ----------------------------
var reg_400 = MathLINREG(inverse_intensity, [A0FmP,Fm_400_P_step1,Fm_400_P_step2,Fm_400_P_step3]);

// Calculate Phi2 w/ and w/out multi-phase flash
// ----------------------------
var fv_400_fm_noMPF = (A0FmP-Fs_400)/A0FmP;
var fv_400_fm_MPF = (reg_400.b-Fs_400)/reg_400.b;


// Calculate NPQt,PhiNPQ_400, PhiNO_400, qL w/ and w/out multi-phase flash
// ----------------------------
var npqt_400_MPF = (4.88 / ((reg_400.b / Fo_400_Prime) -1) )-1;
var npqt_400_noMPF = (4.88 / ((A0FmP / Fo_400_Prime) -1) )-1;
var qL_400_MPF = ((reg_400.b - Fs_400)*Fo_400_Prime)/((reg_400.b-Fo_400_Prime)*Fs_400);
var qL_400_noMPF = ((A0FmP - Fs_400)*Fo_400_Prime)/((A0FmP-Fo_400_Prime)*Fs_400);
var PhiNO_400_MPF = 1/(npqt_400_MPF + 1 + qL_400_MPF*4.88); //based on equation 52 in Kramer et al., 2004 PRES
var PhiNO_400_noMPF = 1/(npqt_400_noMPF + 1 + qL_400_noMPF*4.88); //based on equation 52 in Kramer et al., 2004 PRES
var PhiNPQ_400_MPF = 1-fv_400_fm_MPF-PhiNO_400_MPF; //based on equation 53 in Kramer et al., 2004 PRES 
var PhiNPQ_400_noMPF = 1-fv_400_fm_noMPF-PhiNO_400_noMPF; //based on equation 53 in Kramer et al., 2004 PRES 

var qP_400_MPF = (reg_400.b - Fs_400)/(reg_400.b - Fo_400_Prime);
var qP_400_noMPF = (Fm_400_Prime - Fs_400)/(Fm_400_Prime - Fo_400_Prime);
var FvP_Fm_400_P_MPF = (reg_400.b-Fo_400_Prime)/reg_400.b;
var FvP_Fm_400_P_noMPF = (A0FmP-Fo_400_Prime)/A0FmP;

// Create the variables to be printed (assume to use the MPF values unless there is a good reason not to)
// ----------------------------
var fv_400_fm = fv_400_fm_MPF;
var npqt_400  = npqt_400_MPF;
var PhiNO_400 = PhiNO_400_MPF;
var PhiNPQ_400 = PhiNPQ_400_MPF;
var qL_400 = qL_400_MPF;
var Fm_400_Prime = reg_400.b;
var qP_400 = qP_400_MPF;
var FvP_Fm_400_P = FvP_Fm_400_P_MPF;
var b = json.b;
var r = json.r;
var g = json.g;


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

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

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

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

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

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

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

// Calculations for corrected Fm_500_Prime using multi-phase flash
// ----------------------------
var reg_500= MathLINREG(inverse_intensity, [A0FmP,Fm_500_P_step1,Fm_500_P_step2,Fm_500_P_step3]);

// Calculate Phi2 w/ and w/out multi-phase flash
// ----------------------------
var fv_500_fm_noMPF = (A0FmP-Fs_500)/A0FmP;
var fv_500_fm_MPF = (reg_500.b-Fs_500)/reg_500.b;


// Calculate NPQt,PhiNPQ_500, PhiNO_500, qL w/ and w/out multi-phase flash
// ----------------------------
var npqt_500_MPF = (4.88 / ((reg_500.b / Fo_500_Prime) -1) )-1;
var npqt_500_noMPF = (4.88 / ((A0FmP / Fo_500_Prime) -1) )-1;
var qL_500_MPF = ((reg_500.b - Fs_500)*Fo_500_Prime)/((reg_500.b-Fo_500_Prime)*Fs_500);
var qL_500_noMPF = ((A0FmP - Fs_500)*Fo_500_Prime)/((A0FmP-Fo_500_Prime)*Fs_500);
var PhiNO_500_MPF = 1/(npqt_500_MPF + 1 + qL_500_MPF*4.88); //based on equation 52 in Kramer et al., 2004 PRES
var PhiNO_500_noMPF = 1/(npqt_500_noMPF + 1 + qL_500_noMPF*4.88); //based on equation 52 in Kramer et al., 2004 PRES
var PhiNPQ_500_MPF = 1-fv_500_fm_MPF-PhiNO_500_MPF; //based on equation 53 in Kramer et al., 2004 PRES 
var PhiNPQ_500_noMPF = 1-fv_500_fm_noMPF-PhiNO_500_noMPF; //based on equation 53 in Kramer et al., 2004 PRES 

var qP_500_MPF = (reg_500.b - Fs_500)/(reg_500.b - Fo_500_Prime);
var qP_500_noMPF = (Fm_500_Prime - Fs_500)/(Fm_500_Prime - Fo_500_Prime);
var FvP_Fm_500_P_MPF = (reg_500.b-Fo_500_Prime)/reg_500.b;
var FvP_Fm_500_P_noMPF = (A0FmP-Fo_500_Prime)/A0FmP;

// Create the variables to be printed (assume to use the MPF values unless there is a good reason not to)
// ----------------------------
var fv_500_fm = fv_500_fm_MPF;
var npqt_500 = npqt_500_MPF;
var PhiNO_500= PhiNO_500_MPF;
var PhiNPQ_500= PhiNPQ_500_MPF;
var qL_500= qL_500_MPF;
var Fm_500_Prime = reg_500.b;
var qP_500= qP_500_MPF;
var FvP_Fm_500_P = FvP_Fm_500_P_MPF;
var b = json.b;
var r = json.r;
var g = json.g;

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

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

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

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

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

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

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

// Calculations for corrected Fm_600_Prime using multi-phase flash
// ----------------------------
var reg_600 = MathLINREG(inverse_intensity, [A0FmP,Fm_600_P_step1,Fm_600_P_step2,Fm_600_P_step3]);

// Calculate Phi2 w/ and w/out multi-phase flash
// ----------------------------
var fv_600_fm_noMPF = (A0FmP-Fs_600)/A0FmP;
var fv_600_fm_MPF = (reg_600.b-Fs_600)/reg_600.b;


// Calculate NPQt,PhiNPQ_600, PhiNO_600, qL w/ and w/out multi-phase flash
// ----------------------------
var npqt_600_MPF = (4.88 / ((reg_600.b / Fo_600_Prime) -1) )-1;
var npqt_600_noMPF = (4.88 / ((A0FmP / Fo_600_Prime) -1) )-1;
var qL_600_MPF = ((reg_600.b - Fs_600)*Fo_600_Prime)/((reg_600.b-Fo_600_Prime)*Fs_600);
var qL_600_noMPF = ((A0FmP - Fs_600)*Fo_600_Prime)/((A0FmP-Fo_600_Prime)*Fs_600);
var PhiNO_600_MPF = 1/(npqt_600_MPF + 1 + qL_600_MPF*4.88); //based on equation 52 in Kramer et al., 2004 PRES
var PhiNO_600_noMPF = 1/(npqt_600_noMPF + 1 + qL_600_noMPF*4.88); //based on equation 52 in Kramer et al., 2004 PRES
var PhiNPQ_600_MPF = 1-fv_600_fm_MPF-PhiNO_600_MPF; //based on equation 53 in Kramer et al., 2004 PRES 
var PhiNPQ_600_noMPF = 1-fv_600_fm_noMPF-PhiNO_600_noMPF; //based on equation 53 in Kramer et al., 2004 PRES 

var qP_600_MPF = (reg_600.b - Fs_600)/(reg_600.b - Fo_600_Prime);
var qP_600_noMPF = (Fm_600_Prime - Fs_600)/(Fm_600_Prime - Fo_600_Prime);
var FvP_Fm_600_P_MPF = (reg_600.b-Fo_600_Prime)/reg_600.b;
var FvP_Fm_600_P_noMPF = (A0FmP-Fo_600_Prime)/A0FmP;

// Create the variables to be printed (assume to use the MPF values unless there is a good reason not to)
// ----------------------------
var fv_600_fm = fv_600_fm_MPF;
var npqt_600  = npqt_600_MPF;
var PhiNO_600 = PhiNO_600_MPF;
var PhiNPQ_600 = PhiNPQ_600_MPF;
var qL_600 = qL_600_MPF;
var Fm_600_Prime = reg_600.b;
var qP_600 = qP_600_MPF;
var FvP_Fm_600_P = FvP_Fm_600_P_MPF;
var b = json.b;
var r = json.r;
var g = json.g;

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

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

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

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

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

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

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

// Calculations for corrected Fm_800_Prime using multi-phase flash
// ----------------------------
var reg_800 = MathLINREG(inverse_intensity, [A0FmP,Fm_800_P_step1,Fm_800_P_step2,Fm_800_P_step3]);

// Calculate Phi2 w/ and w/out multi-phase flash
// ----------------------------
var fv_800_fm_noMPF = (A0FmP-Fs_800)/A0FmP;
var fv_800_fm_MPF = (reg_800.b-Fs_800)/reg_800.b;


// Calculate NPQt,PhiNPQ_800, PhiNO_800, qL w/ and w/out multi-phase flash
// ----------------------------
var npqt_800_MPF = (4.88 / ((reg_800.b / Fo_800_Prime) -1) )-1;
var npqt_800_noMPF = (4.88 / ((A0FmP / Fo_800_Prime) -1) )-1;
var qL_800_MPF = ((reg_800.b - Fs_800)*Fo_800_Prime)/((reg_800.b-Fo_800_Prime)*Fs_800);
var qL_800_noMPF = ((A0FmP - Fs_800)*Fo_800_Prime)/((A0FmP-Fo_800_Prime)*Fs_800);
var PhiNO_800_MPF = 1/(npqt_800_MPF + 1 + qL_800_MPF*4.88); //based on equation 52 in Kramer et al., 2004 PRES
var PhiNO_800_noMPF = 1/(npqt_800_noMPF + 1 + qL_800_noMPF*4.88); //based on equation 52 in Kramer et al., 2004 PRES
var PhiNPQ_800_MPF = 1-fv_800_fm_MPF-PhiNO_800_MPF; //based on equation 53 in Kramer et al., 2004 PRES 
var PhiNPQ_800_noMPF = 1-fv_800_fm_noMPF-PhiNO_800_noMPF; //based on equation 53 in Kramer et al., 2004 PRES 

var qP_800_MPF = (reg_800.b - Fs_800)/(reg_800.b - Fo_800_Prime);
var qP_800_noMPF = (Fm_800_Prime - Fs_800)/(Fm_800_Prime - Fo_800_Prime);
var FvP_Fm_800_P_MPF = (reg_800.b-Fo_800_Prime)/reg_800.b;
var FvP_Fm_800_P_noMPF = (A0FmP-Fo_800_Prime)/A0FmP;

// Create the variables to be printed (assume to use the MPF values unless there is a good reason not to)
// ----------------------------
var fv_800_fm = fv_800_fm_MPF;
var npqt_800  = npqt_800_MPF;
var PhiNO_800 = PhiNO_800_MPF;
var PhiNPQ_800 = PhiNPQ_800_MPF;
var qL_800 = qL_800_MPF;
var Fm_800_Prime = reg_800.b;
var qP_800 = qP_800_MPF;
var FvP_Fm_800_P = FvP_Fm_800_P_MPF;
var b = json.b;
var r = json.r;
var g = json.g;

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

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

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

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

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

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

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

// Calculations for corrected Fm_1000_Prime using multi-phase flash
// ----------------------------
var reg_1000 = MathLINREG(inverse_intensity, [A0FmP,Fm_1000_P_step1,Fm_1000_P_step2,Fm_1000_P_step3]);

// Calculate Phi2 w/ and w/out multi-phase flash
// ----------------------------
var fv_1000_fm_noMPF = (A0FmP-Fs_1000)/A0FmP;
var fv_1000_fm_MPF = (reg_1000.b-Fs_1000)/reg_1000.b;


// Calculate NPQt,PhiNPQ_1000, PhiNO_1000, qL w/ and w/out multi-phase flash
// ----------------------------
var npqt_1000_MPF = (4.88 / ((reg_1000.b / Fo_1000_Prime) -1) )-1;
var npqt_1000_noMPF = (4.88 / ((A0FmP / Fo_1000_Prime) -1) )-1;
var qL_1000_MPF = ((reg_1000.b - Fs_1000)*Fo_1000_Prime)/((reg_1000.b-Fo_1000_Prime)*Fs_1000);
var qL_1000_noMPF = ((A0FmP - Fs_1000)*Fo_1000_Prime)/((A0FmP-Fo_1000_Prime)*Fs_1000);
var PhiNO_1000_MPF = 1/(npqt_1000_MPF + 1 + qL_1000_MPF*4.88); //based on equation 52 in Kramer et al., 2004 PRES
var PhiNO_1000_noMPF = 1/(npqt_1000_noMPF + 1 + qL_1000_noMPF*4.88); //based on equation 52 in Kramer et al., 2004 PRES
var PhiNPQ_1000_MPF = 1-fv_1000_fm_MPF-PhiNO_1000_MPF; //based on equation 53 in Kramer et al., 2004 PRES 
var PhiNPQ_1000_noMPF = 1-fv_1000_fm_noMPF-PhiNO_1000_noMPF; //based on equation 53 in Kramer et al., 2004 PRES 

var qP_1000_MPF = (reg_1000.b - Fs_1000)/(reg_1000.b - Fo_1000_Prime);
var qP_1000_noMPF = (Fm_1000_Prime - Fs_1000)/(Fm_1000_Prime - Fo_1000_Prime);
var FvP_Fm_1000_P_MPF = (reg_1000.b-Fo_1000_Prime)/reg_1000.b;
var FvP_Fm_1000_P_noMPF = (A0FmP-Fo_1000_Prime)/A0FmP;

// Create the variables to be printed (assume to use the MPF values unless there is a good reason not to)
// ----------------------------
var fv_1000_fm = fv_1000_fm_MPF;
var npqt_1000  = npqt_1000_MPF;
var PhiNO_1000 = PhiNO_1000_MPF;
var PhiNPQ_1000 = PhiNPQ_1000_MPF;
var qL_1000 = qL_1000_MPF;
var Fm_1000_Prime = reg_1000.b;
var qP_1000 = qP_1000_MPF;
var FvP_Fm_1000_P = FvP_Fm_1000_P_MPF;
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_400, PhiNO_400... 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_400.m > 0) {
  fv_400_fm = fv_400_fm_noMPF;
  npqt_400 = npqt_400_noMPF;
  PhiNO_400 = PhiNO_400_noMPF;
  PhiNPQ_400 = PhiNPQ_400_noMPF;
  qL_400 = qL_400_noMPF;
  Fm_400_Prime = A0FmP;
  qP = qP_400_noMPF;
  FvP_Fm_400_P = fv_400_fm_noMPF;
  
  if (fv_400_fm <= 0) {
    output["Phi2_400"] 			= 0;
	warning('Phi2_400 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_400_noMPF"] 	= MathROUND(npqt_400,3);
  }
  if (fv_400_fm >=.85) {
    output["Phi2_400"] 			= -1;
	danger("Phi2_400 above the normal range (0 - 0.85).  Please check the raw trace and seriously consider excluding this point.", output);

  }
  else {
	  output["Phi2_400"] 		= MathROUND(fv_400_fm,3);
  }
  
  if (npqt_400 <= 0) {
	output["PhiNPQ_400"]		= 0;
    output["NPQt_400"]			= 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_400_noMPF and PhiNPQ_noMPF variable",output);
	output["PhiNPQ_400_noMPF"]  = MathROUND(PhiNPQ_400,3);
	output["npqt_400_noMPF"]	= MathROUND(npqt_400,3);
  }
  else {
	output["PhiNPQ_400"]  = MathROUND(PhiNPQ_400,3);
	output["NPQt_400"]		= MathROUND(npqt_400,3);
  }
	output["PhiNO_400"]		= MathROUND(PhiNO_400,3);
	output["qL_400"]		= MathROUND(qL_400,3);
    output['FvP/Fm_400_P']		= MathROUND(FvP_Fm_400_P,3);
    output['qP_400']			= MathROUND(qP_400,3);
}

// Otherwise, use the multi-phase flash calculation for Phi2, NPQt, PhiNPQ, PhiNO_400... 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_400_fm <= 0) {
    output["Phi2_400"] 			= 0;
	warning("Phi2_400 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_400_MPF"] 	= MathROUND(npqt_400,3);
  }
  if (fv_400_fm >=.85) {
    output["Phi2_400"] 			= -1;
	danger("Phi2_400 above the normal range (0 - 0.85).  Please check the raw trace and seriously consider excluding this point.", output);
  }
  else {
    output["Phi2_400"]			= MathROUND(fv_400_fm,3);
  }
  if (npqt_400 <= 0) {
	output["PhiNPQ_400"]		= 0;
    output["NPQt_400"]			= 0;
	warning("NPQt_400 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_400_MPF and PhiNPQ_MPF variables",output);
	output["PhiNPQ_400_MPF"]  = MathROUND(PhiNPQ,3);
	output["npqt_400_MPF"]		= MathROUND(npqt_400,3);
  }
  else {
	output["PhiNPQ_400"]  = MathROUND(PhiNPQ_400,3);
	output["NPQt_400"]		= MathROUND(npqt_400,3);
  }
	output["PhiNO_400"]		= MathROUND(PhiNO_400,3);
	output["qL_400"]			= MathROUND(qL_400,3);
    output['FvP/Fm_400_P']		= MathROUND(FvP_Fm_400_P,3);
    output['qP_400']			= MathROUND(qP_400,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((fv_400_fm  * 0.45 * json.light_intensity),3);
}

if (Fs_400_std > 100) {
	danger("noisy Fs_400", output);
}
/*
if (A0FmP_std > 300) {
	danger("noisy Fm_400_Prime", output);
}
*/
if (Fm_400_P_step1_std > 120 | Fm_400_P_step2_std > 120 | Fm_400_P_step3_std > 120 | Fm_400_P_end_std > 300) {
	danger("noisy  multi-phase flash steps",output);
}

if (Fo_400_Prime_std > 150) {
	danger("noisy Fo_400_Prime", output);
}
/*
if (reg_400.m > 0) {
	info("Used Phi2_400 and not Phi2_400 MPF - ambient light level was too low to apply MPF calculation", output);
}
if (Fm_400_P_end/A0FmP - A0FmP/A0FmP > .1) {	
	info("Fm_400_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_400_P_end/A0FmP - A0FmP/A0FmP < -.1) {
	info("Fm_400_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 VALUES FROM MACRO fro 100umol*******************/

// If multi-phase flash steps are flat or positive slope, then just use the normal Phi2, NPQt, PhiNPQ_5000, PhiNO_500... 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_500.m > 0) {
  fv_500_fm = fv_500_fm_noMPF;
  npqt_500= npqt_500_noMPF;
  PhiNO_500= PhiNO_500_noMPF;
  PhiNPQ_500= PhiNPQ_500_noMPF;
  qL_500= qL_500_noMPF;
  Fm_500_Prime = A0FmP;
  qP = qP_500_noMPF;
  FvP_Fm_500_P = fv_500_fm_noMPF;
  
  if (fv_500_fm <= 0) {
    output["Phi2_500"] 			= 0;
	warning('Phi2_500is 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_500_noMPF"] 	= MathROUND(npqt_500,3);
  }
  if (fv_500_fm >=.85) {
    output["Phi2_500"] 			= -1;
	danger("Phi2_500above the normal range (0 - 0.85).  Please check the raw trace and seriously consider excluding this point.", output);

  }
  else {
	  output["Phi2_500"] 		= MathROUND(fv_500_fm,3);
  }
  
  if (npqt_500<= 0) {
	output["PhiNPQ_500"]		= 0;
    output["NPQt_500"]			= 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_500_noMPF and PhiNPQ_noMPF variable",output);
	output["PhiNPQ_500_noMPF"]  = MathROUND(PhiNPQ_500,3);
	output["npqt_500_noMPF"]	= MathROUND(npqt_500,3);
  }
  else {
	output["PhiNPQ_500"]  = MathROUND(PhiNPQ_500,3);
	output["NPQt_500"]		= MathROUND(npqt_500,3);
  }
	output["PhiNO_500"]		= MathROUND(PhiNO_500,3);
	output["qL_500"]		= MathROUND(qL_500,3);
    output['FvP/Fm_500_P']		= MathROUND(FvP_Fm_500_P,3);
    output['qP_500']			= MathROUND(qP_500,3);
}

// Otherwise, use the multi-phase flash calculation for Phi2, NPQt, PhiNPQ, PhiNO_500... 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_500_fm <= 0) {
    output["Phi2_500"] 			= 0;
	warning("Phi2_500is 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_500_MPF"] 	= MathROUND(npqt_500,3);
  }
  if (fv_500_fm >=.85) {
    output["Phi2_500"] 			= -1;
	danger("Phi2_500above the normal range (0 - 0.85).  Please check the raw trace and seriously consider excluding this point.", output);
  }
  else {
    output["Phi2_500"]			= MathROUND(fv_500_fm,3);
  }
  if (npqt_500<= 0) {
	output["PhiNPQ_500"]		= 0;
    output["NPQt_500"]			= 0;
	warning("NPQt_500is 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_500_MPF and PhiNPQ_MPF variables",output);
	output["PhiNPQ_500_MPF"]  = MathROUND(PhiNPQ,3);
	output["npqt_500_MPF"]		= MathROUND(npqt_500,3);
  }
  else {
	output["PhiNPQ_500"]  = MathROUND(PhiNPQ_500,3);
	output["NPQt_500"]		= MathROUND(npqt_500,3);
  }
	output["PhiNO_500"]		= MathROUND(PhiNO_500,3);
	output["qL_500"]			= MathROUND(qL_500,3);
    output['FvP/Fm_500_P']		= MathROUND(FvP_Fm_500_P,3);
    output['qP_500']			= MathROUND(qP_500,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((fv_500_fm  * 0.45 * json.light_intensity),3);
}

if (Fs_500_std > 100) {
	danger("noisy Fs_500", output);
}
/*
if (A0FmP_std > 300) {
	danger("noisy Fm_500_Prime", output);
}
*/
if (Fm_500_P_step1_std > 120 | Fm_500_P_step2_std > 120 | Fm_500_P_step3_std > 120 | Fm_500_P_end_std > 300) {
	danger("noisy  multi-phase flash steps",output);
}

if (Fo_500_Prime_std > 150) {
	danger("noisy Fo_500_Prime", output);
}
/*
if (reg_500.m > 0) {
	info("Used Phi2_500and not Phi2_500MPF - ambient light level was too low to apply MPF calculation", output);
}
if (Fm_500_P_end/A0FmP - A0FmP/A0FmP > .1) {	
	info("Fm_500_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_500_P_end/A0FmP - A0FmP/A0FmP < -.1) {
	info("Fm_500_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_400_Prime"] 		= MathROUND(Fm_400_Prime,3);
output["Fs_400"] 			= MathROUND(Fs_400,1);
output['Fo_400_Prime']		= MathROUND(Fo_400_Prime,0);
output["RFd"]           = Number(MathROUND(((Fm_400_Prime/Fs_400)-1),3));
//output["ratio MPF/noMPF, Phi2_400"] = MathROUND(fv_400_fm_MPF / fv_400_fm_noMPF,5);
//output["ratio MPF/noMPF, PhiNPQ_400"] = MathROUND(PhiNPQ_400_MPF / PhiNPQ_400_noMPF,5);
//output["ratio MPF/noMPF, PhiNO_400"] = MathROUND(PhiNO_400_MPF / PhiNO_400_noMPF,5);
//output["ratio MPF/noMPF, PhiNO_400"] = MathROUND(npqt_400_MPF / npqt_400_noMPF,5);
output["MPF_slope_400"] 	= MathROUND(reg_400.m,3);
output["MPF_rsquared_400"] 	= MathROUND(reg_400.r,3);
/*
output["Phi2_400_MPF"] 		= MathROUND(fv_400_fm_MPF,3);
output["Phi2_400_noMPF"] 	= MathROUND(fv_400_fm,3);
output["Fm_400_Prime_MPF"] 	= MathROUND(reg_400.b,3);
output["Fm_400_Prime_noMPF"] = MathROUND(A0FmP,1);
output['qL_400_MPF']		= MathROUND(qL_400_MPF,3);
output['qL_400_noMPF']      = MathROUND(qL,3);
output['PhiNPQ_MPF']    = MathROUND(PhiNPQ_MPF,3);
output['PhiNPQ_noMPF']  = MathROUND(PhiNPQ,3);
output['PhiNO_400_MPF']		= MathROUND(PhiNO_400_MPF,3);
output['PhiNO_400_noMPF']	= MathROUND(PhiNO_400,3);
output["Fs_400_std"] 			= MathROUND(Fs_400_std,1);
output["A0FmP_std"] 			= MathROUND(A0FmP_std,1);
output["Fm_400_P_step1_std"] 	= MathROUND(Fm_400_P_step1_std,1);
output["Fm_400_P_step2_std"] 	= MathROUND(Fm_400_P_step2_std,1);
output["Fm_400_P_step3_std"] 	= MathROUND(Fm_400_P_step3_std,1);
output["Fm_400_P_end_std"] 		= MathROUND(Fm_400_P_end_std,1);
output["Fo_400_Prime_std"] 			= MathROUND(Fo_400_Prime_std,1);
*/

//output["Fm_400_P_step1"] = MathROUND(Fm_400_P_step1,3);
//output["Fm_400_P_step2"] = MathROUND(Fm_400_P_step2,3);
//output["Fm_400_P_step3"] = MathROUND(Fm_400_P_step3,3);
//output["intensity inverse"] = inverse_intensity;
//output["steps"] = [A0FmP,Fm_400_P_step1,Fm_400_P_step2,Fm_400_P_step3];
//output["slopey"] = Fm_400_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["Fm_500_Prime"] 		= MathROUND(Fm_500_Prime,3);
output["Fs_500"] 			= MathROUND(Fs_500,1);
output['Fo_500_Prime']		= MathROUND(Fo_500_Prime,0);
output["RFd"]           = Number(MathROUND(((Fm_500_Prime/Fs_500)-1),3));
//output["ratio MPF/noMPF, Phi2_500"] = MathROUND(fv_500_fm_MPF / fv_500_fm_noMPF,5);
//output["ratio MPF/noMPF, PhiNPQ_500"] = MathROUND(PhiNPQ_500_MPF / PhiNPQ_500_noMPF,5);
//output["ratio MPF/noMPF, PhiNO_500"] = MathROUND(PhiNO_500_MPF / PhiNO_500_noMPF,5);
//output["ratio MPF/noMPF, PhiNO_500"] = MathROUND(npqt_500_MPF / npqt_500_noMPF,5);
output["MPF_slope_500"] 	= MathROUND(reg_500.m,3);
output["MPF_rsquared_500"] 	= MathROUND(reg_500.r,3);
/*
output["Phi2_500_MPF"] 		= MathROUND(fv_500_fm_MPF,3);
output["Phi2_500_noMPF"] 	= MathROUND(fv_500_fm,3);
output["Fm_500_Prime_MPF"] 	= MathROUND(reg_500.b,3);
output["Fm_500_Prime_noMPF"] = MathROUND(A0FmP,1);
output['qL_500_MPF']		= MathROUND(qL_500_MPF,3);
output['qL_500_noMPF']      = MathROUND(qL,3);
output['PhiNPQ_MPF']    = MathROUND(PhiNPQ_MPF,3);
output['PhiNPQ_noMPF']  = MathROUND(PhiNPQ,3);
output['PhiNO_500_MPF']		= MathROUND(PhiNO_500_MPF,3);
output['PhiNO_500_noMPF']	= MathROUND(PhiNO_500,3);
output["Fs_500_std"] 			= MathROUND(Fs_500_std,1);
output["A0FmP_std"] 			= MathROUND(A0FmP_std,1);
output["Fm_500_P_step1_std"] 	= MathROUND(Fm_500_P_step1_std,1);
output["Fm_500_P_step2_std"] 	= MathROUND(Fm_500_P_step2_std,1);
output["Fm_500_P_step3_std"] 	= MathROUND(Fm_500_P_step3_std,1);
output["Fm_500_P_end_std"] 		= MathROUND(Fm_500_P_end_std,1);
output["Fo_500_Prime_std"] 			= MathROUND(Fo_500_Prime_std,1);
*/

//output["Fm_500_P_step1"] = MathROUND(Fm_500_P_step1,3);
//output["Fm_500_P_step2"] = MathROUND(Fm_500_P_step2,3);
//output["Fm_500_P_step3"] = MathROUND(Fm_500_P_step3,3);
//output["intensity inverse"] = inverse_intensity;
//output["steps"] = [A0FmP,Fm_500_P_step1,Fm_500_P_step2,Fm_500_P_step3];
//output["slopey"] = Fm_500_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_400","PhiNPQ_400","PhiNO_400","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_600, PhiNO_600... 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_600.m > 0) {
  fv_600_fm = fv_600_fm_noMPF;
  npqt_600 = npqt_600_noMPF;
  PhiNO_600 = PhiNO_600_noMPF;
  PhiNPQ_600 = PhiNPQ_600_noMPF;
  qL_600 = qL_600_noMPF;
  Fm_600_Prime = A0FmP;
  qP = qP_600_noMPF;
  FvP_Fm_600_P = fv_600_fm_noMPF;
  
  if (fv_600_fm <= 0) {
    output["Phi2_600"] 			= 0;
	warning('Phi2_600 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_600_noMPF"] 	= MathROUND(npqt_600,3);
  }
  if (fv_600_fm >=.85) {
    output["Phi2_600"] 			= -1;
	danger("Phi2_600 above the normal range (0 - 0.85).  Please check the raw trace and seriously consider excluding this point.", output);

  }
  else {
	  output["Phi2_600"] 		= MathROUND(fv_600_fm,3);
  }
  
  if (npqt_600 <= 0) {
	output["PhiNPQ_600"]		= 0;
    output["NPQt_600"]			= 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_600_noMPF and PhiNPQ_noMPF variable",output);
	output["PhiNPQ_600_noMPF"]  = MathROUND(PhiNPQ_600,3);
	output["npqt_600_noMPF"]	= MathROUND(npqt_600,3);
  }
  else {
	output["PhiNPQ_600"]  = MathROUND(PhiNPQ_600,3);
	output["NPQt_600"]		= MathROUND(npqt_600,3);
  }
	output["PhiNO_600"]		= MathROUND(PhiNO_600,3);
	output["qL_600"]		= MathROUND(qL_600,3);
    output['FvP/Fm_600_P']		= MathROUND(FvP_Fm_600_P,3);
    output['qP_600']			= MathROUND(qP_600,3);
}

// Otherwise, use the multi-phase flash calculation for Phi2, NPQt, PhiNPQ, PhiNO_600... 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_600_fm <= 0) {
    output["Phi2_600"] 			= 0;
	warning("Phi2_600 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_600_MPF"] 	= MathROUND(npqt_600,3);
  }
  if (fv_600_fm >=.85) {
    output["Phi2_600"] 			= -1;
	danger("Phi2_600 above the normal range (0 - 0.85).  Please check the raw trace and seriously consider excluding this point.", output);
  }
  else {
    output["Phi2_600"]			= MathROUND(fv_600_fm,3);
  }
  if (npqt_600 <= 0) {
	output["PhiNPQ_600"]		= 0;
    output["NPQt_600"]			= 0;
	warning("NPQt_600 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_600_MPF and PhiNPQ_MPF variables",output);
	output["PhiNPQ_600_MPF"]  = MathROUND(PhiNPQ,3);
	output["npqt_600_MPF"]		= MathROUND(npqt_600,3);
  }
  else {
	output["PhiNPQ_600"]  = MathROUND(PhiNPQ_600,3);
	output["NPQt_600"]		= MathROUND(npqt_600,3);
  }
	output["PhiNO_600"]		= MathROUND(PhiNO_600,3);
	output["qL_600"]			= MathROUND(qL_600,3);
    output['FvP/Fm_600_P']		= MathROUND(FvP_Fm_600_P,3);
    output['qP_600']			= MathROUND(qP_600,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((fv_600_fm  * 0.45 * json.light_intensity),3);
}

if (Fs_600_std > 100) {
	danger("noisy Fs_600", output);
}
/*
if (A0FmP_std > 300) {
	danger("noisy Fm_600_Prime", output);
}
*/
if (Fm_600_P_step1_std > 120 | Fm_600_P_step2_std > 120 | Fm_600_P_step3_std > 120 | Fm_600_P_end_std > 300) {
	danger("noisy  multi-phase flash steps",output);
}

if (Fo_600_Prime_std > 150) {
	danger("noisy Fo_600_Prime", output);
}
/*
if (reg_600.m > 0) {
	info("Used Phi2_600 and not Phi2_600 MPF - ambient light level was too low to apply MPF calculation", output);
}
if (Fm_600_P_end/A0FmP - A0FmP/A0FmP > .1) {	
	info("Fm_600_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_600_P_end/A0FmP - A0FmP/A0FmP < -.1) {
	info("Fm_600_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_600_Prime"] 		= MathROUND(Fm_600_Prime,3);
output["Fs_600"] 			= MathROUND(Fs_600,1);
output['Fo_600_Prime']		= MathROUND(Fo_600_Prime,0);
output["RFd"]           = Number(MathROUND(((Fm_600_Prime/Fs_600)-1),3));
//output["ratio MPF/noMPF, Phi2_600"] = MathROUND(fv_600_fm_MPF / fv_600_fm_noMPF,5);
//output["ratio MPF/noMPF, PhiNPQ_600"] = MathROUND(PhiNPQ_600_MPF / PhiNPQ_600_noMPF,5);
//output["ratio MPF/noMPF, PhiNO_600"] = MathROUND(PhiNO_600_MPF / PhiNO_600_noMPF,5);
//output["ratio MPF/noMPF, PhiNO_600"] = MathROUND(npqt_600_MPF / npqt_600_noMPF,5);
output["MPF_slope_600"] 	= MathROUND(reg_600.m,3);
output["MPF_rsquared_600"] 	= MathROUND(reg_600.r,3);
/*
output["Phi2_600_MPF"] 		= MathROUND(fv_600_fm_MPF,3);
output["Phi2_600_noMPF"] 	= MathROUND(fv_600_fm,3);
output["Fm_600_Prime_MPF"] 	= MathROUND(reg_600.b,3);
output["Fm_600_Prime_noMPF"] = MathROUND(A0FmP,1);
output['qL_600_MPF']		= MathROUND(qL_600_MPF,3);
output['qL_600_noMPF']      = MathROUND(qL,3);
output['PhiNPQ_MPF']    = MathROUND(PhiNPQ_MPF,3);
output['PhiNPQ_noMPF']  = MathROUND(PhiNPQ,3);
output['PhiNO_600_MPF']		= MathROUND(PhiNO_600_MPF,3);
output['PhiNO_600_noMPF']	= MathROUND(PhiNO_600,3);
output["Fs_600_std"] 			= MathROUND(Fs_600_std,1);
output["A0FmP_std"] 			= MathROUND(A0FmP_std,1);
output["Fm_600_P_step1_std"] 	= MathROUND(Fm_600_P_step1_std,1);
output["Fm_600_P_step2_std"] 	= MathROUND(Fm_600_P_step2_std,1);
output["Fm_600_P_step3_std"] 	= MathROUND(Fm_600_P_step3_std,1);
output["Fm_600_P_end_std"] 		= MathROUND(Fm_600_P_end_std,1);
output["Fo_600_Prime_std"] 			= MathROUND(Fo_600_Prime_std,1);
*/

//output["Fm_600_P_step1"] = MathROUND(Fm_600_P_step1,3);
//output["Fm_600_P_step2"] = MathROUND(Fm_600_P_step2,3);
//output["Fm_600_P_step3"] = MathROUND(Fm_600_P_step3,3);
//output["intensity inverse"] = inverse_intensity;
//output["steps"] = [A0FmP,Fm_600_P_step1,Fm_600_P_step2,Fm_600_P_step3];
//output["slopey"] = Fm_600_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_600","PhiNPQ_600","PhiNO_600","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_800, PhiNO_800... 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_800.m > 0) {
  fv_800_fm = fv_800_fm_noMPF;
  npqt_800 = npqt_800_noMPF;
  PhiNO_800 = PhiNO_800_noMPF;
  PhiNPQ_800 = PhiNPQ_800_noMPF;
  qL_800 = qL_800_noMPF;
  Fm_800_Prime = A0FmP;
  qP = qP_800_noMPF;
  FvP_Fm_800_P = fv_800_fm_noMPF;
  
  if (fv_800_fm <= 0) {
    output["Phi2_800"] 			= 0;
	warning('Phi2_800 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_800_noMPF"] 	= MathROUND(npqt_800,3);
  }
  if (fv_800_fm >=.85) {
    output["Phi2_800"] 			= -1;
	danger("Phi2_800 above the normal range (0 - 0.85).  Please check the raw trace and seriously consider excluding this point.", output);

  }
  else {
	  output["Phi2_800"] 		= MathROUND(fv_800_fm,3);
  }
  
  if (npqt_800 <= 0) {
	output["PhiNPQ_800"]		= 0;
    output["NPQt_800"]			= 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_800_noMPF and PhiNPQ_noMPF variable",output);
	output["PhiNPQ_800_noMPF"]  = MathROUND(PhiNPQ_800,3);
	output["npqt_800_noMPF"]	= MathROUND(npqt_800,3);
  }
  else {
	output["PhiNPQ_800"]  = MathROUND(PhiNPQ_800,3);
	output["NPQt_800"]		= MathROUND(npqt_800,3);
  }
	output["PhiNO_800"]		= MathROUND(PhiNO_800,3);
	output["qL_800"]		= MathROUND(qL_800,3);
    output['FvP/Fm_800_P']		= MathROUND(FvP_Fm_800_P,3);
    output['qP_800']			= MathROUND(qP_800,3);
}

// Otherwise, use the multi-phase flash calculation for Phi2, NPQt, PhiNPQ, PhiNO_800... 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_800_fm <= 0) {
    output["Phi2_800"] 			= 0;
	warning("Phi2_800 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_800_MPF"] 	= MathROUND(npqt_800,3);
  }
  if (fv_800_fm >=.85) {
    output["Phi2_800"] 			= -1;
	danger("Phi2_800 above the normal range (0 - 0.85).  Please check the raw trace and seriously consider excluding this point.", output);
  }
  else {
    output["Phi2_800"]			= MathROUND(fv_800_fm,3);
  }
  if (npqt_800 <= 0) {
	output["PhiNPQ_800"]		= 0;
    output["NPQt_800"]			= 0;
	warning("NPQt_800 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_800_MPF and PhiNPQ_MPF variables",output);
	output["PhiNPQ_800_MPF"]  = MathROUND(PhiNPQ,3);
	output["npqt_800_MPF"]		= MathROUND(npqt_800,3);
  }
  else {
	output["PhiNPQ_800"]  = MathROUND(PhiNPQ_800,3);
	output["NPQt_800"]		= MathROUND(npqt_800,3);
  }
	output["PhiNO_800"]		= MathROUND(PhiNO_800,3);
	output["qL_800"]			= MathROUND(qL_800,3);
    output['FvP/Fm_800_P']		= MathROUND(FvP_Fm_800_P,3);
    output['qP_800']			= MathROUND(qP_800,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((fv_800_fm  * 0.45 * json.light_intensity),3);
}

if (Fs_800_std > 100) {
	danger("noisy Fs_800", output);
}
/*
if (A0FmP_std > 300) {
	danger("noisy Fm_800_Prime", output);
}
*/
if (Fm_800_P_step1_std > 120 | Fm_800_P_step2_std > 120 | Fm_800_P_step3_std > 120 | Fm_800_P_end_std > 300) {
	danger("noisy  multi-phase flash steps",output);
}

if (Fo_800_Prime_std > 150) {
	danger("noisy Fo_800_Prime", output);
}
/*
if (reg_800.m > 0) {
	info("Used Phi2_800 and not Phi2_800 MPF - ambient light level was too low to apply MPF calculation", output);
}
if (Fm_800_P_end/A0FmP - A0FmP/A0FmP > .1) {	
	info("Fm_800_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_800_P_end/A0FmP - A0FmP/A0FmP < -.1) {
	info("Fm_800_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_800_Prime"] 		= MathROUND(Fm_800_Prime,3);
output["Fs_800"] 			= MathROUND(Fs_800,1);
output['Fo_800_Prime']		= MathROUND(Fo_800_Prime,0);
output["RFd"]           = Number(MathROUND(((Fm_800_Prime/Fs_800)-1),3));
//output["ratio MPF/noMPF, Phi2_800"] = MathROUND(fv_800_fm_MPF / fv_800_fm_noMPF,5);
//output["ratio MPF/noMPF, PhiNPQ_800"] = MathROUND(PhiNPQ_800_MPF / PhiNPQ_800_noMPF,5);
//output["ratio MPF/noMPF, PhiNO_800"] = MathROUND(PhiNO_800_MPF / PhiNO_800_noMPF,5);
//output["ratio MPF/noMPF, PhiNO_800"] = MathROUND(npqt_800_MPF / npqt_800_noMPF,5);
output["MPF_slope_800"] 	= MathROUND(reg_800.m,3);
output["MPF_rsquared_800"] 	= MathROUND(reg_800.r,3);
/*
output["Phi2_800_MPF"] 		= MathROUND(fv_800_fm_MPF,3);
output["Phi2_800_noMPF"] 	= MathROUND(fv_800_fm,3);
output["Fm_800_Prime_MPF"] 	= MathROUND(reg_800.b,3);
output["Fm_800_Prime_noMPF"] = MathROUND(A0FmP,1);
output['qL_800_MPF']		= MathROUND(qL_800_MPF,3);
output['qL_800_noMPF']      = MathROUND(qL,3);
output['PhiNPQ_MPF']    = MathROUND(PhiNPQ_MPF,3);
output['PhiNPQ_noMPF']  = MathROUND(PhiNPQ,3);
output['PhiNO_800_MPF']		= MathROUND(PhiNO_800_MPF,3);
output['PhiNO_800_noMPF']	= MathROUND(PhiNO_800,3);
output["Fs_800_std"] 			= MathROUND(Fs_800_std,1);
output["A0FmP_std"] 			= MathROUND(A0FmP_std,1);
output["Fm_800_P_step1_std"] 	= MathROUND(Fm_800_P_step1_std,1);
output["Fm_800_P_step2_std"] 	= MathROUND(Fm_800_P_step2_std,1);
output["Fm_800_P_step3_std"] 	= MathROUND(Fm_800_P_step3_std,1);
output["Fm_800_P_end_std"] 		= MathROUND(Fm_800_P_end_std,1);
output["Fo_800_Prime_std"] 			= MathROUND(Fo_800_Prime_std,1);
*/

//output["Fm_800_P_step1"] = MathROUND(Fm_800_P_step1,3);
//output["Fm_800_P_step2"] = MathROUND(Fm_800_P_step2,3);
//output["Fm_800_P_step3"] = MathROUND(Fm_800_P_step3,3);
//output["intensity inverse"] = inverse_intensity;
//output["steps"] = [A0FmP,Fm_800_P_step1,Fm_800_P_step2,Fm_800_P_step3];
//output["slopey"] = Fm_800_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_800","PhiNPQ_800","PhiNO_800","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_1000, PhiNO_1000... 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_1000.m > 0) {
  fv_1000_fm = fv_1000_fm_noMPF;
  npqt_1000 = npqt_1000_noMPF;
  PhiNO_1000 = PhiNO_1000_noMPF;
  PhiNPQ_1000 = PhiNPQ_1000_noMPF;
  qL_1000 = qL_1000_noMPF;
  Fm_1000_Prime = A0FmP;
  qP = qP_1000_noMPF;
  FvP_Fm_1000_P = fv_1000_fm_noMPF;
  
  if (fv_1000_fm <= 0) {
    output["Phi2_1000"] 			= 0;
	warning('Phi2_1000 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_1000_noMPF"] 	= MathROUND(npqt_1000,3);
  }
  if (fv_1000_fm >=.85) {
    output["Phi2_1000"] 			= -1;
	danger("Phi2_1000 above the normal range (0 - 0.85).  Please check the raw trace and seriously consider excluding this point.", output);

  }
  else {
	  output["Phi2_1000"] 		= MathROUND(fv_1000_fm,3);
  }
  
  if (npqt_1000 <= 0) {
	output["PhiNPQ_1000"]		= 0;
    output["NPQt_1000"]			= 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_1000_noMPF and PhiNPQ_noMPF variable",output);
	output["PhiNPQ_1000_noMPF"]  = MathROUND(PhiNPQ_1000,3);
	output["npqt_1000_noMPF"]	= MathROUND(npqt_1000,3);
  }
  else {
	output["PhiNPQ_1000"]  = MathROUND(PhiNPQ_1000,3);
	output["NPQt_1000"]		= MathROUND(npqt_1000,3);
  }
	output["PhiNO_1000"]		= MathROUND(PhiNO_1000,3);
	output["qL_1000"]		= MathROUND(qL_1000,3);
    output['FvP/Fm_1000_P']		= MathROUND(FvP_Fm_1000_P,3);
    output['qP_1000']			= MathROUND(qP_1000,3);
}

// Otherwise, use the multi-phase flash calculation for Phi2, NPQt, PhiNPQ, PhiNO_1000... 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_1000_fm <= 0) {
    output["Phi2_1000"] 			= 0;
	warning("Phi2_1000 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_1000_MPF"] 	= MathROUND(npqt_1000,3);
  }
  if (fv_1000_fm >=.85) {
    output["Phi2_1000"] 			= -1;
	danger("Phi2_1000 above the normal range (0 - 0.85).  Please check the raw trace and seriously consider excluding this point.", output);
  }
  else {
    output["Phi2_1000"]			= MathROUND(fv_1000_fm,3);
  }
  if (npqt_1000 <= 0) {
	output["PhiNPQ_1000"]		= 0;
    output["NPQt_1000"]			= 0;
	warning("NPQt_1000 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_1000_MPF and PhiNPQ_MPF variables",output);
	output["PhiNPQ_1000_MPF"]  = MathROUND(PhiNPQ,3);
	output["npqt_1000_MPF"]		= MathROUND(npqt_1000,3);
  }
  else {
	output["PhiNPQ_1000"]  = MathROUND(PhiNPQ_1000,3);
	output["NPQt_1000"]		= MathROUND(npqt_1000,3);
  }
	output["PhiNO_1000"]		= MathROUND(PhiNO_1000,3);
	output["qL_1000"]			= MathROUND(qL_1000,3);
    output['FvP/Fm_1000_P']		= MathROUND(FvP_Fm_1000_P,3);
    output['qP_1000']			= MathROUND(qP_1000,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((fv_1000_fm  * 0.45 * json.light_intensity),3);
}

if (Fs_1000_std > 100) {
	danger("noisy Fs_1000", output);
}
/*
if (A0FmP_std > 300) {
	danger("noisy Fm_1000_Prime", output);
}
*/
if (Fm_1000_P_step1_std > 120 | Fm_1000_P_step2_std > 120 | Fm_1000_P_step3_std > 120 | Fm_1000_P_end_std > 300) {
	danger("noisy  multi-phase flash steps",output);
}

if (Fo_1000_Prime_std > 150) {
	danger("noisy Fo_1000_Prime", output);
}
/*
if (reg_1000.m > 0) {
	info("Used Phi2_1000 and not Phi2_1000 MPF - ambient light level was too low to apply MPF calculation", output);
}
if (Fm_1000_P_end/A0FmP - A0FmP/A0FmP > .1) {	
	info("Fm_1000_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_1000_P_end/A0FmP - A0FmP/A0FmP < -.1) {
	info("Fm_1000_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_1000_Prime"] 		= MathROUND(Fm_1000_Prime,3);
output["Fs_1000"] 			= MathROUND(Fs_1000,1);
output['Fo_1000_Prime']		= MathROUND(Fo_1000_Prime,0);
output["RFd"]           = Number(MathROUND(((Fm_1000_Prime/Fs_1000)-1),3));
//output["ratio MPF/noMPF, Phi2_1000"] = MathROUND(fv_1000_fm_MPF / fv_1000_fm_noMPF,5);
//output["ratio MPF/noMPF, PhiNPQ_1000"] = MathROUND(PhiNPQ_1000_MPF / PhiNPQ_1000_noMPF,5);
//output["ratio MPF/noMPF, PhiNO_1000"] = MathROUND(PhiNO_1000_MPF / PhiNO_1000_noMPF,5);
//output["ratio MPF/noMPF, PhiNO_1000"] = MathROUND(npqt_1000_MPF / npqt_1000_noMPF,5);
output["MPF_slope_1000"] 	= MathROUND(reg_1000.m,3);
output["MPF_rsquared_1000"] 	= MathROUND(reg_1000.r,3);
/*
output["Phi2_1000_MPF"] 		= MathROUND(fv_1000_fm_MPF,3);
output["Phi2_1000_noMPF"] 	= MathROUND(fv_1000_fm,3);
output["Fm_1000_Prime_MPF"] 	= MathROUND(reg_1000.b,3);
output["Fm_1000_Prime_noMPF"] = MathROUND(A0FmP,1);
output['qL_1000_MPF']		= MathROUND(qL_1000_MPF,3);
output['qL_1000_noMPF']      = MathROUND(qL,3);
output['PhiNPQ_MPF']    = MathROUND(PhiNPQ_MPF,3);
output['PhiNPQ_noMPF']  = MathROUND(PhiNPQ,3);
output['PhiNO_1000_MPF']		= MathROUND(PhiNO_1000_MPF,3);
output['PhiNO_1000_noMPF']	= MathROUND(PhiNO_1000,3);
output["Fs_1000_std"] 			= MathROUND(Fs_1000_std,1);
output["A0FmP_std"] 			= MathROUND(A0FmP_std,1);
output["Fm_1000_P_step1_std"] 	= MathROUND(Fm_1000_P_step1_std,1);
output["Fm_1000_P_step2_std"] 	= MathROUND(Fm_1000_P_step2_std,1);
output["Fm_1000_P_step3_std"] 	= MathROUND(Fm_1000_P_step3_std,1);
output["Fm_1000_P_end_std"] 		= MathROUND(Fm_1000_P_end_std,1);
output["Fo_1000_Prime_std"] 			= MathROUND(Fo_1000_Prime_std,1);
*/

//output["Fm_1000_P_step1"] = MathROUND(Fm_1000_P_step1,3);
//output["Fm_1000_P_step2"] = MathROUND(Fm_1000_P_step2,3);
//output["Fm_1000_P_step3"] = MathROUND(Fm_1000_P_step3,3);
//output["intensity inverse"] = inverse_intensity;
//output["steps"] = [A0FmP,Fm_1000_P_step1,Fm_1000_P_step2,Fm_1000_P_step3];
//output["slopey"] = Fm_1000_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_1000","PhiNPQ_1000","PhiNO_1000","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": 1500386615704,
  "device_name": "MultispeQ",
  "device_version": "1",
  "device_id": "01:12:38:86",
  "device_battery": 77,
  "device_firmware": 1.17,
  "sample": [
    {
      "time": 1500386615719,
      "protocol_id": 1,
      "detector_read1": 8607,
      "light_intensity": 47,
      "r": 45,
      "g": 20,
      "b": 17,
      "light_intensity_raw": 73,
      "temperature": 23.459999,
      "humidity": 66.548828,
      "pressure": 984.45282,
      "temperature2": 23.370001,
      "humidity2": 65.449219,
      "pressure2": 984.670776,
      "contactless_temp": 23.39,
      "thickness": 0.93,
      "compass_direction": "E",
      "compass": "90.00",
      "angle": 6.71,
      "angle_direction": "E",
      "pitch": -1.56,
      "roll": 6.52,
      "recall": {
        "time": 1500386631657,
        "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": [
        17589,
        17574,
        17558,
        17543,
        17538,
        17527,
        17511,
        17505,
        17497,
        17477,
        17463,
        17463,
        17442,
        17439,
        17427,
        17420,
        17411,
        17398,
        17390,
        17383,
        18335,
        18415,
        18442,
        18445,
        18439,
        18441,
        18421,
        18415,
        18405,
        18399,
        18404,
        18393,
        18388,
        18378,
        18366,
        18374,
        18370,
        18361,
        18348,
        18344,
        18339,
        18341,
        18335,
        18314,
        18317,
        18311,
        18309,
        18303,
        18290,
        18294,
        18251,
        18228,
        18227,
        18231,
        18221,
        18222,
        18208,
        18209,
        18209,
        18200,
        18133,
        18135,
        18117,
        18120,
        18111,
        18113,
        18115,
        18103,
        18097,
        18097,
        18016,
        18004,
        17990,
        17996,
        17989,
        17994,
        17976,
        17979,
        17983,
        17980,
        18137,
        18163,
        18164,
        18156,
        18149,
        18147,
        18145,
        18135,
        18130,
        18127,
        18118,
        18117,
        18109,
        18107,
        18106,
        18095,
        18091,
        18091,
        18079,
        18071,
        18076,
        18071,
        18055,
        18061,
        18055,
        18048,
        18049,
        18035,
        18036,
        18027,
        11553,
        9407,
        8600,
        8278,
        8131,
        8047,
        7999,
        7955,
        7925,
        7905,
        7887,
        7868,
        7847,
        7844,
        7837,
        7823,
        7806,
        7795,
        7791,
        7780,
        5247,
        5043,
        4977,
        4933,
        4902,
        4884,
        4867,
        4858,
        4855,
        4846,
        4842,
        4830,
        4827,
        4831,
        4827,
        4821,
        4813,
        4821,
        4820,
        4813,
        4810,
        4814,
        4814,
        4806,
        4807,
        4811,
        4811,
        4805,
        4810,
        4809,
        4807,
        4805,
        4807,
        4806,
        4804,
        4803,
        4806,
        4807,
        4802,
        4808,
        4810,
        4807,
        4799,
        4803,
        4807,
        4807,
        4798,
        4805,
        4810,
        4807,
        4799,
        4805,
        4807,
        4810,
        4801,
        4810,
        4811,
        4806,
        4801,
        4807,
        4806,
        4806,
        4803,
        4810,
        4807,
        4807,
        4805,
        4807,
        4809,
        4805,
        4807,
        4809,
        4810,
        4811,
        4805,
        4810,
        4813,
        4810,
        4804,
        4811,
        4813,
        4813,
        4805,
        4813,
        4812,
        4814,
        4807,
        4814,
        4815,
        4815,
        4808,
        4812,
        4817,
        4815,
        4817,
        4809,
        4814,
        4818,
        4817,
        4812,
        4817,
        4819,
        4819,
        4817,
        4809,
        4821,
        4822,
        4822,
        4813,
        4819,
        4823,
        4822,
        4823,
        4815,
        4822,
        4825,
        4823,
        4819,
        4819,
        4827,
        4826,
        4827,
        4823,
        4821,
        4827,
        4829,
        4829,
        4823,
        4822,
        4833,
        4833,
        4831,
        4823,
        4828,
        4833,
        4834,
        4835,
        4827,
        4827,
        4834,
        4838,
        4838,
        4831,
        4827,
        4839,
        4838,
        4838,
        4837,
        4833,
        4833,
        16743,
        16745,
        16738,
        16735,
        16741,
        16733,
        16729,
        16735,
        16730,
        16725,
        16727,
        16725,
        16727,
        16722,
        16719,
        16727,
        16718,
        16716,
        16723,
        16715,
        17223,
        17285,
        17301,
        17297,
        17291,
        17287,
        17285,
        17276,
        17269,
        17263,
        17257,
        17251,
        17252,
        17247,
        17241,
        17241,
        17242,
        17232,
        17230,
        17221,
        17223,
        17216,
        17205,
        17207,
        17198,
        17188,
        17181,
        17175,
        17167,
        17163,
        17129,
        17121,
        17111,
        17102,
        17101,
        17095,
        17081,
        17084,
        17079,
        17066,
        17018,
        17000,
        16991,
        16988,
        16982,
        16972,
        16969,
        16964,
        16959,
        16956,
        16882,
        16863,
        16863,
        16843,
        16843,
        16838,
        16830,
        16821,
        16811,
        16811,
        16934,
        16940,
        16942,
        16935,
        16916,
        16901,
        16903,
        16880,
        16870,
        16874,
        16861,
        16854,
        16839,
        16835,
        16821,
        16807,
        16797,
        16783,
        16777,
        16763,
        16767,
        16751,
        16741,
        16738,
        16724,
        16707,
        16692,
        16689,
        16679,
        16671,
        11463,
        9450,
        8591,
        8237,
        8089,
        8017,
        7986,
        7968,
        7961,
        7958,
        7964,
        7972,
        7979,
        7981,
        7993,
        8003,
        8006,
        8011,
        8020,
        8025,
        4997,
        4852,
        4794,
        4762,
        4731,
        4719,
        4706,
        4687,
        4691,
        4682,
        4677,
        4666,
        4666,
        4666,
        4663,
        4659,
        4648,
        4649,
        4655,
        4651,
        4652,
        4650,
        4639,
        4643,
        4648,
        4646,
        4646,
        4645,
        4643,
        4636,
        4641,
        4645,
        4642,
        4643,
        4645,
        4639,
        4636,
        4643,
        4645,
        4643,
        4643,
        4638,
        4636,
        4634,
        4643,
        4642,
        4645,
        4643,
        4638,
        4637,
        4639,
        4645,
        4645,
        4644,
        4645,
        4641,
        4639,
        4643,
        4646,
        4647,
        4646,
        4642,
        4641,
        4647,
        4649,
        4647,
        4650,
        4645,
        4644,
        4647,
        4651,
        4652,
        4652,
        4653,
        4645,
        4650,
        4652,
        4653,
        4655,
        4656,
        4647,
        4651,
        4653,
        4659,
        4661,
        4660,
        4658,
        4655,
        4657,
        4664,
        4664,
        4664,
        4665,
        4658,
        4661,
        4669,
        4668,
        4670,
        4671,
        4663,
        4666,
        4674,
        4673,
        4674,
        4673,
        4671,
        4674,
        4681,
        4678,
        4679,
        4673,
        4675,
        4683,
        4682,
        4684,
        4682,
        4677,
        4683,
        4687,
        4687,
        4687,
        4689,
        4683,
        4689,
        4691,
        4691,
        4693,
        4688,
        4690,
        4698,
        4697,
        4699,
        4693,
        4692,
        4699,
        4703,
        4702,
        4705,
        4699,
        4701,
        4707,
        4710,
        4709,
        4707,
        4705,
        4711,
        4715,
        4711,
        4712,
        4709
      ]
    }
  ],
  "app_os": "mac",
  "app_name": "PhotosynQ",
  "app_version": "0.3.8",
  "app_device": "x86-64",
  "ConsoleMacro": null
}
Default avatar
Created by

Jonathan R Pleban


Protocol connections:
1
Latest Update:
Jul 2017