measure_store_offsets_DMK2


calculates offsets even when negative.
/**
 * Macro for data evaluation on PhotosynQ.org
 * by: David M. Kramer
 * created: December 18, 2018 1:05 PM
 */   
   
 // Define the output object here

var offset_min = -100;
var offset_max = 500;
var output = {};

var number_pulses=json.v_arrays[0][0];
output.number_pulses=number_pulses;
  
var xvals=json.v_arrays[1];
output.pulse_durations=xvals;

// Check if the key time exists in json
if (json.time !== undefined){
    // Add key time and value to output
    output.time = json.time;
}   
 
var d1_off = GetProtocolByLabel( "offset_detector1", json );
var d3_off = GetProtocolByLabel( "offset_detector3", json );
output["detector 1 offset test "]=d1_off.data_raw;
output["detector 3 offset test "]=d3_off.data_raw;
   
offset_raw_avs=[];
inv_offset=[];
for (var i=0; i<9; i++){
	offset_raw_avs.push(MathMEAN(d1_off.data_raw.slice(i*number_pulses,(i+1)*number_pulses)));
	var io = MathMEAN(d1_off.data_raw.slice(i*number_pulses,(i+1)*number_pulses));
  	inv_offset.push(1/io);
} 
  // offset_raw_avs.push(MathMEAN(d1_off.data_raw.slice(10,19)));
// offset_raw_avs.push(MathMEAN(d1_off.data_raw.slice(20,29)));
 
output.offset_raw_avs=offset_raw_avs;

//var values = ArrayZip( xvals, inv_offset );
//mnl = NonLinearRegression(values, {equation: "b + a * e(- x / c)", initial: [30,4000,1000]});
//output.mnla=mnl.parameters[2].value;


fit_inv1=MathLINREG(xvals, inv_offset);
output.fit_inv1=1/fit_inv1.b;

//xvals=TransformTrace( "subtract", xvals, 15);
fit_1=MathLINREG(xvals, offset_raw_avs);

output.offset_1=MathROUND(fit_1.b,2);
output.slope_1=MathROUND(fit_1.m,2); 
output.r2_1=MathROUND(fit_1.r2,3); 
 
output.toDevice="set_detector_offset+1+";
output.toDevice+=MathROUND(fit_1.b,3);
output.toDevice+="+";

var d3_off = GetProtocolByLabel( "offset_detector3", json );
 
output.d3_off=MathROUND(d3_off.data_raw);
 
offset_raw_avs3=[];
var inv_offset3=[];
for (var i=0; i<9; i++){
	offset_raw_avs3.push(MathMEAN(d3_off.data_raw.slice(i*number_pulses,(i+1)*number_pulses)));
	var io = MathMEAN(d3_off.data_raw.slice(i*number_pulses,(i+1)*number_pulses));
  	inv_offset3.push(1/io);
}  
  

// offset_raw_avs3.push(MathMEAN(d3_off.data_raw.slice(0,9)));
// offset_raw_avs3.push(MathMEAN(d3_off.data_raw.slice(10,19)));
// offset_raw_avs3.push(MathMEAN(d3_off.data_raw.slice(20,29)));


output.offset_raw_avs3=offset_raw_avs3;

output.xvals=xvals;

//fit_inv1=MathLINREG(xvals, inv_offset);
//output.fit_inv1=1/fit_inv1.b;


fit_inv3=MathLINREG(xvals, inv_offset3);
output.fit_inv3=1/fit_inv3.b;

fit_3=MathLINREG(xvals, offset_raw_avs3);

if ((fit_3.b>offset_max) || (fit_3.b<offset_min)){ 
  danger("offset for detector 3 is too large. May cause poor resutls",output);
}

if ((fit_1.b>offset_max) || (fit_1.b<offset_min)){ 
  danger("offset for detector 1 is too large. May cause poor resutls",output);
}

output.slope_3=MathROUND(fit_3.m); 
output.r2_3=MathROUND(fit_3.r2,3); 

output.offset_3=MathROUND(fit_3.b);
output.toDevice+="set_detector_offset+3+";
output.toDevice+=MathROUND(fit_3.b,2); 
output.toDevice+="+";

output.toDevice+="set_detector_offset+2+0+";
output.toDevice+="set_detector_offset+4+0+";

