test_new_spad_4


test of new spad process
/**
 * Macro for data evaluation on PhotosynQ.org
 * by: David M. Kramer
 * created: 2017-06-21 @ 10:36:29
 */


/*
light_1 = 530 nm top
light_2 = 650 nm top
light_3 = 605 nm top
light 4 = blue top
light_5 = 940 nm top

light_9 = 940 nm bottom
light_7 =  650 bottom
light_8 = 850 nm bottom
light 9 = 730 nm bottom
light 10 = 880 nm bottom
*/

// Define the output object here
var output = {};

// Check if the key time exists in json
if (json.time !== undefined){

	// Add key time and value to output
	output.time = json.time;
}

output.t1=json.set[1].absorbance;
output.t2=json.set[2].absorbance;
output.t3=json.set[3].absorbance;
output.t4=json.set[4].absorbance;
output.t5=json.set[5].absorbance;

output.t9=json.set[9].absorbance;

//var baseline = json.set[0].absorbance;
//var dif_traces = new Array();
//for (var m =1; m< json.set.length; m++){
//  var test = json.set[m].absorbance;
//  for (var index in baseline){
//      test[index]=MathROUND(test[index]-baseline[index],3);
//  }
//	dif_traces.push(test);
 // output["diff_trace#"+m]=test;
//  output["diff_trace_t#"+m]=test.join(",");;

//}

var dif_1=3;
var dif_2=4;
var dif_array = new Array();
for (var m =1; m< json.set.length; m++){
	dif_array.push(MathROUND(json.set[m].absorbance[dif_1] - json.set[m].absorbance[dif_2]));
    
}
output.dif_array_445_940=dif_array.join(", ");


var dif_1=0;
var dif_2=4;
var dif_array = new Array();
for (var m =1; m< json.set.length; m++){
	dif_array.push(MathROUND(json.set[m].absorbance[dif_1] - json.set[m].absorbance[dif_2]));
}
output.dif_array_530_940=dif_array.join(", ");


var dif_1=6;
var dif_2=4;
var dif_array = new Array();
for (var m =1; m< json.set.length; m++){
	dif_array.push(MathROUND(json.set[m].absorbance[dif_1] - json.set[m].absorbance[dif_2]));
}
output.dif_array_730_940=dif_array.join(", ");

var dif_1=2;
var dif_2=4;
var dif_array = new Array();
var dif_array_600_940 = new Array();

for (var m =1; m< json.set[1].length; m++){
	dif_array.push(MathROUND(json.set[m].absorbance[dif_1] - json.set[m].absorbance[dif_2]));
}
output.dif_array_600_940=dif_array.join(", ");


var dif_1=2;
var dif_2=4;
var dif_array = new Array();
var dif_array_600_940 = new Array();

for (var m =1; m< json.set.length; m++){
	dif_array.push(MathROUND(json.set[m].absorbance[dif_1] - json.set[m].absorbance[dif_2]));
}
output.dif_array_600_940=dif_array.join(", ");



