Leaf Photosynthesis MultispeQ V1.0 - solo ECS - RG


JUST PMF PART
// 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);

///*

var pulsedistance = 1; // pulse distance for the ECS portion of the trace in seconds
var ecsPulses = 300; // pulses during each light cycle duing ECS portion of trace (300 light on, 300 light off, 300 light on)
var fit_cutoff = .01; // valueless number indicating what portion of the decay curve to pass to the decay fitting subroutine
var hit_cutoff_times = 1;  // this is a counter to ensure we don't just hit a weird portion of the curve and cutoff too soon.   

// we need an array representing the time (in us) and data for each pulse in the ECS trace.  Subtract first and less point so it's 898 points total

var timeArray = [];
for (var i = 1; i < ecsPulses*3+1; i++) {
  timeArray[i-1] = pulsedistance*i;
}
var ecsArray = data.slice(0,ecsPulses*3);

// the very first pulse is often low.  Just set it to the 2nd pulse by default
ecsArray[0] = ecsArray[1];
// now check for big spikes
for (var i = 1; i < ecsArray.length; i++) {
// this line should be flat, or slightly sloped.  So if there are any big spikes (> 10% of the previous value) then set it equal to the previous value
  if (ecsArray[i] > 1.10*ecsArray[i-1]) {
    ecsArray[i] = ecsArray[i-1];
  }
}

//output["ecsArray raw"] = data.slice(0,ecsPulses*3);
// sanity check - do the arrays look as we expect?
//output["all_ecs length"] = ecsArray.length;
//output["all_time length"] = timeArray.length;
//output["ecsArray cleaned"] = ecsArray;

// first lets make the ECS trace flat, in case for some reason it's tilted up or down. Skip first and last point in case there were blips

var flattenData = ecsArray.slice(0,ecsPulses);
var flattenTime = timeArray.slice(0,ecsPulses);

// make some error catching things - standard deviation of the first portion of the trace... etc.
var flattenData_std = MathSTDEV(flattenData);
var endOfTrace_std =  MathSTDEV(ecsArray.slice(ecsPulses*2,ecsPulses*3));
//output["flattenData_std"] = flattenData_std;
//output["endOfTrace_std"] = endOfTrace_std;

// if the standard deviation is too high, then let's not output ECS values

// now let's run a regression to determine the slope
  
var flattenReg = MathLINREG(flattenTime,flattenData);

//output["flatten slope"] = MathROUND(flattenReg.m,4);
//output["flatten y-int"] = flattenReg.b;
// sanity check - what does the slope look like before by checking the first and last value in the initial light period?  Compare with after the flattening adjustment
//output["ecsArray pre 0"] = ecsArray[0];
//output["ecsArray pre 300"] = ecsArray[300];
//output["ecsArray"] = ecsArray;


// now we assume this slope applies to the whole ECS trace, and subtract off the slope at each point

var ecsArray_flat = ecsArray.slice(0,ecsPulses*3);
for (var i = 0; i < timeArray.length; i++) {
  var adjustment = flattenReg.m*timeArray[i]; 
  ecsArray_flat[i] = ecsArray_flat[i]-adjustment;
}
// now we can calculate the initial and max ecs values to calculate ECSt
// calculated as the median value within 25 pulses of the light-on phase (minimum) and within 50 pulses of the light off phase (maximum)
ecs_initial = MathROUND(MathMEDIAN(ecsArray_flat.slice(ecsPulses-25,ecsPulses)),2);
ecs_max = MathROUND(MathMEDIAN(ecsArray_flat.slice(ecsPulses*2-100,ecsPulses*2)),2);
ecst_estimate = ecs_max - ecs_initial;
//output["ecs_initial"] = MathROUND(MathMEDIAN(ecsArray_flat.slice(ecsPulses-25,ecsPulses)),2);
//output["ecs_max"] = MathROUND(MathMEDIAN(ecsArray_flat.slice(ecsPulses*2-100,ecsPulses*2)),2);
//output ["ECSt ="] = MathROUND(ecst_estimate,5);
//output["ecsArray flattened"] = ecsArray_flat;
// sanity check - ok these two numbers should be much closer to each other (slope has moved towards 0), and make sure our flattening worked
//output["ecsArray post 0"] = ecsArray_flat[0];
//output["ecsArray post 300"] = ecsArray_flat[300];