// Return data
return output;
{
  "time": 1546452884695,
  "device_name": "MultispeQ",
  "device_version": "2",
  "device_id": "63:00:08:08",
  "device_battery": 14,
  "device_firmware": 2.0056,
  "sample": [
    [
      {
        "time": 1546452884695,
        "v_arrays": [
          [
            "30",
            "7",
            "300",
            "1",
            "200"
          ],
          [
            "10",
            "11",
            "12",
            "13",
            "14",
            "15",
            "20",
            "25",
            "30"
          ]
        ],
        "protocol_id": 1,
        "set": [
          {
            "time": 1546452884718,
            "set_detector_offsets": [
              [
                1,
                0
              ],
              [
                3,
                0
              ]
            ],
            "message": [
              "alert",
              "clamp calibration panel 1",
              "ok"
            ],
            "label": "offset_detector1",
            "autogain": [
              [
                9,
                1,
                30,
                421,
                2011
              ]
            ],
            "data_raw": [
              163,
              163,
              161,
              165,
              159,
              161,
              167,
              164,
              160,
              165,
              167,
              162,
              164,
              167,
              164,
              163,
              163,
              160,
              165,
              164,
              163,
              160,
              162,
              162,
              166,
              160,
              165,
              167,
              167,
              165,
              226,
              230,
              229,
              225,
              223,
              226,
              228,
              226,
              220,
              224,
              219,
              228,
              223,
              222,
              225,
              228,
              221,
              218,
              227,
              224,
              226,
              227,
              221,
              219,
              221,
              220,
              226,
              225,
              220,
              219,
              283,
              285,
              286,
              288,
              295,
              282,
              285,
              285,
              285,
              282,
              287,
              288,
              287,
              283,
              287,
              287,
              288,
              291,
              286,
              287,
              293,
              283,
              283,
              285,
              291,
              284,
              285,
              281,
              281,
              290,
              347,
              345,
              350,
              360,
              350,
              364,
              355,
              357,
              351,
              352,
              359,
              351,
              359,
              350,
              354,
              357,
              353,
              352,
              353,
              353,
              350,
              355,
              356,
              355,
              348,
              351,
              350,
              351,
              348,
              351,
              418,
              414,
              429,
              412,
              423,
              421,
              421,
              421,
              422,
              425,
              427,
              424,
              417,
              423,
              420,
              428,
              413,
              425,
              419,
              418,
              425,
              417,
              423,
              418,
              421,
              419,
              418,
              425,
              422,
              419,
              490,
              481,
              484,
              483,
              496,
              491,
              486,
              487,
              488,
              485,
              489,
              491,
              487,
              487,
              489,
              491,
              487,
              487,
              486,
              491,
              487,
              481,
              487,
              497,
              483,
              486,
              485,
              493,
              484,
              490,
              835,
              844,
              842,
              835,
              835,
              837,
              841,
              833,
              837,
              834,
              829,
              832,
              835,
              840,
              832,
              838,
              830,
              842,
              829,
              835,
              836,
              833,
              835,
              833,
              840,
              839,
              839,
              831,
              829,
              831,
              1169,
              1174,
              1169,
              1172,
              1171,
              1173,
              1170,
              1162,
              1168,
              1179,
              1177,
              1183,
              1177,
              1172,
              1161,
              1174,
              1174,
              1168,
              1172,
              1172,
              1179,
              1177,
              1170,
              1175,
              1166,
              1171,
              1167,
              1181,
              1175,
              1174,
              1494,
              1495,
              1489,
              1494,
              1495,
              1499,
              1489,
              1491,
              1497,
              1491,
              1485,
              1496,
              1498,
              1493,
              1492,
              1490,
              1490,
              1496,
              1490,
              1493,
              1494,
              1496,
              1501,
              1491,
              1487,
              1488,
              1483,
              1497,
              1495,
              1493
            ]
          },
          {
            "time": 1546452888939,
            "label": "offset_detector3",
            "autogain": [
              [
                3,
                3,
                30,
                110,
                782
              ]
            ],
            "data_raw": [
              293,
              295,
              293,
              295,
              293,
              293,
              291,
              292,
              293,
              294,
              294,
              292,
              294,
              291,
              292,
              293,
              294,
              291,
              295,
              295,
              292,
              295,
              295,
              291,
              295,
              295,
              296,
              295,
              291,
              295,
              320,
              324,
              325,
              323,
              325,
              324,
              320,
              322,
              322,
              320,
              321,
              322,
              320,
              321,
              323,
              322,
              323,
              322,
              321,
              321,
              323,
              323,
              321,
              323,
              323,
              322,
              323,
              322,
              322,
              323,
              351,
              350,
              353,
              350,
              351,
              352,
              352,
              350,
              352,
              350,
              349,
              349,
              352,
              352,
              351,
              352,
              353,
              349,
              351,
              349,
              351,
              351,
              351,
              349,
              354,
              351,
              351,
              349,
              350,
              351,
              377,
              381,
              381,
              380,
              380,
              382,
              379,
              380,
              379,
              381,
              378,
              380,
              380,
              381,
              379,
              381,
              380,
              379,
              379,
              379,
              379,
              380,
              383,
              381,
              379,
              380,
              381,
              378,
              377,
              378,
              410,
              408,
              407,
              411,
              408,
              411,
              410,
              411,
              407,
              407,
              410,
              407,
              410,
              407,
              407,
              406,
              410,
              410,
              407,
              409,
              408,
              409,
              407,
              409,
              409,
              407,
              407,
              410,
              407,
              409,
              436,
              436,
              436,
              437,
              439,
              439,
              439,
              438,
              436,
              437,
              438,
              437,
              434,
              437,
              439,
              434,
              435,
              435,
              436,
              435,
              436,
              433,
              433,
              437,
              433,
              437,
              438,
              437,
              437,
              437,
              575,
              573,
              574,
              571,
              573,
              573,
              573,
              573,
              572,
              576,
              575,
              571,
              573,
              573,
              575,
              575,
              573,
              571,
              571,
              569,
              575,
              573,
              571,
              574,
              573,
              573,
              571,
              576,
              572,
              574,
              704,
              705,
              704,
              703,
              705,
              704,
              705,
              703,
              703,
              703,
              704,
              707,
              704,
              701,
              701,
              706,
              705,
              705,
              705,
              706,
              705,
              702,
              705,
              703,
              701,
              703,
              706,
              705,
              705,
              706,
              827,
              827,
              826,
              827,
              826,
              827,
              827,
              828,
              824,
              823,
              827,
              827,
              827,
              824,
              825,
              823,
              826,
              830,
              826,
              828,
              830,
              829,
              822,
              825,
              825,
              827,
              826,
              829,
              826,
              828
            ]
          }
        ],
        "data_raw": [

        ]
      }
    ]
  ],
  "app_os": "macOS 17.7.0",
  "app_name": "PhotosynQ",
  "app_version": "1.0.1",
  "app_device": "x64",
  "location": false,
  "time_offset": "America/New_York"
}
Default avatar
Created by

Luka Kramer


Protocol connections:
1
Latest Update:
Jan 2019