toff


This performes a standard blank at 3 different simulated leaf thicknesses, and also calibrates each thickness to a known SPAD value from a Minolta SPAD meter. When you have multiple SPAD devices involved in a single project, you can use this protocol to ensure that all devices are calibrated together. MultispeQs have some natural variation in the SPAD value between devices, and this reduces that variation by calibrating them all against a common standard.
//============================================
// 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];
 
var output = {};
var sample_940 = [];
var sample_650 = [];

var message = json.message;
var nine40_temp = [];
var six50_temp = [];

var datay = json.set[1].data_raw;
output.datay = 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);
    sample_940.push(temp_940); 
  	if (sample_940<=0) {
      sample_940 = 0.1;
    }  
	var temp_650 = MathROUND(MathMEAN(datay.slice(12+20*x,18+20*x)),0);
    if (temp_650<=0) {
      temp_650 = 0.1;
    }
    sample_650.push(temp_650);  
  	}
output.s650="[" + sample_650.join() + "]";
output.s940="[" +sample_940.join() + "]";

var fit_detector_3=MathLINREG(standards, sample_650);

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) {
	warning("Detector 1 fit bad. Check for offsets!", output);
}

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

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


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

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


return output;

{
  "time": 1547046453708,
  "device_name": "MultispeQ",
  "device_version": "2",
  "device_id": "52:00:07:fd",
  "device_battery": -1,
  "device_firmware": 2.007,
  "sample": [
    [
      {
        "time": 1547046453708,
        "protocol_id": 1,
        "set": [
          {
            "time": 1547046453732,
            "message": [
              "prompt",
              "Clamp tile 1 and Enter",
              ""
            ],
            "autogain": [
              [
                2,
                3,
                20,
                251,
                33338
              ],
              [
                6,
                1,
                20,
                1083,
                25674
              ]
            ],
            "data_raw": [

            ]
          },
          {
            "time": 1547046461603,
            "set_detector_offsets": [
              [
                1,
                0
              ],
              [
                3,
                0
              ]
            ],
            "message": [
              [
                "prompt",
                "Clamp tile 1 and Enter",
                ""
              ],
              [
                "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",
                ""
              ],
              [
                "prompt",
                "Clamp tile 7 and Enter",
                ""
              ],
              [
                "0",
                "0",
                ""
              ],
              [
                "prompt",
                "Clamp tile 8 and Enter",
                ""
              ],
              [
                "0",
                "0",
                ""
              ],
              [
                "prompt",
                "Clamp tile 9 and Enter",
                ""
              ],
              [
                "0",
                "0",
                ""
              ]
            ],
            "recall": {
              "time": 1547046487658,
              "colorcal_blank1[2]": 62027,
              "colorcal_blank2[2]": 23655,
              "colorcal_blank3[2]": 19811,
              "colorcal_blank1[6]": "NaN",
              "colorcal_blank2[6]": 20075,
              "colorcal_blank3[6]": 6930.5
            },
            "data_raw": [
              12703,
              12706,
              12705,
              12709,
              12711,
              12707,
              12708,
              12705,
              12705,
              12709,
              42483,
              42484,
              42475,
              42481,
              42467,
              42481,
              42475,
              42483,
              42481,
              42475,
              11481,
              11479,
              11477,
              11478,
              11481,
              11478,
              11474,
              11472,
              11480,
              11475,
              38397,
              38387,
              38399,
              38402,
              38398,
              38404,
              38393,
              38402,
              38391,
              38395,
              7824,
              7826,
              7829,
              7825,
              7822,
              7818,
              7823,
              7829,
              7830,
              7822,
              27413,
              27412,
              27417,
              27415,
              27414,
              27415,
              27411,
              27403,
              27406,
              27405,
              3810,
              3809,
              3808,
              3804,
              3806,
              3809,
              3806,
              3810,
              3812,
              3808,
              16041,
              16039,
              16036,
              16045,
              16044,
              16039,
              16039,
              16039,
              16043,
              16044,
              174,
              173,
              174,
              174,
              178,
              175,
              173,
              174,
              173,
              175,
              4332,
              4333,
              4333,
              4332,
              4331,
              4331,
              4333,
              4333,
              4332,
              4330,
              50,
              50,
              51,
              52,
              49,
              50,
              50,
              50,
              51,
              51,
              1539,
              1540,
              1537,
              1535,
              1539,
              1538,
              1538,
              1538,
              1535,
              1535,
              5045,
              5045,
              5040,
              5045,
              5043,
              5042,
              5039,
              5044,
              5038,
              5039,
              19193,
              19193,
              19195,
              19196,
              19201,
              19204,
              19204,
              19201,
              19202,
              19207,
              48,
              49,
              47,
              46,
              47,
              48,
              50,
              48,
              47,
              48,
              571,
              572,
              571,
              571,
              573,
              573,
              572,
              574,
              574,
              574,
              55,
              56,
              55,
              57,
              56,
              55,
              57,
              55,
              54,
              56,
              2414,
              2414,
              2415,
              2415,
              2418,
              2415,
              2415,
              2416,
              2415,
              2415
            ]
          }
        ],
        "data_raw": [

        ]
      }
    ]
  ],
  "app_os": "macOS 17.7.0",
  "app_name": "PhotosynQ",
  "app_version": "1.1.0",
  "app_device": "x64",
  "location": [
    "42.6911897",
    "-84.4464103"
  ],
  "time_offset": "America/New_York"
}
Dave in cap img 4615
Created by

David M. Kramer


Protocol connections:
2
Latest Update:
Jan 2019