Commit 08b36456 authored by Andrey Filippov's avatar Andrey Filippov

modified other distance measurements (like for temperature coefficient)

to use lens aberration model
parent 77c3afd4
This diff is collapsed.
......@@ -2977,7 +2977,25 @@ public class CalibrationHardwareInterface {
fullResults
);
}
public FocusingField.FocusingFieldMeasurement getThisFFMeasurement(
FocusingField focusingField,
String sTimestamp,
double temperature,
double[][] psfMetrics,
double [][][][] fullResults){
return focusingField.getFocusingFieldMeasurement(
sTimestamp, //focusingState.getTimestamp(),
temperature, //focusingState.getTemperature(),
this.curpos, //focusingState.motorsPos,
fullResults); //focusingState.getSamples());
}
/*
* FocusingHistory.FocusingState focusingState
public void addToHistory( String sTimestamp,double temperature, double[][] psfMetrics){ // null OK
this.focusingHistory.add(
sTimestamp,
......@@ -3004,6 +3022,7 @@ public class CalibrationHardwareInterface {
}
public void listHistory(
boolean useLMA,
String path,
String lensSerial,
String comment,
......@@ -3015,6 +3034,7 @@ public class CalibrationHardwareInterface {
double weightY // R-frac, Y-frac have the same scale regardless of the sharpness, but not Y. This is to balance Y contribution
){
listHistory(
useLMA,
path,
"",
lensSerial,
......@@ -3033,6 +3053,7 @@ public class CalibrationHardwareInterface {
}
public void listHistory(
boolean useLMA,
String path,
String serialNumber,
String lensSerial,
......@@ -3051,6 +3072,7 @@ public class CalibrationHardwareInterface {
){
this.focusingHistory.list(
useLMA,
path,
serialNumber,
lensSerial,
......@@ -3084,6 +3106,7 @@ public class CalibrationHardwareInterface {
pY0,
sampleCoord);
}
public FocusingField.FocusingFieldMeasurement getThisFFMeasurement(FocusingField focusingField){
return getThisFFMeasurement(focusingField, -1);
}
......@@ -3899,6 +3922,14 @@ public class CalibrationHardwareInterface {
if ((index<0) || (index>=this.history.size())) return null;
return this.history.get(index).getCenterResolutions();
}
public double [] getzTxTy(int index){
if ((index<0) || (index>=this.history.size())) return null;
return this.history.get(index).getzTxTy();
}
public double [] getzTxTy(){
if (this.history.size()<1) return null;
return getzTxTy(this.history.size()-1);
}
public int size(){
return this.history.size();
}
......@@ -5067,6 +5098,7 @@ if (debugLevel>=debugThreshold) System.out.println(i+" "+diff[0]+" "+diff[1]+" "
* @return array of 2 elements - {length at 0C, microns/degree}
*/
public double [] temperatureLinearApproximation(
boolean useLMA,
int numSamples, // number of last samples from history to use, 0 - use all
double lensDistanceWeightK, // used in distance calculation
double lensDistanceWeightY // R-frac, Y-frac have the same scale regardless of the sharpness, but not Y. This is to balance Y contribution
......@@ -5079,8 +5111,11 @@ if (debugLevel>=debugThreshold) System.out.println(i+" "+diff[0]+" "+diff[1]+" "
int firstSample=this.history.size()-numSamples;
for (int nSample=0;nSample<numSamples;nSample++){
resolutions= this.history.get(firstSample+nSample).getCenterResolutions();
data[nSample][0]=this.history.get(firstSample+nSample).getTemperature();
if (useLMA){
data[nSample][1]=this.history.get(firstSample+nSample).getzTxTy()[0];
} else {
resolutions= this.history.get(firstSample+nSample).getCenterResolutions();
data[nSample][1]=getLensDistance(
resolutions, // {R-sharpness,G-sharpness,B-sharpness}
true, // boolean absolute, // return absolutely calibrated data
......@@ -5089,6 +5124,7 @@ if (debugLevel>=debugThreshold) System.out.println(i+" "+diff[0]+" "+diff[1]+" "
1 //debugLevel
);
}
}
PolynomialApproximation pa= new PolynomialApproximation(debugLevel);
double [] polyCoeff=pa.polynomialApproximation1d(data, 1); // just linear
return polyCoeff;
......@@ -5524,6 +5560,7 @@ if (debugLevel>=debugThreshold) System.out.println(i+" "+diff[0]+" "+diff[1]+" "
// todo - add "probe around" - 6/3 points, +/- for each direction (fraction of sigma?)
public void list(
boolean useLMA,
String path,
String lensSerial, // if null - do not add average
String comment,
......@@ -5533,8 +5570,10 @@ if (debugLevel>=debugThreshold) System.out.println(i+" "+diff[0]+" "+diff[1]+" "
double weightRatioBlueToGreen,
double weightK, // 0.0 - all 3 component errors are combined with the same weights. 1.0 - proportional to squared first derivatives
double weightY){ // R-frac, Y-frac have the same scale regardless of the sharpness, but not Y. This is to balance Y contribution
list (path,
"",
list (
useLMA,
path,
"", // serial; number
lensSerial, // if null - do not add average
comment,
showIndividualComponents,
......@@ -5641,6 +5680,7 @@ if (debugLevel>=debugThreshold) System.out.println(i+" "+diff[0]+" "+diff[1]+" "
}
public void list(
boolean useLMA,
String path,
String serialNumber,
String lensSerial, // if null - do not add average
......@@ -5701,15 +5741,22 @@ if (debugLevel>=debugThreshold) System.out.println(i+" "+diff[0]+" "+diff[1]+" "
if (showIndividualComponents) {
for (int i=0;i<this.history.size();i++){
FocusingState focusingState=this.history.get(i);
double [] zTxTy=useLMA?focusingState.getzTxTy():null;
double [][] metrics=focusingState.getMetrics(weightRatioRedToGreen,weightRatioBlueToGreen);
double [][] resolution=focusingState.getSharpness(weightRatioRedToGreen,weightRatioBlueToGreen);
double dist= getLensDistance(
double dist= (zTxTy==null)?getLensDistance(
focusingState.getCenterResolutions(), // {R-sharpness,G-sharpness,B-sharpness}
true, //boolean absolute, // return absolutely calibrated data
weightK, // 0.0 - all 3 component errors are combined with the same weights. 1.0 - proportional to squared first derivatives
weightY, // R-frac, Y-frac have the same scale regardless of the sharpness, but not Y. This is to balance Y contribution
1); //int debugLevel
1): //int debugLevel
zTxTy[0];
double [] averageMetrics=metrics[3];
if (zTxTy!=null){
averageMetrics=metrics[3].clone(); // to modify w/o changing original
averageMetrics[1]=zTxTy[1]; // tiltX
averageMetrics[2]=zTxTy[2]; // tiltY
}
double [] averageResolution=resolution[3];
sb.append((i+1)+"\t");
String timestamp=focusingState.getTimestamp();
......@@ -5779,9 +5826,15 @@ if (debugLevel>=debugThreshold) System.out.println(i+" "+diff[0]+" "+diff[1]+" "
for (int i=0;i<this.history.size();i++){
// int parIndex=0;
FocusingState focusingState=this.history.get(i);
double [] zTxTy=useLMA?focusingState.getzTxTy():null;
double [][] metrics=focusingState.getMetrics(weightRatioRedToGreen,weightRatioBlueToGreen);
double [][] resolution=focusingState.getSharpness(weightRatioRedToGreen,weightRatioBlueToGreen);
double [] averageMetrics=metrics[3];
if (zTxTy!=null){
averageMetrics=metrics[3].clone(); // to modify w/o changing original
averageMetrics[1]=zTxTy[1]; // tiltX
averageMetrics[2]=zTxTy[2]; // tiltY
}
double [] averageResolution=resolution[3];
if (!justSummary) sb.append((i+1)+"\t");
String timestamp=focusingState.getTimestamp();
......@@ -5806,12 +5859,13 @@ if (debugLevel>=debugThreshold) System.out.println(i+" "+diff[0]+" "+diff[1]+" "
sums[4]+=focusingState.motorsPos[0];
sums[5]+=focusingState.motorsPos[1];
sums[6]+=focusingState.motorsPos[2];
double dist= getLensDistance(
double dist= (zTxTy==null)?getLensDistance(
focusingState.getCenterResolutions(), // {R-sharpness,G-sharpness,B-sharpness}
true, //boolean absolute, // return absolutely calibrated data
weightK, // 0.0 - all 3 component errors are combined with the same weights. 1.0 - proportional to squared first derivatives
weightY, // R-frac, Y-frac have the same scale regardless of the sharpness, but not Y. This is to balance Y contribution
1); //int debugLevel
1): //int debugLevel
zTxTy[0];
if (Double.isNaN(dist)){
if (!justSummary) sb.append("\t---");
} else {
......@@ -6199,7 +6253,19 @@ if (debugLevel>=debugThreshold) System.out.println(i+" "+diff[0]+" "+diff[1]+" "
1.0,
weightRatioBlueToGreen);
}
// alternative mode (from aberration model) ising metrics[6][]
public double [] getzTxTy(){
if (this.psfMetricses==null){
return null;
}
if ((this.psfMetricses.length<7) || (this.psfMetricses[6]==null)) {
System.out.println("BUG? psfMetrics does not have line 6 with lens berration model z, tx, ty");
return null;
}
double [] zTxTy={this.psfMetricses[6][0],this.psfMetricses[6][1],this.psfMetricses[6][2]};
return zTxTy;
}
public double [][] getMetrics(
double weightRed,
double weightGreen,
......
......@@ -5121,20 +5121,39 @@ public boolean LevenbergMarquardt(
public double [][] getAllZTM(
boolean noTiltScan,
FocusingField ff){
double [][] result =new double[ff.measurements.size()][6];
for (int i=0;i<result.length;i++) result[i]=adjustLMA(noTiltScan,ff.measurements.get(i),false);
FocusingField ff,
boolean noMotors){
double [][] result =new double[ff.measurements.size()][];
for (int i=0;i<result.length;i++) result[i]=adjustLMA(
noTiltScan,
ff.measurements.get(i),
false, // boolean parallelMove,
true, // boolean noQualB, // do not re-claculate testQualB
noMotors); // boolean noAdjust) // do not calculate correction
return result;
}
public double [] averageZTM(// results relative to optimal
boolean noTiltScan,
FocusingField ff){
double [] result =new double[6];
FocusingField ff,
boolean noMotors){
if (debugLevel>0) System.out.println("Calculating optimal focal/tilt, qualBOptimizeMode="+this.qualBOptimizeMode);
testQualB(false); // optimize qualB, store results in this.qualBOptimizationResults
if (debugLevel>0) {
System.out.println("Optimal absolute Zc="+this.qualBOptimizationResults[0]);
System.out.println("Optimal Tx="+this.qualBOptimizationResults[1]);
System.out.println("Optimal Ty="+this.qualBOptimizationResults[2]);
}
double [] result =new double[noMotors?3:6];
for (int i=0;i<result.length;i++) result[i]=0.0;
int num=0;
for (FocusingFieldMeasurement measurement:ff.measurements){
double [] ZTM = adjustLMA(noTiltScan,measurement,false);
double [] ZTM = adjustLMA(
noTiltScan,
measurement,
false, // boolean parallelMove,
true, // boolean noQualB, // do not re-claculate testQualB
noMotors); // boolean noAdjust) // do not calculate correction
if (ZTM!=null) {
for (int i=0;i<result.length;i++) result[i]+=ZTM[i];
num++;
......@@ -5147,7 +5166,10 @@ public boolean LevenbergMarquardt(
public double [] adjustLMA ( // result relative to optimal
boolean noTiltScan,
FocusingFieldMeasurement measurement,
boolean parallelMove){
boolean parallelMove,
boolean noQualB, // do not re-claculate testQualB
boolean noAdjust){ // do not calculate correction
if (!noQualB) {
if (debugLevel>0) System.out.println("Calculating optimal focal/tilt, qualBOptimizeMode="+this.qualBOptimizeMode);
testQualB(false); // optimize qualB, store results in this.qualBOptimizationResults
if (debugLevel>0) {
......@@ -5155,6 +5177,7 @@ public boolean LevenbergMarquardt(
System.out.println("Optimal Tx="+this.qualBOptimizationResults[1]);
System.out.println("Optimal Ty="+this.qualBOptimizationResults[2]);
}
}
if (!testMeasurement(
measurement,
zMin, //+best_qb_corr[0],
......@@ -5166,23 +5189,16 @@ public boolean LevenbergMarquardt(
if (debugLevel>0) System.out.println("adjustLMA() failed");
return null;
}
double [] result=new double [6];
// double [] best_qb_corr= fieldFitting.getBestQualB(
// k_red,
// k_blue,
// true);
double [] result=new double [noAdjust?3:6];
double [] zTilts=getCenterZTxTy(measurement);
result[0]=zTilts[0]-this.qualBOptimizationResults[0]; //best_qb_corr[0];
result[1]=zTilts[1]-this.qualBOptimizationResults[1];
result[2]=zTilts[2]-this.qualBOptimizationResults[2];
if (!noAdjust) {
double [] zm=null;
// if (parallelMove){
zm=new double [3];
for (int i=0;i<zm.length;i++) zm[i]=fieldFitting.mechanicalFocusingModel.mToZm(measurement.motors[i], i);
// }
if (this.debugLevel>0){
System.out.println("Current linearized motor positions, center="+(0.25*zm[0]+0.25*zm[1]+0.5*zm[2]));
for (int i=0;i<zm.length;i++) {
......@@ -5214,6 +5230,7 @@ public boolean LevenbergMarquardt(
result[4]=Double.NaN;
result[5]=Double.NaN;
}
}
return result;
}
......@@ -5310,7 +5327,7 @@ public boolean LevenbergMarquardt(
zTxTy[0]=fieldFitting.mechanicalFocusingModel.getValue(MECH_PAR.z0);
zTxTy[1]=fieldFitting.mechanicalFocusingModel.getValue(MECH_PAR.tx);
zTxTy[2]=fieldFitting.mechanicalFocusingModel.getValue(MECH_PAR.ty);
if (debugLevel>0) System.out.println("testMeasurement(), run "+n+" (z="+zTxTy[0]+" tx="+zTxTy[1]+" ty="+zTxTy[2]+")");
if (debugLevel>1) System.out.println("testMeasurement(), run "+n+" (z="+zTxTy[0]+" tx="+zTxTy[1]+" ty="+zTxTy[2]+")");
boolean [] was2PrevEnable=(wasPrevEnable==null)?null:wasPrevEnable.clone();
wasPrevEnable=(prevEnable==null)?null:prevEnable.clone();
this.lambda=this.adjustmentInitialLambda;
......@@ -5340,8 +5357,8 @@ public boolean LevenbergMarquardt(
break;
}
if (!changedEnable) {
if (debugLevel>0) System.out.println("No filter cnange, finished in "+(n+1)+" step"+((n==0)?"":"s"));
if (debugLevel>0) {
if (debugLevel>1) System.out.println("No filter cnange, finished in "+(n+1)+" step"+((n==0)?"":"s"));
if (debugLevel>1) {
System.out.println("=== Absolute shift/tilt from the measuremet ===");
for (int i=0;i<fieldFitting.mechanicalFocusingModel.paramValues.length;i++){
if ((fieldFitting.mechanicalSelect==null) || fieldFitting.mechanicalSelect[i] ) {
......@@ -9609,7 +9626,7 @@ f_corr: d_fcorr/d_zcorr=0, other: a, reff, kx -> ar[1], ar[2], ar[3], ar[4]
String msg="QualB="+this.currentQualB+" ("+this.firstQualB+") "+
" at "+ IJ.d2s(0.000000001*(System.nanoTime()-this.qStartTime),3);
if (debugLevel>0) System.out.println("qStepLevenbergMarquardtAction() "+msg);
if (debugLevel>1) System.out.println("qStepLevenbergMarquardtAction() "+msg);
// if (this.updateStatus) IJ.showStatus(msg);
if (updateStatus){
IJ.showStatus("Done: Step #"+this.iterationStepNumber+
......
......@@ -195,6 +195,7 @@ public class LensAdjustment {
public String gridGeometryFile="";
public String initialCalibrationFile="";
public String focusingHistoryFile="";
public boolean useLMAMetrics=true; // measure/report focal distance and tilts using lens model/LMA (when available)
public String strategyFile="";
public String resultsSuperDirectory=""; // directory with subdirectories named as serial numbers to stro results
public int EEPROM_channel=1; // EEPROM channel to read serial number from
......@@ -430,6 +431,7 @@ public class LensAdjustment {
String strategyFile,
String resultsSuperDirectory, // directory with subdirectories named as serial numbers to stro results
String focusingHistoryFile,
boolean useLMAMetrics, // measure/report focal distance and tilts using lens model/LMA (when available)
int EEPROM_channel, // EEPROM channel to read serial number from
boolean saveResults, // save focusing results
boolean showResults, // show focusing (includingh intermediate) results
......@@ -577,6 +579,7 @@ public class LensAdjustment {
this.strategyFile=strategyFile;
this.resultsSuperDirectory=resultsSuperDirectory; // directory with subdirectories named as serial numbers to stro results
this.focusingHistoryFile=focusingHistoryFile;
this.useLMAMetrics=useLMAMetrics; // measure/report focal distance and tilts using lens model/LMA (when available)
this.EEPROM_channel=EEPROM_channel; // EEPROM channel to read serial number from
this.saveResults=saveResults; // save focusing results
this.showResults=showResults; // show focusing (includingh intermediate) results
......@@ -725,6 +728,7 @@ public class LensAdjustment {
this.strategyFile,
this.resultsSuperDirectory, // directory with subdirectories named as serial numbers to stro results
this.focusingHistoryFile,
this.useLMAMetrics, // measure/report focal distance and tilts using lens model/LMA (when available)
this.EEPROM_channel,// EEPROM channel to read serial number from
this.saveResults, // save focusing results
this.showResults, // show focusing (includingh intermediate) results
......@@ -871,6 +875,7 @@ public class LensAdjustment {
properties.setProperty(prefix+"strategyFile",this.strategyFile+"");
properties.setProperty(prefix+"resultsSuperDirectory",this.resultsSuperDirectory+"");
properties.setProperty(prefix+"focusingHistoryFile",this.focusingHistoryFile+"");
properties.setProperty(prefix+"useLMAMetrics",this.useLMAMetrics+"");
properties.setProperty(prefix+"serialNumber",this.serialNumber+"");
if (!Double.isNaN(this.sensorTemperature))properties.setProperty(prefix+"sensorTemperature",this.sensorTemperature+"");
if (!Double.isNaN(this.result_lastKT))properties.setProperty(prefix+"result_lastKT",this.result_lastKT+"");
......@@ -1030,6 +1035,9 @@ public class LensAdjustment {
if (properties.getProperty(prefix+"focusingHistoryFile")!=null)
this.focusingHistoryFile=properties.getProperty(prefix+"focusingHistoryFile");
if (properties.getProperty(prefix+"useLMAMetrics")!=null)
this.useLMAMetrics=Boolean.parseBoolean(properties.getProperty(prefix+"useLMAMetrics"));
if (properties.getProperty(prefix+"serialNumber")!=null)
this.serialNumber=properties.getProperty(prefix+"serialNumber");
// this.serialNumber is only written, but never read from the configuration file (only from devivce)
......@@ -1441,7 +1449,8 @@ public class LensAdjustment {
gd.addStringField ("Initial camera intrinsic/extrinsic parametres file", this.initialCalibrationFile,40);
gd.addStringField ("Levenberg-Marquardt algorithm strategy file", this.strategyFile,40);
gd.addStringField ("Focusing results superdirectory (individual will be named by serial numbers)", this.resultsSuperDirectory,40);
gd.addStringField ("Measurement history (acquired during \"Scan Calib LMA\" file", this.focusingHistoryFile,80);
gd.addStringField ("Measurement history (acquired during \"Scan Calib LMA\") file", this.focusingHistoryFile,80);
gd.addCheckbox ("Use lens aberration model (if available) for focal distance and tilts", this.useLMAMetrics);
gd.addNumericField("EEPROM channel to read sensor serial number from", this.EEPROM_channel, 0,4,"");
gd.addCheckbox ("Save SFE focusing results (including intermediate) ", this.saveResults);
gd.addCheckbox ("Show SFE focusing results (including intermediate) ", this.showResults);
......@@ -1618,6 +1627,8 @@ public class LensAdjustment {
this.strategyFile= gd.getNextString();
this.resultsSuperDirectory= gd.getNextString();
this.focusingHistoryFile= gd.getNextString();
this.useLMAMetrics = gd.getNextBoolean();
this.EEPROM_channel= (int) gd.getNextNumber();
this.saveResults= gd.getNextBoolean();
this.showResults= gd.getNextBoolean();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment