Measure and Detect Offsets (toff)


see Measure and Detect Offsets protocol.
//============================================
// Macro for setting the detector offset values
// using a series of panels with different 
// blank/white patterns
//============================================
      
// blank1/2/3 represent the blanks for 3 leaf thicknesses (lowest to highest).  spad_cal1/2/3 is the calibration to a known Minolta SPAD meter value for each of those thicknesses in the form y = mx+b where the two saved values in the array are x and b.

standards = [4095,3695,2640,1427,371,141,1774,77,220];
standards = [4195,3795,2740,1527,471,241,1874,177,320];
 
var output = {};
var sample_940 = []; 
var sample_650 = [];

var message = json.message;

var datay = json.set[1].data_raw;
output.raw_data = datay;



// pull and average the calibration values for 940 and 650 LEDs from the trace
for (x=0;x<9;x++) {
	var temp_940 = MathROUND(MathMEAN(datay.slice(2+20*x,8+20*x)),0);
  	if (isNaN(temp_940)) {
      temp_940 = 0.0; 
    }  
    sample_940.push(temp_940); 
	var temp_650 = MathROUND(MathMEAN(datay.slice(12+20*x,18+20*x)),0);
    if (isNaN(temp_650)) {
      temp_650 = 0;
    }
    sample_650.push(temp_650);  
  	}
output.s650="[" + sample_650.join() + "]";
output.s940="[" +sample_940.join() + "]";

var fit_detector_3=MathLINREG(standards.slice(0,5), sample_650.slice(0,5));

output.fit_detector_3m=MathROUND(fit_detector_3.m, 3);
output.detector_3_offset=MathROUND(fit_detector_3.b,0);
output.fit_detector_3r2=MathROUND(fit_detector_3.r2,4);

//var fit_detector_1=MathLINREG(standards, sample_940);
 
//output.fit_detector_1m=MathROUND(fit_detector_1.m, 3);
//output.detector_1_offset=MathROUND(fit_detector_1.b,0);
//output.fit_detector_1r2=MathROUND(fit_detector_1.r2,4);

var fit_detector_1=MathLINREG(standards.slice(0,5), sample_940.slice(0,5));
 
output.fit_detector_1m=MathROUND(fit_detector_1.m, 3);
output.detector_1_offset=MathROUND(fit_detector_1.b,0);
output.fit_detector_1r2=MathROUND(fit_detector_1.r2,4);

  

output ["toDevice"] = "set_detector_offset+";
output ["toDevice"] += "1+";
output ["toDevice"] += output.detector_1_offset + "+";

output ["toDevice"] += "set_detector_offset+";
output ["toDevice"] += "3+";
output ["toDevice"] += output.detector_3_offset + "+";
 

if (fit_detector_1.r2 < .99) {
	danger("Detector 1 fit bad. Check for offsets!", output);
}

if (output.detector_1_offset < -200) {
	danger("Detector 1 offset too negative!", output);
}

if (output.detector_1_offset > 2000) {
	danger("Detector 1 offset too positive!", output);
}


if (output.detector_3_offset < -200) {
	danger("Detector 3 offset too negative!", output);
}

if (output.detector_3_offset > 2000) {
	danger("Detector 3 offset too positive!", output);
}

if (isNaN(output.detector_1_offset)) {
	danger("Detector 1 error!", output);
}

if (isNaN(output.detector_3_offset)) {
	danger("Detector 3 error!", output);
}



return output;

{
  "time": 1547489238884,
  "device_name": "MultispeQ",
  "device_version": "2",
  "device_id": "00:00:00:00",
  "device_battery": 102,
  "device_firmware": 2.009,
  "sample": [
    [
      {
        "time": 1547489238884,
        "protocol_id": 1,
        "set": [
          {
            "time": 1547489238900,
            "message": [
              "prompt",
              "Clamp tile 1 and Enter",
              ""
            ],
            "autogain": [
              [
                2,
                3,
                20,
                1083,
                28265
              ],
              [
                6,
                1,
                20,
                942,
                39552
              ]
            ],
            "data_raw": [

            ]
          },
          {
            "time": 1547489251135,
            "set_detector_offsets": [
              [
                1,
                0
              ],
              [
                3,
                0
              ]
            ],
            "message": [
              [
                "0",
                "0",
                ""
              ],
              [
                "0",
                "0",
                ""
              ],
              [
                "prompt",
                "Clamp tile 2 and Enter",
                ""
              ],
              [
                "0",
                "0",
                ""
              ],
              [
                "prompt",
                "Clamp tile 3 and Enter",
                ""
              ],
              [
                "0",
                "0",
                ""
              ],
              [
                "prompt",
                "Clamp tile 4 and Enter",
                ""
              ],
              [
                "0",
                "0",
                ""
              ],
              [
                "prompt",
                "Clamp tile 5 and Enter",
                ""
              ],
              [
                "0",
                "0",
                ""
              ],
              [
                "prompt",
                "Clamp tile 6 and Enter",
                ""
              ],
              [
                "0",
                "0",
                ""
              ]
            ],
            "data_raw": [
              7729,
              7729,
              7726,
              7727,
              7727,
              7725,
              7727,
              7723,
              7725,
              7729,
              9093,
              9093,
              9091,
              9093,
              9093,
              9092,
              9092,
              9093,
              9093,
              9093,
              7067,
              7066,
              7063,
              7069,
              7063,
              7066,
              7068,
              7067,
              7069,
              7063,
              8123,
              8127,
              8127,
              8125,
              8126,
              8123,
              8124,
              8126,
              8122,
              8123,
              5103,
              5101,
              5101,
              5101,
              5103,
              5100,
              5101,
              5099,
              5103,
              5102,
              5896,
              5894,
              5895,
              5891,
              5895,
              5893,
              5895,
              5897,
              5897,
              5895,
              2943,
              2944,
              2943,
              2942,
              2943,
              2942,
              2941,
              2943,
              2943,
              2943,
              3259,
              3257,
              3255,
              3255,
              3259,
              3258,
              3257,
              3256,
              3255,
              3257,
              933,
              936,
              935,
              936,
              931,
              933,
              934,
              934,
              933,
              933,
              855,
              853,
              851,
              853,
              852,
              854,
              855,
              855,
              855,
              854,
              483,
              481,
              480,
              482,
              484,
              479,
              481,
              479,
              483,
              479,
              300,
              296,
              299,
              297,
              298,
              299,
              297,
              296,
              300,
              297
            ]
          }
        ],
        "data_raw": [

        ]
      }
    ]
  ],
  "app_os": "macOS 16.7.0",
  "app_name": "PhotosynQ",
  "app_version": "1.0.2",
  "app_device": "x64",
  "location": false,
  "time_offset": "America/Detroit"
}
Dave in cap img 4615
Created by

David M. Kramer


Protocol connections:
1
Latest Update:
Jan 2019