Measure and Detect Offsets (toff) 2


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.

//var standards = [4095,3695,2640,1427,371,141,1774,77,220];
//var standards = [4195,3795,2740,1527,471,241,1874,177,320];
 
//var standard_green=[124.4, 115.1, 88, 57.5, 30, 23.1]; //,20]; //.8,9.78];
//var standard_red =[47.7, 43.3, 31.1, 17.6, 5.2, 2.2]; //,1.3,0.14];
var standard_green=[613, 379, 11.3, 2.2];
var standard_red =[80.3, 49.5, 1.5, 0.3];
 
standard_green=TransformTrace( "normToMax", standard_green );
standard_red=TransformTrace( "normToMax", standard_red );

var output = {};

output.standard_green=standard_green;
output.standard_red=standard_red;

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<4;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);  
  	}

var max_det3=MathMAX(sample_650);
output.max_det3=max_det3;
sample_650=TransformTrace( "normToMax", sample_650 );
output.LIGHT1="[" + sample_650.join() + "]";

var max_det1=MathMAX(sample_940);
output.max_det1=max_det1;
sample_940=TransformTrace( "normToMax", sample_940 );

output.LED9="[" +sample_940.join() + "]";

var fit_detector_3=MathLINREG(standard_red, sample_650);

output.fit_detector_3m=MathROUND(fit_detector_3.m, 3);
output.detector_3_offset=MathROUND(max_det3*fit_detector_3.b,2);
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(standard_red, sample_940);
 
output.fit_detector_1m=MathROUND(fit_detector_1.m, 3);
output.detector_1_offset=MathROUND(max_det1*fit_detector_1.b,3);
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": 1548180952205,
  "device_name": "MultispeQ",
  "device_version": "2",
  "device_id": "41:00:08:b4",
  "device_battery": 1,
  "device_firmware": 2.0092,
  "sample": [
    [
      {
        "time": 1548180952205,
        "protocol_id": 1,
        "set": [
          {
            "time": 1548180952205,
            "message": [
              "prompt",
              "Clamp tile 1 and Enter",
              ""
            ],
            "autogain": [
              [
                1,
                3,
                20,
                -61,
                36775
              ],
              [
                9,
                1,
                20,
                -730,
                36996
              ]
            ],
            "data_raw": [

            ]
          },
          {
            "time": 1548180955984,
            "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",
                ""
              ]
            ],
            "data_raw": [
              36830,
              36830,
              36831,
              36831,
              36833,
              36829,
              36833,
              36830,
              36833,
              36835,
              36519,
              36462,
              36468,
              36492,
              36530,
              36484,
              36500,
              36541,
              36599,
              36549,
              23276,
              23284,
              23283,
              23283,
              23281,
              23283,
              23281,
              23283,
              23285,
              23284,
              22143,
              22116,
              22129,
              22158,
              22167,
              22131,
              22106,
              22178,
              22110,
              22098,
              695,
              693,
              693,
              693,
              694,
              697,
              694,
              698,
              695,
              694,
              679,
              679,
              678,
              679,
              678,
              681,
              677,
              679,
              681,
              679,
              123,
              123,
              127,
              124,
              124,
              124,
              123,
              123,
              124,
              127,
              159,
              158,
              160,
              159,
              157,
              157,
              158,
              156,
              159,
              157
            ]
          }
        ],
        "data_raw": [

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

David M. Kramer


Protocol connections:
1
Latest Update:
30 days ago