/*
var number_spads=2;
var number_lights=5;
var s = new Array(number_lights);

for (var i=1; i< number_spads; i++){
output["t_"]=json.set[i].data_raw;
}

for (var i=1; i< number_lights; i++){
	s[j]=0;
}

for (var j=1; j<number_lights; j+1){
	for (var i=1; i< number_spads; i++){
  		s[j]+=json.set[i].data_raw[i][j];
    }
}

/*
for (var j; j<number_lights; j+1){
	output["sum s " + j]=s[i];
}

/*
var i_sample = new Array(number_spads-1);
var i_ref = new Array(number_spads-1);
var spad_out = new Array(number_spads-1);

var sample_led=2;
var ref_led=3;
var num_pulses = 10;
var offset=100;

//var i_1_3_0=MathMEAN(json.set[1].data_raw.slice(1,9));

for (var i=1; i< number_spads; i++){
	i_ref[i-1]=MathMEAN(json.set[i].data_raw.slice((ref_led)*num_pulses,(ref_led)*num_pulses+1));
	i_sample[i-1]=MathMEAN(json.set[i].data_raw.slice((sample_led)*num_pulses,(sample_led+1)*num_pulses));
	spad_out[i-1]=MathROUND(MathLOG(i_ref[i-1]-offset)-MathLOG(i_sample[i-1]-offset), 2);
}
output.i_ref=i_ref;
output.i_sample=i_sample;
output.spad_out=spad_out;

output.spad_out=spad_out.join(",");


/*
var i_1_3_0=MathMEAN(json.set[1].data_raw.slice(1,9));
var i_2_3_0=MathMEAN(json.set[1].data_raw.slice(11,19));
var i_3_3_0=MathMEAN(json.set[1].data_raw.slice(21,29));
var i_6_1_0=MathMEAN(json.set[1].data_raw.slice(31,39));
var i_7_1_0=MathMEAN(json.set[1].data_raw.slice(41,49));

var i_1_3=MathMEAN(json.set[2].data_raw.slice(0,9));
var i_2_3=MathMEAN(json.set[2].data_raw.slice(11,19));
var i_3_3=MathMEAN(json.set[2].data_raw.slice(21,29));
var i_6_1=MathMEAN(json.set[2].data_raw.slice(31,39));
var i_7_1=MathMEAN(json.set[2].data_raw.slice(41,49));

var DA_1_3=MathLOG(i_1_3_0/i_1_3);
var DA_2_3=MathLOG(i_2_3_0/i_2_3);
var DA_3_3=MathLOG(i_3_3_0/i_3_3);
var DA_6_1=MathLOG(i_6_1_0/i_6_1);
var DA_7_1=MathLOG(i_7_1_0/i_7_1);

output.DA_1_3=DA_1_3;
output.DA_2_3=DA_2_3;
output.DA_3_3=DA_3_3;
output.DA_6_1=DA_6_1;
output.DA_7_1=DA_7_1;

var DA_2_3=MathLOG(i_2_3_0/i_2_3);
var DA_3_3=MathLOG(i_3_3_0/i_3_3);
var DA_6_1=MathLOG(i_6_1_0/i_6_1);
var DA_7_1=MathLOG(i_7_1_0/i_7_1);


var DA_array=[DA_1_3,DA_2_3,DA_3_3,DA_6_1,DA_7_1];
output.DA_array=DA_array;



var i_1_3=MathMEAN(json.set[3].data_raw.slice(0,9));
var i_2_3=MathMEAN(json.set[3].data_raw.slice(11,19));
var i_3_3=MathMEAN(json.set[3].data_raw.slice(21,29));
var i_6_1=MathMEAN(json.set[3].data_raw.slice(31,39));
var i_7_1=MathMEAN(json.set[3].data_raw.slice(41,49));

var DA_1_3=MathLOG(i_1_3_0/i_1_3);
var DA_2_3=MathLOG(i_2_3_0/i_2_3);
var DA_3_3=MathLOG(i_3_3_0/i_3_3);
var DA_6_1=MathLOG(i_6_1_0/i_6_1);
var DA_7_1=MathLOG(i_7_1_0/i_7_1);

output.DA_1_3_2=DA_1_3;
output.DA_2_3_2=DA_2_3;
output.DA_3_3_2=DA_3_3;
output.DA_3_3_2=DA_3_3;
output.DA_6_1_2=DA_6_1;
output.DA_7_1_2=DA_7_1;

var DA_1_3_2=MathLOG(i_2_3_0/i_2_3);
var DA_2_3_2=MathLOG(i_2_3_0/i_2_3);
var DA_3_3_2=MathLOG(i_3_3_0/i_3_3);
var DA_6_1_2=MathLOG(i_6_1_0/i_6_1);
var DA_7_1_2=MathLOG(i_7_1_0/i_7_1);

var DA_array_2=[DA_1_3_2,DA_2_3_2,DA_3_3_2,DA_6_1_2,DA_7_1_2];
//output.DA_array_2=DA_array_2;

var number_leds=5;
var number_spads=5;
var leds=[1,2,3,6,7];
var lambda=[535,650,590,940,655];            
var start_pt=[1,101,201,301,401];
var end_pt=[91,191,291,391,491];
var spad_val=[7.9,15,30.3,24.9];

var ttp = new Array(number_spads);
for (var i = 0; i < number_leds; i++) {
  ttp[i] = new Array(number_spads);
  	for (var j = 0; j < number_leds; j++) {
     ttp[i][j]=i*j; 
    }
}
for (i = 0; i < number_leds; i++) {
	for (j = 0; j < number_spads; j++) {      	
  	  i_zero=MathMEAN(json.set[1].data_raw.slice(start_pt[j],end_pt[j]));
  	  i_l=MathMEAN(json.set[i+1].data_raw.slice(start_pt[j],end_pt[j]));
	  a=MathLOG(i_zero/i_l);
      ttp[j][i]=a;  
    }
}

var spad_outputs_1 = new Array(number_spads);
for (j = 0; j < number_spads; j++) { 
  spad_outputs_1[j]=ttp[2][j] - ttp[3][j];
}

output.so=spad_outputs_1;

var spad_outputs_2 = new Array(number_spads);
for (j = 0; j < number_spads; j++) { 
  spad_outputs_2[j]=ttp[0][j] - ttp[3][j];
}

output.so_2=spad_outputs_2;


var spad_outputs_3 = new Array(number_spads);
for (j = 0; j < number_spads; j++) { 
  spad_outputs_3[j]=ttp[4][j] - ttp[3][j];
}

output.so_3=spad_outputs_3;



//output.trial=ttp[3];
//for (i = 0; i < number_spads; i++) {
//	output["res"+i]=ttp[i];
//}

for (i = 0; i < number_leds; i++) {
	output["delta_A_"+lambda[i]]=ttp[i]; //.slice(1,5);
	//output["delta_A_"+i]=ttp[i];
}


output.spads=spad_val;

//output.DA1=ttp[2];

//output.d530=ttp[1];

/*
var d=0.0;
var c=(66.5); //(2*45.6);
var i_650_0=MathMEAN(json.set[1].data_raw.slice(0,90));
var i_940_0=MathMEAN(json.set[1].data_raw.slice(100,190));
output.i_650_0=i_650_0;
output.i_940_0=i_940_0;


i_650=MathMEAN(json.set[5].data_raw.slice(0,99));
i_940=MathMEAN(json.set[5].data_raw.slice(100,199));
var i_650_black=0; //i_650;
var i_940_black=0; //i_940;
output.i_650_black=i_650;
output.i_940_black0=i_940;

var s=1;
var i_650=MathMEAN(json.set[s].data_raw.slice(0,99));
var i_940=MathMEAN(json.set[s].data_raw.slice(100,199));
T_650=(i_650-i_650_black)/(i_650_0-i_650_black);
T_940=(i_940-i_940_black)/(i_940_0-i_940_black);

spad=c*(d*MathLOG(T_940)-MathLOG(T_650));
output.trace_1=json.set[1].data_raw;

//spad=-1*MathLOG(T_650);

output.T_650_1=T_650;
output.T_940_1=T_940;
output.spad1=spad;
output.trace_1=json.set[s].data_raw;

var s=2;
var i_650=MathMEAN(json.set[s].data_raw.slice(0,99));
var i_940=MathMEAN(json.set[s].data_raw.slice(100,199));
T_650=(i_650-i_650_black)/(i_650_0-i_650_black);
T_940=(i_940-i_940_black)/(i_940_0-i_940_black);
spad=c*(d*MathLOG(T_940)-MathLOG(T_650));

output.T_650_2=T_650;
output.T_940_3=T_940;
//spad=-1*MathLOG(T_650);

output.spad2=spad;
output.trace_2=json.set[2].data_raw;

var s=3;
var i_650=MathMEAN(json.set[s].data_raw.slice(0,99));
var i_940=MathMEAN(json.set[s].data_raw.slice(100,199));
var spad=(41/62.0)*100*MathLOG(((i_650_0)/(i_650))/((i_940_0-i_94_black0)/(i_940-i_94_black0)));
T_650=(i_650-i_650_black)/(i_650_0-i_650_black);

//T_940=(i_940-i_940_black)/(i_940_0-i_940_black);
spad=c*(d*MathLOG(T_940)-MathLOG(T_650));
output.T_650_3=T_650;
output.T_940_3=T_940;
//spad=-1*MathLOG(T_650);

output.spad3=spad;
output.trace_3=json.set[s].data_raw;


var s=4;
var i_650=MathMEAN(json.set[s].data_raw.slice(0,99));
var i_940=MathMEAN(json.set[s].data_raw.slice(100,199));
T_650=(i_650-i_650_black)/(i_650_0-i_650_black);
T_940=(i_940-i_940_black)/(i_940_0-i_940_black);

spad=c*(d*MathLOG(T_940)-MathLOG(T_650));
output.T_650_4=T_650;
output.T_940_4=T_940;
//spad=-1*MathLOG(T_650);

output.spad4=spad;
output.trace_4=json.set[s].data_raw;

var s=5;

var i_650=MathMEAN(json.set[s].data_raw.slice(0,99));
var i_940=MathMEAN(json.set[s].data_raw.slice(100,199));
T_650=(i_650-i_650_black)/(i_650_0-i_650_black);
T_940=(i_940-i_940_black)/(i_940_0-i_940_black);

spad=c*(d*MathLOG(T_940)-MathLOG(T_650));
output.T_650_5=T_650;
output.T_940_5=T_940;
//spad=-1*MathLOG(T_650);

output.spad5=spad;
output.trace_5=json.set[s].data_raw;


var s=6;
var i_650=MathMEAN(json.set[s].data_raw.slice(0,99));
var i_940=MathMEAN(json.set[s].data_raw.slice(100,199));
T_650=(i_650-i_650_black)/(i_650_0-i_650_black);
T_940=(i_940-i_940_black)/(i_940_0-i_940_black);
spad=c*(d*MathLOG(T_940)-MathLOG(T_650));

output.T_650_6=T_650;
output.T_940_6=T_940;
//spad=-1*MathLOG(T_650);

output.spad6=spad;
output.trace_6=json.set[s].data_raw;


var s=7;
var i_650=MathMEAN(json.set[s].data_raw.slice(0,99));
var i_940=MathMEAN(json.set[s].data_raw.slice(100,199));
T_650=(i_650-i_650_black)/(i_650_0-i_650_black);
T_940=(i_940-i_940_black)/(i_940_0-i_940_black);

spad=c*(d*MathLOG(T_940)-MathLOG(T_650));
output.T_650_7=T_650;
output.T_940_7=T_940;
//spad=-1*MathLOG(T_650);
output.spad7=spad;
output.trace_7=json.set[s].data_raw;


var s=8;
var i_650=MathMEAN(json.set[s].data_raw.slice(0,99));
var i_940=MathMEAN(json.set[s].data_raw.slice(100,199));
T_650=(i_650-i_650_black)/(i_650_0-i_650_black);
T_940=(i_940-i_940_black)/(i_940_0-i_940_black);

output.T_650_8=T_650;
output.T_940_8=T_940;
//spad=-1*MathLOG(T_650);
spad=c*(d*MathLOG(T_940)-MathLOG(T_650));
output.spad8=spad;
output.trace_8=json.set[s].data_raw;

var s=9;
var i_650=MathMEAN(json.set[s].data_raw.slice(0,99));
var i_940=MathMEAN(json.set[s].data_raw.slice(100,199));

T_650=(i_650-i_650_black)/(i_650_0-i_650_black);
T_940=(i_940-i_940_black)/(i_940_0-i_940_black);
spad=c*(d*MathLOG(T_940)-MathLOG(T_650));
output.T_650_9=T_650;
output.T_940_9=T_940;
//spad=-1*MathLOG(T_650);

output.spad9=spad;
// Return data
output.trace_9=json.set[s].data_raw;
*/