// Then convert these values into absorbance in the form abs = -log(Io/I), where we set Io to ecs_initial.  
// For the decay fitting subroutine, we also try to set the estimated asymptote (ecs_max) to zero - this helps the fitting subroutine reduce iterations to converge to the correct value
ecsArray_flat_log = [];
for (var i = 0; i < timeArray.length; i++) {
  var abs = MathLOG(ecs_initial/(ecsArray_flat[i])); 
  ecsArray_flat_log[i] = abs - MathLOG(ecs_initial/ecs_max);
}

//output["ECS full"] = ecsArray_flat_log;

  //output["ecs_r_squared"] = flattenReg.r;

/*if (ecs_initial <= 8000) {
  warning("There was a technical error with your measurement, please retake the measurement", output);
}

else if (ecs_initial >= 58000) {
  warning("There was a technical error with your measurement, please retake the measurement", output);
}*/

//if (ecst_estimate < 2 || json.light_intensity < 50) {
  //output["ECSt"] = 0;
  //output["vH+"] = 0;
  //output["gH+"] = 0;
  //warning("proton motive force signal too low.  May be due to low ambient light, or normal biological variation.  ECSt, vH+, and gH+ have been set to zero", output);
//}
/*if (flattenData_std > 25 || endOfTrace_std > 25) {
  output["ECSt"] = "NA";
  output["vH+"] = "NA";
  output["gH+"] = "NA";
  warning("Proton Motive Force too noisy", output);
}*/
/*if (!(flattenData_std > 25 || endOfTrace_std > 25 || ecst_estimate < 2 || json.light_intensity < 50)) {
  // Now we fit a best fit line to the curve.  We need to put our data in the format [[x,y],[x,y]...] first though
  //si esta todo bien seria... 
  */
var expData = ecsArray_flat_log.slice(ecsPulses,ecsPulses+100);
  var expTime = [];
  // normalize time to zero for the fit
  for (var i = 0; i < timeArray.slice(ecsPulses, ecsPulses*2).length; i++) {
    expTime.push(i);
  }
  //output["time array"] = expTime;
//  output["ECS decay"] = expData;

  var expFitArray = [];
  for (var i = 0; i < 99; i++) {
    expFitArray[i] = [expTime[i], expData[i]];
  }
  
  expReg = MathEXPINVREG(expFitArray);
//output = expReg;
  // questions for kevin - ECSt would be y int + outputted asymptote, correct?

  //output["asymptote"] = expReg.asymptote;
  output["ECSt"] = MathROUND(expReg.results[0],4);
  //output["expFit slope"] = expReg.slope;
  output["vH+"] = MathROUND(expReg.slope,8);
  //output["expFit lifetime"] = expReg.lifetime;
  output["gH+"] = MathROUND(expReg.lifetime,4);


// Check to make sure that the detector2 setting which determines the intensity of the green LED is not zero or maxed
if (json.detector_read2 == 65535 || json.detector_read2 < 1) {
  danger("Something is wrong with the auto-intensity calibration detector_read2.  Make sure device is stable and completely clamped on measurement.  Measure again.", output);
}