return output;
{
  "time": "1498322750738",
  "device_name": "MultispeQ",
  "device_version": "1",
  "device_id": "01:12:53:21",
  "device_battery": 86,
  "device_firmware": 1.18,
  "sample": [
    [
      {
        "time": "1498322750738",
        "light_intensity_raw": 0,
        "data_raw": [

        ],
        "protocol_id": 1,
        "set": [
          {
            "time": "1498322750739",
            "blank:": "blank"
          },
          {
            "time": "1498322750748",
            "absorbance": [
              [
                -0.116572
              ],
              [
                0.139807
              ],
              [
                -0.063728
              ],
              [
                0.917659
              ],
              [
                -0.109583
              ],
              [
                -0.118585
              ],
              [
                -0.123155
              ],
              [
                -0.12495
              ]
            ],
            "data_raw": [

            ]
          },
          {
            "time": "1498322753130",
            "absorbance": [
              [
                0.327508
              ],
              [
                0.879178
              ],
              [
                0.468268
              ],
              [
                1.254408
              ],
              [
                -0.109583
              ],
              [
                -0.118585
              ],
              [
                -0.123155
              ],
              [
                -0.12495
              ]
            ],
            "data_raw": [

            ]
          },
          {
            "time": "1498322759167",
            "absorbance": [
              [
                -0.068477
              ],
              [
                0.364644
              ],
              [
                -0.012779
              ],
              [
                0.921645
              ],
              [
                -0.109583
              ],
              [
                -0.118585
              ],
              [
                -0.123155
              ],
              [
                -0.12495
              ]
            ],
            "data_raw": [

            ]
          },
          {
            "time": "1498322764285",
            "absorbance": [
              [
                0.230564
              ],
              [
                0.824727
              ],
              [
                0.315349
              ],
              [
                1.729228
              ],
              [
                -0.109583
              ],
              [
                -0.118585
              ],
              [
                -0.123155
              ],
              [
                -0.12495
              ]
            ],
            "data_raw": [

            ]
          },
          {
            "time": "1498322768855",
            "absorbance": [
              [
                0.110103
              ],
              [
                -0.047038
              ],
              [
                -0.095592
              ],
              [
                0.520031
              ],
              [
                -0.109583
              ],
              [
                -0.118585
              ],
              [
                -0.123155
              ],
              [
                -0.12495
              ]
            ],
            "data_raw": [

            ]
          },
          {
            "time": "1498322773645",
            "absorbance": [
              [
                -0.063417
              ],
              [
                0.376816
              ],
              [
                0.00115
              ],
              [
                1.148937
              ],
              [
                -0.109583
              ],
              [
                -0.118585
              ],
              [
                -0.123155
              ],
              [
                -0.12495
              ]
            ],
            "data_raw": [

            ]
          },
          {
            "time": "1498322778960",
            "absorbance": [
              [
                0.345274
              ],
              [
                0.82724
              ],
              [
                0.471536
              ],
              [
                1.132248
              ],
              [
                -0.109583
              ],
              [
                -0.118585
              ],
              [
                -0.123155
              ],
              [
                -0.12495
              ]
            ],
            "data_raw": [

            ]
          },
          {
            "time": "1498322783290",
            "absorbance": [
              [
                0.043831
              ],
              [
                0.480327
              ],
              [
                0.116221
              ],
              [
                1.065135
              ],
              [
                -0.109583
              ],
              [
                -0.118585
              ],
              [
                -0.123155
              ],
              [
                -0.12495
              ]
            ],
            "data_raw": [

            ]
          },
          {
            "time": "1498322787399",
            "absorbance": [
              [
                1.643375
              ],
              [
                1.868282
              ],
              [
                2.081004
              ],
              [
                2.835888
              ],
              [
                0.895094
              ],
              [
                0.900665
              ],
              [
                1.757613
              ],
              [
                0.898261
              ]
            ],
            "data_raw": [

            ]
          }
        ]
      }
    ]
  ],
  "app_os": "darwin-x64",
  "app_name": "PhotosynQ",
  "app_version": "0.0.11-DMK",
  "app_device": "x64",
  "location": [
    "42.7223811",
    "-84.4746529"
  ],
  "time_offset": "America/Detroit"
}
Dave in cap img 4615
Created by

David M. Kramer


Protocol connections:
2
Latest Update:
Jun 2017