return output;
{
  "time_offset": 180,
  "time": 1501185848344,
  "device_name": "MultispeQ",
  "device_version": "1",
  "device_id": "01:06:11:88",
  "device_battery": 13,
  "device_firmware": 1.17,
  "sample": [
    {
      "time": 1501185848357,
      "protocol_id": 1,
      "data_raw": [
        17496,
        21121,
        21145,
        21157,
        21143,
        21158,
        21153,
        21155,
        21155,
        21150,
        21152,
        21153,
        21157,
        21151,
        21151,
        21154,
        21156,
        21148,
        21159,
        21148,
        21155,
        21153,
        21152,
        21150,
        21147,
        21153,
        21151,
        21151,
        21147,
        21146,
        21145,
        21155,
        21144,
        21149,
        21147,
        21145,
        21145,
        21135,
        21142,
        21142,
        21146,
        21141,
        21135,
        21145,
        21135,
        21143,
        21144,
        21129,
        21141,
        21131,
        21135,
        21132,
        21129,
        21136,
        21127,
        21135,
        21125,
        21127,
        21132,
        21130,
        21127,
        21130,
        21124,
        21129,
        21131,
        21122,
        21128,
        21117,
        21125,
        21123,
        21121,
        21127,
        21116,
        21123,
        21125,
        21122,
        21123,
        21110,
        21123,
        21124,
        21111,
        21126,
        21116,
        21121,
        21122,
        21118,
        21119,
        21109,
        21122,
        21115,
        21114,
        21117,
        21111,
        21117,
        21113,
        21109,
        21119,
        21109,
        21115,
        21110,
        21113,
        21112,
        21116,
        21107,
        21106,
        21103,
        21107,
        21108,
        21110,
        21109,
        21101,
        21103,
        21106,
        21099,
        21106,
        21104,
        21101,
        21107,
        21095,
        21101,
        21103,
        21099,
        21109,
        21103,
        21103,
        21107,
        21093,
        21101,
        21093,
        21098,
        21106,
        21093,
        21098,
        21091,
        21099,
        21096,
        21091,
        21097,
        21093,
        21097,
        21094,
        21092,
        21102,
        21093,
        21095,
        21090,
        21092,
        21097,
        21091,
        21093,
        21090,
        21086,
        21093,
        21095,
        21089,
        21092,
        21088,
        21091,
        21095,
        21089,
        21089,
        21091,
        21092,
        21092,
        21092,
        21089,
        21091,
        21088,
        21089,
        21083,
        21083,
        21093,
        21080,
        21089,
        21088,
        21093,
        21091,
        21091,
        21091,
        21081,
        21086,
        21088,
        21079,
        21085,
        21087,
        21085,
        21085,
        21080,
        21083,
        21083,
        21081,
        21086,
        21083,
        21081,
        21093,
        21081,
        21082,
        21072,
        21087,
        21079,
        21085,
        21079,
        21076,
        21084,
        21084,
        21079,
        21079,
        21077,
        21076,
        21084,
        21078,
        21086,
        21077,
        21082,
        21079,
        21081,
        21080,
        21085,
        21079,
        21083,
        21081,
        21079,
        21085,
        21075,
        21080,
        21075,
        21080,
        21084,
        21075,
        21084,
        21077,
        21078,
        21085,
        21070,
        21085,
        21086,
        21080,
        21079,
        21075,
        21082,
        21078,
        21078,
        21078,
        21079,
        21081,
        21083,
        21074,
        21079,
        21079,
        21075,
        21083,
        21077,
        21082,
        21087,
        21083,
        21085,
        21078,
        21087,
        21086,
        21075,
        21082,
        21083,
        21082,
        21091,
        21079,
        21085,
        21078,
        21085,
        21080,
        21080,
        21078,
        21085,
        21075,
        21081,
        21078,
        21079,
        21086,
        21075,
        21085,
        21077,
        21085,
        21078,
        21075,
        21077,
        21078,
        21078,
        21081,
        21073,
        21085,
        21079,
        21077,
        21085,
        21071,
        21085,
        21083,
        21078,
        21078,
        21081,
        21076,
        21082,
        21009,
        21004,
        20999,
        21002,
        20998,
        21009,
        21011,
        21018,
        21011,
        21015,
        21019,
        21027,
        21019,
        21028,
        21025,
        21035,
        21034,
        21029,
        21047,
        21037,
        21043,
        21045,
        21043,
        21055,
        21045,
        21057,
        21055,
        21055,
        21062,
        21061,
        21058,
        21059,
        21063,
        21066,
        21068,
        21063,
        21067,
        21077,
        21068,
        21071,
        21077,
        21075,
        21082,
        21071,
        21083,
        21076,
        21079,
        21082,
        21077,
        21080,
        21085,
        21083,
        21082,
        21086,
        21084,
        21085,
        21083,
        21091,
        21087,
        21085,
        21087,
        21087,
        21089,
        21091,
        21086,
        21091,
        21085,
        21094,
        21090,
        21095,
        21095,
        21092,
        21093,
        21097,
        21091,
        21095,
        21088,
        21100,
        21090,
        21092,
        21092,
        21091,
        21095,
        21091,
        21098,
        21093,
        21102,
        21101,
        21100,
        21103,
        21095,
        21100,
        21093,
        21091,
        21090,
        21087,
        21095,
        21087,
        21089,
        21093,
        21086,
        21095,
        21086,
        21100,
        21096,
        21091,
        21094,
        21093,
        21099,
        21090,
        21091,
        21095,
        21094,
        21089,
        21094,
        21095,
        21093,
        21095,
        21090,
        21093,
        21091,
        21087,
        21095,
        21087,
        21094,
        21093,
        21092,
        21092,
        21093,
        21095,
        21093,
        21094,
        21089,
        21094,
        21092,
        21095,
        21092,
        21096,
        21100,
        21095,
        21099,
        21097,
        21102,
        21093,
        21093,
        21095,
        21090,
        21093,
        21094,
        21092,
        21091,
        21100,
        21093,
        21093,
        21094,
        21092,
        21100,
        21085,
        21095,
        21093,
        21091,
        21093,
        21091,
        21096,
        21094,
        21092,
        21087,
        21093,
        21093,
        21102,
        21089,
        21097,
        21095,
        21097,
        21096,
        21094,
        21100,
        21096,
        21093,
        21095,
        21093,
        21087,
        21094,
        21086,
        21093,
        21095,
        21089,
        21094,
        21085,
        21093,
        21099,
        21088,
        21097,
        21093,
        21101,
        21101,
        21090,
        21099,
        21095,
        21098,
        21095,
        21101,
        21093,
        21101,
        21085,
        21096,
        21091,
        21095,
        21095,
        21094,
        21097,
        21095,
        21090,
        21092,
        21095,
        21091,
        21095,
        21088,
        21092,
        21087,
        21093,
        21094,
        21089,
        21100,
        21091,
        21094,
        21087,
        21093,
        21091,
        21098,
        21086,
        21097,
        21094,
        21093,
        21094,
        21089,
        21094,
        21095,
        21092,
        21092,
        21092,
        21089,
        21095,
        21087,
        21093,
        21087,
        21093,
        21086,
        21089,
        21087,
        21100,
        21085,
        21093,
        21087,
        21095,
        21090,
        21092,
        21093,
        21098,
        21089,
        21097,
        21089,
        21094,
        21096,
        21093,
        21094,
        21093,
        21097,
        21097,
        21093,
        21097,
        21095,
        21090,
        21095,
        21095,
        21103,
        21095,
        21093,
        21097,
        21103,
        21093,
        21101,
        21091,
        21101,
        21094,
        21092,
        21095,
        21096,
        21098,
        21098,
        21095,
        21097,
        21097,
        21089,
        21102,
        21091,
        21099,
        21095,
        21087,
        21094
      ]
    }
  ],
  "app_os": "win",
  "app_name": "PhotosynQ",
  "app_version": "0.3.8",
  "app_device": "x86-32",
  "location": [
    "-32.9695615",
    "-60.6257404"
  ],
  "ConsoleMacro": "97"
}
Default avatar
Created by

Rodrigo Gomez


Protocol connections:
20
Latest Update:
Jul 2017