Commit 1ac965a0 authored by Andrey Filippov's avatar Andrey Filippov

debugging

parent 3479dfe6
...@@ -4060,7 +4060,7 @@ if (MORE_BUTTONS) { ...@@ -4060,7 +4060,7 @@ if (MORE_BUTTONS) {
pY0, pY0,
sampleCoord, sampleCoord,
this.SYNC_COMMAND.stopRequested); this.SYNC_COMMAND.stopRequested);
if (PROPERTIES!=null) FOCUSING_FIELD.getProperties("FOCUSING_FIELD.", PROPERTIES);
System.out.println("Saving measurement history to "+path); System.out.println("Saving measurement history to "+path);
MOTORS.addCurrentHistoryToFocusingField(FOCUSING_FIELD); MOTORS.addCurrentHistoryToFocusingField(FOCUSING_FIELD);
FOCUSING_FIELD.saveXML(path); FOCUSING_FIELD.saveXML(path);
...@@ -4383,6 +4383,7 @@ if (MORE_BUTTONS) { ...@@ -4383,6 +4383,7 @@ if (MORE_BUTTONS) {
"",//); //String defaultPath); // AtomicInteger stopRequested "",//); //String defaultPath); // AtomicInteger stopRequested
this.SYNC_COMMAND.stopRequested); this.SYNC_COMMAND.stopRequested);
FOCUSING_FIELD.setDebugLevel(DEBUG_LEVEL); FOCUSING_FIELD.setDebugLevel(DEBUG_LEVEL);
if (PROPERTIES!=null) FOCUSING_FIELD.getProperties("FOCUSING_FIELD.", PROPERTIES);
System.out.println("Loaded FocusingField"); System.out.println("Loaded FocusingField");
if (!FOCUSING_FIELD.configureDataVector("Configure curvature",true)) return; if (!FOCUSING_FIELD.configureDataVector("Configure curvature",true)) return;
FOCUSING_FIELD.setDataVector(FOCUSING_FIELD.createDataVector()); FOCUSING_FIELD.setDataVector(FOCUSING_FIELD.createDataVector());
...@@ -12862,6 +12863,7 @@ private double [][] jacobianByJacobian(double [][] jacobian, boolean [] mask) { ...@@ -12862,6 +12863,7 @@ private double [][] jacobianByJacobian(double [][] jacobian, boolean [] mask) {
MOTORS.focusingHistory.setProperties("FOCUSING_HISTORY.", properties); MOTORS.focusingHistory.setProperties("FOCUSING_HISTORY.", properties);
GONIOMETER_PARAMETERS.setProperties("GONIOMETER_PARAMETERS.", properties); GONIOMETER_PARAMETERS.setProperties("GONIOMETER_PARAMETERS.", properties);
ABERRATIONS_PARAMETERS.setProperties("ABERRATIONS_PARAMETERS.", properties); ABERRATIONS_PARAMETERS.setProperties("ABERRATIONS_PARAMETERS.", properties);
if (FOCUSING_FIELD!=null) FOCUSING_FIELD.setProperties("FOCUSING_FIELD.", properties);
} }
/* ======================================================================== */ /* ======================================================================== */
public void getAllProperties(Properties properties){ public void getAllProperties(Properties properties){
...@@ -12900,6 +12902,7 @@ private double [][] jacobianByJacobian(double [][] jacobian, boolean [] mask) { ...@@ -12900,6 +12902,7 @@ private double [][] jacobianByJacobian(double [][] jacobian, boolean [] mask) {
MOTORS.focusingHistory.getProperties("FOCUSING_HISTORY.", properties); MOTORS.focusingHistory.getProperties("FOCUSING_HISTORY.", properties);
GONIOMETER_PARAMETERS.getProperties("GONIOMETER_PARAMETERS.", properties); GONIOMETER_PARAMETERS.getProperties("GONIOMETER_PARAMETERS.", properties);
ABERRATIONS_PARAMETERS.getProperties("ABERRATIONS_PARAMETERS.", properties); ABERRATIONS_PARAMETERS.getProperties("ABERRATIONS_PARAMETERS.", properties);
if (FOCUSING_FIELD!=null) FOCUSING_FIELD.getProperties("FOCUSING_FIELD.", properties);
} }
......
...@@ -53,122 +53,236 @@ import Jama.Matrix; ...@@ -53,122 +53,236 @@ import Jama.Matrix;
public class FocusingField { public class FocusingField {
// public String path; // public String path;
public static final double PIXEL_SIZE=0.0022; // mm // restored from properties
public static final String sep = " "; FieldFitting fieldFitting=null;
public static final String regSep = "\\s";
public String serialNumber;
public String lensSerial; // if null - do not add average
public String comment;
public double pX0_distortions; public double pX0_distortions;
public double pY0_distortions; public double pY0_distortions;
public double currentPX0; public double currentPX0;
public double currentPY0; public double currentPY0;
public double [][][] sampleCoord;
public ArrayList<FocusingFieldMeasurement> measurements;
boolean sagittalMaster=false; // center data is the same, when true sagittal fitting only may change r=0 coefficients, boolean sagittalMaster=false; // center data is the same, when true sagittal fitting only may change r=0 coefficients,
// when false - tangential is master // when false - tangential is master
double [] minMeas= {1.0,1.0,1.0,1.0,1.0,1.0}; // pixels double [] minMeas= {1.0,1.0,1.0,1.0,1.0,1.0}; // pixels
double [] maxMeas= {4.5,4.5,4.5,4.5,4.5,4.5}; // pixels double [] maxMeas= {4.5,4.5,4.5,4.5,4.5,4.5}; // pixels
double [] thresholdMax= {2.4,3.0,2.6,3.0,3.1,3.0}; // pixels double [] thresholdMax= {2.4,3.0,2.6,3.0,3.1,3.0}; // pixels
double [] weightReference=null;
boolean useMinMeas= true; boolean useMinMeas= true;
boolean useMaxMeas= true; boolean useMaxMeas= true;
boolean useThresholdMax=true; boolean useThresholdMax=true;
FieldFitting fieldFitting=null; int weightMode=1; // 0; // 0 - same weight, 1 - linear threshold difference, 2 - quadratic thershold difference
int weighMode=1; // 0; // 0 - same weight, 1 - linear threshold difference, 2 - quadratic thershold difference
double weightRadius=0.0; //2.0; // Gaussian sigma in mm double weightRadius=0.0; //2.0; // Gaussian sigma in mm
private double k_red=0.7;
private double k_blue=0.4;
private double qb_scan_below=-20.0; // um
private double qb_scan_above= 60.0; // um
private double qb_scan_step= 0.5; // um
private boolean qb_use_corrected=true;
private boolean qb_invert=true;
private boolean rslt_show_z_axial=true;
private boolean rslt_show_z_individual=true;
private boolean rslt_show_f_axial=true;
private boolean rslt_show_f_individual=true;
private double rslt_scan_below=-10.0;
private double rslt_scan_above= 10.0;
private double rslt_scan_step= 5.0;
private boolean rslt_mtf50_mode= true;
private boolean [] rslt_show_chn={true,true,true,true,true,true};
// not saved/restored
public static final double PIXEL_SIZE=0.0022; // mm
public static final String sep = " ";
public static final String regSep = "\\s";
public String serialNumber;
public String lensSerial; // if null - do not add average
public String comment;
public double [][][] sampleCoord;
public ArrayList<FocusingFieldMeasurement> measurements;
double [] weightReference=null;
MeasuredSample [] dataVector; MeasuredSample [] dataVector;
double [] dataValues; double [] dataValues;
double [] dataWeights; double [] dataWeights;
// double sumWeights=0.0; // double sumWeights=0.0;
double [][] jacobian=null; // rows - parameters, columns - samples double [][] jacobian=null; // rows - parameters, columns - samples
double [] currentVector=null; double [] currentVector=null;
double [] nextVector=null; double [] nextVector=null;
double [] savedVector=null; double [] savedVector=null;
private LMAArrays lMAArrays=null;
private LMAArrays savedLMAArrays=null;
private double [] currentfX=null; // array of "f(x)" - simulated data for all images, combining pixel-X and pixel-Y (odd/even)
private double [] nextfX=null; // array of "f(x)" - simulated data for all images, combining pixel-X and pixel-Y (odd/even)
private double currentRMS=-1.0; // calculated RMS for the currentVector->currentfX
private double currentRMSPure=-1.0; // calculated RMS for the currentVector->currentfX
private double nextRMS=-1.0; // calculated RMS for the nextVector->nextfX
private double nextRMSPure=-1.0; // calculated RMS for the nextVector->nextfX
private double firstRMS=-1.0; // RMS before current series of LMA started
private double firstRMSPure=-1.0; // RMS before current series of LMA started
private double lambdaStepUp= 8.0; // multiply lambda by this if result is worse
private double lambdaStepDown= 0.5; // multiply lambda by this if result is better
private double thresholdFinish=0.001; // (copied from series) stop iterations if 2 last steps had less improvement (but not worsening )
private int numIterations= 100; // maximal number of iterations
private double maxLambda= 100.0; // max lambda to fail
private double lambda=0.001; // copied from series
private double [] lastImprovements= {-1.0,-1.0}; // {last improvement, previous improvement}. If both >0 and < thresholdFinish - done
private int iterationStepNumber=0;
private boolean stopEachStep= true; // open dialog after each fitting step
private boolean stopOnFailure= true; // open dialog when fitting series failed
private boolean showParams= false; // show modified parameters
private boolean showDisabledParams = false;
private boolean showCorrectionParams = false;
private boolean keepCorrectionParameters = true;
private long startTime=0;
private AtomicInteger stopRequested=null; // 1 - stop now, 2 - when convenient
private boolean saveSeries=false; // just for the dialog
private boolean showMotors = true;
private boolean [] showMeasCalc = {true,true,true};
private boolean [] showColors = {true,true,true};
private boolean [] showDirs = {true,true};
private boolean [] showSamples = null;
private boolean showAllSamples = true;
private boolean showIgnoredData= false;
private boolean showRad = true;
private boolean [][][][][] sampleMask=null;
private boolean correct_measurement_ST=true;
private boolean updateWeightWhileFitting=false;
public int debugLevel;
public boolean debugDerivatives;
public boolean debugDerivativesFxDxDy=false;
private double k_red=0.7;
private double k_blue=0.4;
private double qb_scan_below=-20.0; // um
private double qb_scan_above= 60.0; // um
private double qb_scan_step= 0.5; // um
private boolean qb_use_corrected=true;
private boolean qb_invert=true;
private boolean rslt_show_z_axial=true;
private boolean rslt_show_z_individual=true;
private boolean rslt_show_f_axial=true;
private boolean rslt_show_f_individual=true;
private double rslt_scan_below=-10.0;
private double rslt_scan_above= 10.0;
private double rslt_scan_step= 5.0;
private boolean rslt_mtf50_mode= true;
private boolean [] rslt_show_chn={true,true,true,true,true,true};
// public double fwhm_to_mtf50=500.0; // put actual number
public double fwhm_to_mtf50=2*Math.log(2.0)/Math.PI*1000; //pi/0.004
private LMAArrays lMAArrays=null;
private LMAArrays savedLMAArrays=null;
private double [] currentfX=null; // array of "f(x)" - simulated data for all images, combining pixel-X and pixel-Y (odd/even)
private double [] nextfX=null; // array of "f(x)" - simulated data for all images, combining pixel-X and pixel-Y (odd/even)
private double currentRMS=-1.0; // calculated RMS for the currentVector->currentfX
private double currentRMSPure=-1.0; // calculated RMS for the currentVector->currentfX
private double nextRMS=-1.0; // calculated RMS for the nextVector->nextfX
private double nextRMSPure=-1.0; // calculated RMS for the nextVector->nextfX
private double firstRMS=-1.0; // RMS before current series of LMA started
private double firstRMSPure=-1.0; // RMS before current series of LMA started
private double lambdaStepUp= 8.0; // multiply lambda by this if result is worse
private double lambdaStepDown= 0.5; // multiply lambda by this if result is better
private double thresholdFinish=0.001; // (copied from series) stop iterations if 2 last steps had less improvement (but not worsening )
private int numIterations= 100; // maximal number of iterations
private double maxLambda= 100.0; // max lambda to fail
private double lambda=0.001; // copied from series
private double [] lastImprovements= {-1.0,-1.0}; // {last improvement, previous improvement}. If both >0 and < thresholdFinish - done
private int iterationStepNumber=0;
private boolean stopEachStep= true; // open dialog after each fitting step
private boolean stopOnFailure= true; // open dialog when fitting series failed
private boolean showParams= false; // show modified parameters
private boolean showDisabledParams = false;
private boolean showCorrectionParams = false;
private boolean keepCorrectionParameters = true;
private long startTime=0;
private AtomicInteger stopRequested=null; // 1 - stop now, 2 - when convenient
private boolean saveSeries=false; // just for the dialog
private boolean showMotors = true;
private boolean [] showMeasCalc = {true,true,true};
private boolean [] showColors = {true,true,true};
private boolean [] showDirs = {true,true};
private boolean [] showSamples = null;
private boolean showAllSamples = true;
private boolean showIgnoredData= false;
private boolean showRad = true;
private boolean [][][][][] sampleMask=null;
private boolean correct_measurement_ST=true;
private boolean updateWeightWhileFitting=false;
public int debugLevel;
public boolean debugDerivatives;
public boolean debugDerivativesFxDxDy=false;
private Properties savedProperties=null; // to-be applied
private String propertiesPrefix=null;
// public double fwhm_to_mtf50=500.0; // put actual number
public double fwhm_to_mtf50=2*Math.log(2.0)/Math.PI*1000; //pi/0.004
public void setProperties(String prefix,Properties properties){
System.out.println("FocusingField: setProperties()");
if (fieldFitting == null) {
System.out.println("fieldFitting is not initioalized, nothing to save");
return;
}
fieldFitting.setProperties(prefix+"fieldFitting.",properties);
properties.setProperty(prefix+"pX0_distortions",pX0_distortions+"");
properties.setProperty(prefix+"pY0_distortions",pY0_distortions+"");
properties.setProperty(prefix+"currentPX0",currentPX0+"");
properties.setProperty(prefix+"currentPY0",currentPY0+"");
properties.setProperty(prefix+"sagittalMaster",sagittalMaster+"");
for (int chn=0; chn<minMeas.length; chn++) properties.setProperty(prefix+"minMeas_"+chn,minMeas[chn]+"");
for (int chn=0; chn<maxMeas.length; chn++) properties.setProperty(prefix+"maxMeas_"+chn,maxMeas[chn]+"");
for (int chn=0; chn<thresholdMax.length; chn++) properties.setProperty(prefix+"thresholdMax_"+chn,thresholdMax[chn]+"");
properties.setProperty(prefix+"useMinMeas",useMinMeas+"");
properties.setProperty(prefix+"useMaxMeas",useMaxMeas+"");
properties.setProperty(prefix+"useThresholdMax",useThresholdMax+"");
properties.setProperty(prefix+"weightMode",weightMode+"");
properties.setProperty(prefix+"weightRadius",weightRadius+"");
properties.setProperty(prefix+"k_red",k_red+"");
properties.setProperty(prefix+"k_blue",k_blue+"");
properties.setProperty(prefix+"qb_scan_below",qb_scan_below+"");
properties.setProperty(prefix+"qb_scan_above",qb_scan_above+"");
properties.setProperty(prefix+"qb_scan_step",qb_scan_step+"");
properties.setProperty(prefix+"qb_use_corrected",qb_use_corrected+"");
properties.setProperty(prefix+"qb_invert",qb_invert+"");
properties.setProperty(prefix+"rslt_show_z_axial",rslt_show_z_axial+"");
properties.setProperty(prefix+"rslt_show_z_individual",rslt_show_z_individual+"");
properties.setProperty(prefix+"rslt_show_f_axial",rslt_show_f_axial+"");
properties.setProperty(prefix+"rslt_show_f_individual",rslt_show_f_individual+"");
properties.setProperty(prefix+"rslt_scan_below",rslt_scan_below+"");
properties.setProperty(prefix+"rslt_scan_above",rslt_scan_above+"");
properties.setProperty(prefix+"rslt_scan_step",rslt_scan_step+"");
properties.setProperty(prefix+"rslt_mtf50_mode",rslt_mtf50_mode+"");
for (int chn=0; chn<rslt_show_chn.length; chn++) properties.setProperty(prefix+"rslt_show_chn_"+chn,rslt_show_chn[chn]+"");
}
public void getProperties(String prefix,Properties properties){
savedProperties=properties;
propertiesPrefix=prefix;
System.out.println("FocusingField: getProperties()");
if (fieldFitting == null) {
System.out.println("fieldFitting is not initialized, will apply properties later");
return; //fieldFitting=new FieldFitting();
}
fieldFitting.getProperties(prefix+"fieldFitting.",properties);
if (properties.getProperty(prefix+"pX0_distortions")!=null)
pX0_distortions=Double.parseDouble(properties.getProperty(prefix+"pX0_distortions"));
if (properties.getProperty(prefix+"pY0_distortions")!=null)
pY0_distortions=Double.parseDouble(properties.getProperty(prefix+"pY0_distortions"));
if (properties.getProperty(prefix+"currentPX0")!=null)
currentPX0=Double.parseDouble(properties.getProperty(prefix+"currentPX0"));
if (properties.getProperty(prefix+"currentPY0")!=null)
currentPY0=Double.parseDouble(properties.getProperty(prefix+"currentPY0"));
for (int chn=0; chn<minMeas.length; chn++) if (properties.getProperty(prefix+"minMeas_"+chn)!=null)
minMeas[chn]=Double.parseDouble(properties.getProperty(prefix+"minMeas_"+chn));
for (int chn=0; chn<maxMeas.length; chn++) if (properties.getProperty(prefix+"maxMeas_"+chn)!=null)
maxMeas[chn]=Double.parseDouble(properties.getProperty(prefix+"maxMeas_"+chn));
for (int chn=0; chn<thresholdMax.length; chn++) if (properties.getProperty(prefix+"thresholdMax_"+chn)!=null)
thresholdMax[chn]=Double.parseDouble(properties.getProperty(prefix+"thresholdMax_"+chn));
if (properties.getProperty(prefix+"useMinMeas")!=null)
useMinMeas=Boolean.parseBoolean(properties.getProperty(prefix+"useMinMeas"));
if (properties.getProperty(prefix+"useMaxMeas")!=null)
useMaxMeas=Boolean.parseBoolean(properties.getProperty(prefix+"useMaxMeas"));
if (properties.getProperty(prefix+"useThresholdMax")!=null)
useThresholdMax=Boolean.parseBoolean(properties.getProperty(prefix+"useThresholdMax"));
if (properties.getProperty(prefix+"weightMode")!=null)
weightMode=Integer.parseInt(properties.getProperty(prefix+"weightMode"));
if (properties.getProperty(prefix+"weightRadius")!=null)
weightRadius=Double.parseDouble(properties.getProperty(prefix+"weightRadius"));
if (properties.getProperty(prefix+"k_red")!=null)
k_red=Double.parseDouble(properties.getProperty(prefix+"k_red"));
if (properties.getProperty(prefix+"k_blue")!=null)
k_blue=Double.parseDouble(properties.getProperty(prefix+"k_blue"));
if (properties.getProperty(prefix+"qb_scan_below")!=null)
qb_scan_below=Double.parseDouble(properties.getProperty(prefix+"qb_scan_below"));
if (properties.getProperty(prefix+"qb_scan_above")!=null)
qb_scan_above=Double.parseDouble(properties.getProperty(prefix+"qb_scan_above"));
if (properties.getProperty(prefix+"qb_scan_step")!=null)
qb_scan_step=Double.parseDouble(properties.getProperty(prefix+"qb_scan_step"));
if (properties.getProperty(prefix+"qb_use_corrected")!=null)
qb_use_corrected=Boolean.parseBoolean(properties.getProperty(prefix+"qb_use_corrected"));
if (properties.getProperty(prefix+"qb_invert")!=null)
qb_invert=Boolean.parseBoolean(properties.getProperty(prefix+"qb_invert"));
if (properties.getProperty(prefix+"rslt_show_z_axial")!=null)
rslt_show_z_axial=Boolean.parseBoolean(properties.getProperty(prefix+"rslt_show_z_axial"));
if (properties.getProperty(prefix+"rslt_show_z_individual")!=null)
rslt_show_z_individual=Boolean.parseBoolean(properties.getProperty(prefix+"rslt_show_z_individual"));
if (properties.getProperty(prefix+"rslt_show_f_axial")!=null)
rslt_show_f_axial=Boolean.parseBoolean(properties.getProperty(prefix+"rslt_show_f_axial"));
if (properties.getProperty(prefix+"rslt_show_f_individual")!=null)
rslt_show_f_individual=Boolean.parseBoolean(properties.getProperty(prefix+"rslt_show_f_individual"));
if (properties.getProperty(prefix+"rslt_scan_below")!=null)
rslt_scan_below=Double.parseDouble(properties.getProperty(prefix+"rslt_scan_below"));
if (properties.getProperty(prefix+"rslt_scan_above")!=null)
rslt_scan_above=Double.parseDouble(properties.getProperty(prefix+"rslt_scan_above"));
if (properties.getProperty(prefix+"rslt_scan_step")!=null)
rslt_scan_step=Double.parseDouble(properties.getProperty(prefix+"rslt_scan_step"));
if (properties.getProperty(prefix+"rslt_mtf50_mode")!=null)
rslt_mtf50_mode=Boolean.parseBoolean(properties.getProperty(prefix+"rslt_mtf50_mode"));
for (int chn=0; chn<rslt_show_chn.length; chn++) if (properties.getProperty(prefix+"rslt_show_chn_"+chn)!=null)
rslt_show_chn[chn]=Boolean.parseBoolean(properties.getProperty(prefix+"rslt_show_chn_"+chn));
}
public void setDebugLevel(int debugLevel){ public void setDebugLevel(int debugLevel){
this.debugLevel=debugLevel; this.debugLevel=debugLevel;
} }
public class LMAArrays { // reuse from Distortions? public class LMAArrays { // reuse from Distortions?
public double [][] jTByJ= null; // jacobian multiplied by Jacobian transposed public double [][] jTByJ= null; // jacobian multiplied by Jacobian transposed
public double [] jTByDiff=null; // jacobian multiplied difference vector public double [] jTByDiff=null; // jacobian multiplied difference vector
public LMAArrays clone() { public LMAArrays clone() {
LMAArrays lma=new LMAArrays(); LMAArrays lma=new LMAArrays();
lma.jTByJ = this.jTByJ.clone(); lma.jTByJ = this.jTByJ.clone();
for (int i=0;i<this.jTByJ.length;i++) lma.jTByJ[i]=this.jTByJ[i].clone(); for (int i=0;i<this.jTByJ.length;i++) lma.jTByJ[i]=this.jTByJ[i].clone();
lma.jTByDiff=this.jTByDiff.clone(); lma.jTByDiff=this.jTByDiff.clone();
return lma; return lma;
} }
} }
public enum MECH_PAR { public enum MECH_PAR {
K0, // Average motor center travel","um/step","0.0124"}, K0, // Average motor center travel","um/step","0.0124"},
...@@ -267,7 +381,7 @@ public boolean configureDataVector(String title, boolean forcenew){ ...@@ -267,7 +381,7 @@ public boolean configureDataVector(String title, boolean forcenew){
gd.addNumericField("Number of parameters for radial dependence of PSF curves (>=1)",numCurvPars[1],0); gd.addNumericField("Number of parameters for radial dependence of PSF curves (>=1)",numCurvPars[1],0);
} }
gd.addMessage(""); gd.addMessage("");
gd.addNumericField("Data weight mode (0 - equal mode, 1 -linear treshold diff, 2 - quadratic threshold diff)",weighMode,0); gd.addNumericField("Data weight mode (0 - equal mode, 1 -linear treshold diff, 2 - quadratic threshold diff)",weightMode,0);
gd.addNumericField("Data weight radius (multiply weight by Gaussian), 0 - no dependence on radius",weightRadius,3,5,"mm"); gd.addNumericField("Data weight radius (multiply weight by Gaussian), 0 - no dependence on radius",weightRadius,3,5,"mm");
gd.addCheckbox("Setup parameter masks?",setupMasks); gd.addCheckbox("Setup parameter masks?",setupMasks);
gd.addCheckbox("Setup parameter values?",setupParameters); gd.addCheckbox("Setup parameter values?",setupParameters);
...@@ -289,7 +403,7 @@ public boolean configureDataVector(String title, boolean forcenew){ ...@@ -289,7 +403,7 @@ public boolean configureDataVector(String title, boolean forcenew){
numCurvPars[0] = (int) gd.getNextNumber(); numCurvPars[0] = (int) gd.getNextNumber();
numCurvPars[1] = (int) gd.getNextNumber(); numCurvPars[1] = (int) gd.getNextNumber();
} }
weighMode = (int) gd.getNextNumber(); weightMode = (int) gd.getNextNumber();
weightRadius = gd.getNextNumber(); weightRadius = gd.getNextNumber();
setupMasks= gd.getNextBoolean(); setupMasks= gd.getNextBoolean();
...@@ -303,6 +417,10 @@ public boolean configureDataVector(String title, boolean forcenew){ ...@@ -303,6 +417,10 @@ public boolean configureDataVector(String title, boolean forcenew){
currentPY0, currentPY0,
numCurvPars[0], numCurvPars[0],
numCurvPars[1]); numCurvPars[1]);
if (savedProperties!=null){
System.out.println("configureDataVector(): Applying properties");
getProperties(propertiesPrefix,savedProperties);
}
} }
if (setupMasks) { if (setupMasks) {
if (!fieldFitting.maskSetDialog("Setup parameter masks")) return false; if (!fieldFitting.maskSetDialog("Setup parameter masks")) return false;
...@@ -334,7 +452,7 @@ public void setDataVector(MeasuredSample [] vector){ // remove unused channels i ...@@ -334,7 +452,7 @@ public void setDataVector(MeasuredSample [] vector){ // remove unused channels i
dataValues = new double [dataVector.length+corrLength]; dataValues = new double [dataVector.length+corrLength];
dataWeights = new double [dataVector.length+corrLength]; dataWeights = new double [dataVector.length+corrLength];
// sumWeights=0.0; // sumWeights=0.0;
int mode=weighMode; int mode=weightMode;
double kw= (weightRadius>0.0)?(-0.5*getPixelMM()*getPixelMM()/(weightRadius*weightRadius)):0; double kw= (weightRadius>0.0)?(-0.5*getPixelMM()*getPixelMM()/(weightRadius*weightRadius)):0;
//weightRadius //weightRadius
if (weightReference==null)mode=0; if (weightReference==null)mode=0;
...@@ -427,11 +545,11 @@ public double [] createFXandJacobian(boolean createJacobian){ ...@@ -427,11 +545,11 @@ public double [] createFXandJacobian(boolean createJacobian){
fx[n]=subData[selChanIndices[ms.channel]]; fx[n]=subData[selChanIndices[ms.channel]];
if (createJacobian) { if (createJacobian) {
double [] thisDerivs=derivs[selChanIndices[ms.channel]]; double [] thisDerivs=derivs[selChanIndices[ms.channel]];
// for (int i=0;i<numRegPars;i++){ // for (int i=0;i<numRegPars;i++){
// contains derivatives for normal and correction parameters // contains derivatives for normal and correction parameters
for (int i=0;i<numPars;i++){ for (int i=0;i<numPars;i++){
// jacobian[i][n]=derivs[selChanIndices[ms.channel]][i]; // jacobian[i][n]=derivs[selChanIndices[ms.channel]][i];
jacobian[i][n]=thisDerivs[i]; jacobian[i][n]=thisDerivs[i];
} }
//TODO: correct /dpx, /dpy to compensate for measured S,T calcualtion //TODO: correct /dpx, /dpy to compensate for measured S,T calcualtion
...@@ -444,6 +562,7 @@ public double [] createFXandJacobian(boolean createJacobian){ ...@@ -444,6 +562,7 @@ public double [] createFXandJacobian(boolean createJacobian){
} }
} }
// add mutual dependence of correction parameters. first - values (fx) // add mutual dependence of correction parameters. first - values (fx)
// System.out.println("Using sampleCorrVector 1");
int index=dataVector.length; // add to the end of vector int index=dataVector.length; // add to the end of vector
if (fieldFitting.sampleCorrChnParIndex!=null){ if (fieldFitting.sampleCorrChnParIndex!=null){
int numSamples=getNumSamples(); int numSamples=getNumSamples();
...@@ -1038,7 +1157,7 @@ d_s2/d_x0= 2*delta_x*delta_y^2/r2^2 ...@@ -1038,7 +1157,7 @@ d_s2/d_x0= 2*delta_x*delta_y^2/r2^2
this.currentRMS= calcErrorDiffY(this.currentfX,false); this.currentRMS= calcErrorDiffY(this.currentfX,false);
this.currentRMSPure=calcErrorDiffY(this.currentfX, true); this.currentRMSPure=calcErrorDiffY(this.currentfX, true);
if (debugLevel>1) { if (debugLevel>1) {
System.out.println(": initial RMS="+IJ.d2s(this.currentRMS,8)+" (pure RMS"+IJ.d2s(this.currentRMSPure,8)+")"+ System.out.println(": initial RMS="+IJ.d2s(this.currentRMS,8)+" (pure RMS="+IJ.d2s(this.currentRMSPure,8)+")"+
". Calculating next Jacobian. Points:"+this.dataValues.length+" Parameters:"+this.currentVector.length); ". Calculating next Jacobian. Points:"+this.dataValues.length+" Parameters:"+this.currentVector.length);
} }
} else { } else {
...@@ -1167,10 +1286,10 @@ public void stepLevenbergMarquardtAction(int debugLevel){// ...@@ -1167,10 +1286,10 @@ public void stepLevenbergMarquardtAction(int debugLevel){//
*/ */
public boolean selectLMAParameters(){ public boolean selectLMAParameters(){
// int numSeries=fittingStrategy.getNumSeries(); // int numSeries=fittingStrategy.getNumSeries();
boolean resetCorrections=false; // boolean resetCorrections=false;
GenericDialog gd = new GenericDialog("Levenberg-Marquardt algorithm parameters for cameras distortions/locations"); GenericDialog gd = new GenericDialog("Levenberg-Marquardt algorithm parameters for cameras distortions/locations");
gd.addCheckbox("Debug df/dX0, df/dY0", false); gd.addCheckbox("Debug df/dX0, df/dY0", false);
gd.addCheckbox("Keep current correction parameters", this.keepCorrectionParameters); gd.addCheckbox("Keep current correction parameters (do not reset)", this.keepCorrectionParameters);
// gd.addNumericField("Iteration number to start (0.."+(numSeries-1)+")", this.seriesNumber, 0); // gd.addNumericField("Iteration number to start (0.."+(numSeries-1)+")", this.seriesNumber, 0);
gd.addNumericField("Initial LMA Lambda ", this.lambda, 5); gd.addNumericField("Initial LMA Lambda ", this.lambda, 5);
gd.addNumericField("Multiply lambda on success", this.lambdaStepDown, 5); gd.addNumericField("Multiply lambda on success", this.lambdaStepDown, 5);
...@@ -1188,7 +1307,7 @@ public boolean selectLMAParameters(){ ...@@ -1188,7 +1307,7 @@ public boolean selectLMAParameters(){
gd.addCheckbox("Show disabled parameters", this.showDisabledParams); gd.addCheckbox("Show disabled parameters", this.showDisabledParams);
gd.addCheckbox("Show per-sample correction parameters", this.showCorrectionParams); gd.addCheckbox("Show per-sample correction parameters", this.showCorrectionParams);
gd.addCheckbox("Reset all per-sample corrections to zero", resetCorrections); // gd.addCheckbox("Reset all per-sample corrections to zero", resetCorrections);
// gd.addCheckbox("Show debug images before correction",this.showThisImages); // gd.addCheckbox("Show debug images before correction",this.showThisImages);
// gd.addCheckbox("Show debug images after correction", this.showNextImages); // gd.addCheckbox("Show debug images after correction", this.showNextImages);
...@@ -1216,8 +1335,8 @@ public boolean selectLMAParameters(){ ...@@ -1216,8 +1335,8 @@ public boolean selectLMAParameters(){
// this.showNextImages= gd.getNextBoolean(); // this.showNextImages= gd.getNextBoolean();
// this.threadsMax= (int) gd.getNextNumber(); // this.threadsMax= (int) gd.getNextNumber();
// this.threadedLMA= gd.getNextBoolean(); // this.threadedLMA= gd.getNextBoolean();
resetCorrections= gd.getNextBoolean(); // resetCorrections= gd.getNextBoolean();
if (resetCorrections) fieldFitting.resetSampleCorr(); if (!keepCorrectionParameters) fieldFitting.resetSampleCorr();
return true; return true;
} }
...@@ -1249,7 +1368,7 @@ public void listData(String title, String path){ ...@@ -1249,7 +1368,7 @@ public void listData(String title, String path){
gd.addCheckbox("Show RED data", this.showColors[0]); gd.addCheckbox("Show RED data", this.showColors[0]);
gd.addCheckbox("Show GREEN data", this.showColors[1]); gd.addCheckbox("Show GREEN data", this.showColors[1]);
gd.addCheckbox("Show BLUE data", this.showColors[2]); gd.addCheckbox("Show BLUE data", this.showColors[2]);
gd.addCheckbox("Show SAGGITAL data", this.showDirs[0]); gd.addCheckbox("Show SAGITAL data", this.showDirs[0]);
gd.addCheckbox("Show TANGENTIAL data", this.showDirs[1]); gd.addCheckbox("Show TANGENTIAL data", this.showDirs[1]);
gd.addMessage("Select field samples"); gd.addMessage("Select field samples");
for (int i=0; i<sampleCoord.length;i++) for (int j=0; j<sampleCoord[0].length;j++){ for (int i=0; i<sampleCoord.length;i++) for (int j=0; j<sampleCoord[0].length;j++){
...@@ -2197,6 +2316,7 @@ public boolean LevenbergMarquardt(boolean openDialog, int debugLevel){ ...@@ -2197,6 +2316,7 @@ public boolean LevenbergMarquardt(boolean openDialog, int debugLevel){
} }
} }
public class FieldFitting{ public class FieldFitting{
// private Properties savedProperties=null;
private double [] pXY=null; private double [] pXY=null;
private boolean [] centerSelect=null; private boolean [] centerSelect=null;
private boolean [] centerSelectDefault={true,true}; private boolean [] centerSelectDefault={true,true};
...@@ -2227,10 +2347,13 @@ public boolean LevenbergMarquardt(boolean openDialog, int debugLevel){ ...@@ -2227,10 +2347,13 @@ public boolean LevenbergMarquardt(boolean openDialog, int debugLevel){
"Blue, sagittal","Blue, tangential"}; "Blue, sagittal","Blue, tangential"};
public void setProperties(String prefix,Properties properties){ public void setProperties(String prefix,Properties properties){
if (mechanicalFocusingModel==null){
System.out.println ("Mechanical properties not yet initialized, will save properties later");
return;
}
properties.setProperty(prefix+"numberOfLocations",numberOfLocations+"");
properties.setProperty(prefix+"centerSelect_X",centerSelect[0]+""); properties.setProperty(prefix+"centerSelect_X",centerSelect[0]+"");
properties.setProperty(prefix+"centerSelect_Y",centerSelect[1]+""); properties.setProperty(prefix+"centerSelect_Y",centerSelect[1]+"");
mechanicalFocusingModel.setProperties(prefix+"mechanicalFocusingModel.",properties); mechanicalFocusingModel.setProperties(prefix+"mechanicalFocusingModel.",properties);
for (int i=0;i<curvatureModel.length;i++){ for (int i=0;i<curvatureModel.length;i++){
if (curvatureModel[i]!=null) curvatureModel[i].setProperties(prefix+"curvatureModel_"+i+".",properties); if (curvatureModel[i]!=null) curvatureModel[i].setProperties(prefix+"curvatureModel_"+i+".",properties);
...@@ -2256,15 +2379,139 @@ public boolean LevenbergMarquardt(boolean openDialog, int debugLevel){ ...@@ -2256,15 +2379,139 @@ public boolean LevenbergMarquardt(boolean openDialog, int debugLevel){
for (int chn=0;chn<sampleCorrPullZero.length;chn++) if (sampleCorrPullZero[chn]!=null) for (int i=0;i<sampleCorrPullZero[chn].length;i++){ for (int chn=0;chn<sampleCorrPullZero.length;chn++) if (sampleCorrPullZero[chn]!=null) for (int i=0;i<sampleCorrPullZero[chn].length;i++){
properties.setProperty(prefix+"sampleCorrPullZero_"+chn+"_"+i,sampleCorrPullZero[chn][i]+""); properties.setProperty(prefix+"sampleCorrPullZero_"+chn+"_"+i,sampleCorrPullZero[chn][i]+"");
} }
/* // save correction parameters values
// private double [][][] correctionParameters=new double[6][][]; // all
if (correctionParameters!=null){
for (int chn=0;chn<correctionParameters.length; chn++) if (correctionParameters[chn]!=null){
for (int np=0;np<correctionParameters[chn].length;np++) if (correctionParameters[chn][np]!=null){
for (int i=0;i<correctionParameters[chn][np].length;i++){
properties.setProperty(prefix+"correctionParameters_"+chn+"_"+np+"_"+i,correctionParameters[chn][np][i]+"");
}
}
}
}
}
public void getProperties(String prefix,Properties properties){
if (properties.getProperty(prefix+"numberOfLocations")!=null)
numberOfLocations=Integer.parseInt(properties.getProperty(prefix+"numberOfLocations"));
if (properties.getProperty(prefix+"centerSelect_X")!=null)
centerSelect[0]=Boolean.parseBoolean(properties.getProperty(prefix+"centerSelect_X"));
if (properties.getProperty(prefix+"centerSelect_Y")!=null)
centerSelect[1]=Boolean.parseBoolean(properties.getProperty(prefix+"centerSelect_Y"));
if (mechanicalFocusingModel==null){
System.out.println ("Mechanical properties not yet initialized, will apply properties later");
return;
}
mechanicalFocusingModel.getProperties(prefix+"mechanicalFocusingModel.",properties);
for (int i=0;i<curvatureModel.length;i++){
if (curvatureModel[i]!=null) curvatureModel[i].getProperties(prefix+"curvatureModel_"+i+".",properties);
}
if (channelSelect==null) {
channelSelect=new boolean [6];
for (int i=0;i<channelSelect.length;i++)channelSelect[i]=true;
}
for (int i=0;i<channelSelect.length;i++) if (properties.getProperty(prefix+"channelSelect_"+i)!=null) {
channelSelect[i]=Boolean.parseBoolean(properties.getProperty(prefix+"channelSelect_"+i));
}
if ((mechanicalSelect==null) || (mechanicalSelect.length!=mechanicalFocusingModel.getDefaultMask().length)){
mechanicalSelect=mechanicalFocusingModel.getDefaultMask();
}
for (int i=0;i<mechanicalSelect.length;i++) if (properties.getProperty(prefix+"mechanicalSelect_"+i)!=null) {
mechanicalSelect[i]=Boolean.parseBoolean(properties.getProperty(prefix+"mechanicalSelect_"+i));
}
// curvature parameter selection: first index : channel, inner index - parameter number (radial fast, z - outer)
if (curvatureSelect==null) {
curvatureSelect=new boolean [curvatureModel.length][];
for (int i=0;i<curvatureSelect.length;i++) curvatureSelect[i]=null;
}
for (int chn=0;chn<correctionParameters.length; chn++) if (curvatureModel[chn]!=null){
if ((curvatureSelect[chn]==null) || (curvatureSelect[chn].length!=curvatureModel[chn].getDefaultMask().length)){
curvatureSelect[chn]=curvatureModel[chn].getDefaultMask();
}
for (int i=0;i<curvatureSelect[chn].length;i++) if (properties.getProperty(prefix+"curvatureSelect_"+chn+"_"+i)!=null){
curvatureSelect[chn][i]=Boolean.parseBoolean(properties.getProperty(prefix+"curvatureSelect_"+chn+"_"+i));
}
}
private double [][] sampleCorrCost= new double[6][]; // equivalent cost of one unit of parameter value (in result units, um) // get correction setup parameters:
private double [][] sampleCorrSigma= new double[6][]; // sigma (in mm) for neighbors influence if (sampleCorrSelect==null){
private double [][] sampleCorrPullZero=new double[6][]; // 1.0 - only difference from neighbors matters, 0.0 - only difference from 0 sampleCorrSelect=new boolean [curvatureModel.length][];
for (int i=0;i<sampleCorrSelect.length;i++) sampleCorrSelect[i]=null;
}
for (int chn=0;chn<curvatureModel.length;chn++) if (curvatureModel[chn]!=null){
if ((sampleCorrSelect[chn]==null) || (sampleCorrSelect[chn].length!=getDefaultSampleCorrSelect().length)){
sampleCorrSelect[chn]=getDefaultSampleCorrSelect();
}
for (int i=0;i<sampleCorrSelect[chn].length;i++) if (properties.getProperty(prefix+"sampleCorrSelect_"+chn+"_"+i)!=null){
sampleCorrSelect[chn][i]=Boolean.parseBoolean(properties.getProperty(prefix+"sampleCorrSelect_"+chn+"_"+i));
}
}
*/ if (sampleCorrCost==null){
sampleCorrCost=new double[curvatureModel.length][];
for (int i=0;i<sampleCorrCost.length;i++) sampleCorrCost[i]=null;
}
for (int chn=0;chn<curvatureModel.length;chn++) if (curvatureModel[chn]!=null){
if ((sampleCorrCost[chn]==null) || (sampleCorrCost[chn].length!=getDefaultSampleCorrCost().length)){
sampleCorrCost[chn]=getDefaultSampleCorrCost();
}
for (int i=0;i<sampleCorrCost[chn].length;i++) if (properties.getProperty(prefix+"sampleCorrCost_"+chn+"_"+i)!=null){
sampleCorrCost[chn][i]=Double.parseDouble(properties.getProperty(prefix+"sampleCorrCost_"+chn+"_"+i));
}
}
if (sampleCorrSigma==null){
sampleCorrSigma=new double[curvatureModel.length][];
for (int i=0;i<sampleCorrSigma.length;i++) sampleCorrSigma[i]=null;
}
for (int chn=0;chn<curvatureModel.length;chn++) if (curvatureModel[chn]!=null){
if ((sampleCorrSigma[chn]==null) || (sampleCorrSigma[chn].length!=getDefaultSampleCorrSigma().length)){
sampleCorrSigma[chn]=getDefaultSampleCorrSigma();
}
for (int i=0;i<sampleCorrSigma[chn].length;i++) if (properties.getProperty(prefix+"sampleCorrSigma_"+chn+"_"+i)!=null){
sampleCorrSigma[chn][i]=Double.parseDouble(properties.getProperty(prefix+"sampleCorrSigma_"+chn+"_"+i));
}
}
if (sampleCorrPullZero==null){
sampleCorrPullZero=new double[curvatureModel.length][];
for (int i=0;i<sampleCorrPullZero.length;i++) sampleCorrPullZero[i]=null;
}
for (int chn=0;chn<curvatureModel.length;chn++) if (curvatureModel[chn]!=null){
if ((sampleCorrPullZero[chn]==null) || (sampleCorrPullZero[chn].length!=getDefaultCorrPullZero().length)){
sampleCorrPullZero[chn]=getDefaultCorrPullZero();
}
for (int i=0;i<sampleCorrPullZero[chn].length;i++) if (properties.getProperty(prefix+"sampleCorrPullZero_"+chn+"_"+i)!=null){
sampleCorrPullZero[chn][i]=Double.parseDouble(properties.getProperty(prefix+"sampleCorrPullZero_"+chn+"_"+i));
}
}
// read/restore correction parameters values
if (correctionParameters==null){
correctionParameters=new double[6][][];
for (int i=0;i<correctionParameters.length;i++) correctionParameters[i]=null;
}
if (numberOfLocations>0) {
for (int chn=0;chn<correctionParameters.length; chn++) if (curvatureModel[chn]!=null){
int numPars=curvatureModel[chn].getNumPars()[0]; // number of Z-parameters
if ((correctionParameters[chn]==null) || (correctionParameters[chn].length!=numPars)){
correctionParameters[chn]=new double [numPars][numberOfLocations]; // numberOfLocations==0 ?
for (int np=0;np<numPars;np++) for (int i=0;i<numberOfLocations;i++)
correctionParameters[chn][np][i]=0.0;
}
for (int np=0;np<numPars;np++) for (int i=0;i<numberOfLocations;i++)
if (properties.getProperty(prefix+"correctionParameters_"+chn+"_"+np+"_"+i)!=null) {
correctionParameters[chn][np][i]=Double.parseDouble(properties.getProperty(prefix+"correctionParameters_"+chn+"_"+np+"_"+i));
}
} }
} else {
System.out.println("numberOfLocations==0, can not restore");
}
}
public double [] getSampleRadiuses(){ // distance from the current center to each each sample public double [] getSampleRadiuses(){ // distance from the current center to each each sample
return sampleCorrRadius; return sampleCorrRadius;
...@@ -2311,7 +2558,7 @@ public boolean LevenbergMarquardt(boolean openDialog, int debugLevel){ ...@@ -2311,7 +2558,7 @@ public boolean LevenbergMarquardt(boolean openDialog, int debugLevel){
} }
/** /**
* Calculate values (saggital and tangential PSF FWHM in um for each of color channels) for specified z * Calculate values (sagital and tangential PSF FWHM in um for each of color channels) for specified z
* @param z distance from lens (from some zero point), image plane is perpendicular to the axis * @param z distance from lens (from some zero point), image plane is perpendicular to the axis
* @param corrected when false - provide averaged (axial model) for radius, if true - with individual correction applied * @param corrected when false - provide averaged (axial model) for radius, if true - with individual correction applied
* @param allChannels calculate for all (even disabled) channels, false - only for currently selected * @param allChannels calculate for all (even disabled) channels, false - only for currently selected
...@@ -2485,21 +2732,52 @@ public boolean LevenbergMarquardt(boolean openDialog, int debugLevel){ ...@@ -2485,21 +2732,52 @@ public boolean LevenbergMarquardt(boolean openDialog, int debugLevel){
return pXY; return pXY;
} }
public void setDefaultSampleCorr(){ public void setDefaultSampleCorr(){
int numPars= getNumCurvars()[0]; // number of Z parameters ( [1] - numbnr of radial parameters). // int numPars= getNumCurvars()[0]; // number of Z parameters ( [1] - numbnr of radial parameters).
for (int n=0;n<channelDescriptions.length;n++){ for (int n=0;n<channelDescriptions.length;n++){
sampleCorrSelect[n]=new boolean[numPars]; sampleCorrSelect[n]=getDefaultSampleCorrSelect(); //new boolean[numPars];
sampleCorrCost[n]=new double [numPars]; sampleCorrCost[n]=getDefaultSampleCorrCost(); // new double [numPars];
sampleCorrSigma[n]=new double [numPars]; sampleCorrSigma[n]=getDefaultSampleCorrSigma(); //new double [numPars];
sampleCorrPullZero[n]=new double [numPars]; sampleCorrPullZero[n]=getDefaultCorrPullZero(); //new double [numPars];
for (int i=0;i<numPars;i++){ // for (int i=0;i<numPars;i++){
sampleCorrSelect[n][i]=(i<dflt_sampleCorrSelect.length)?dflt_sampleCorrSelect[i]:false; // sampleCorrSelect[n][i]=(i<dflt_sampleCorrSelect.length)?dflt_sampleCorrSelect[i]:false;
sampleCorrCost[n][i]=(i<dflt_sampleCorrCost.length)?dflt_sampleCorrCost[i]:1.0; // sampleCorrCost[n][i]=(i<dflt_sampleCorrCost.length)?dflt_sampleCorrCost[i]:1.0;
sampleCorrSigma[n][i]=dflt_sampleCorrSigma; // sampleCorrSigma[n][i]=dflt_sampleCorrSigma;
sampleCorrPullZero[n][i]=dflt_sampleCorrPullZero; // sampleCorrPullZero[n][i]=dflt_sampleCorrPullZero;
// }
} }
} }
public boolean [] getDefaultSampleCorrSelect(){
boolean [] dflt=new boolean[getNumCurvars()[0]]; // number of Z parameters ( [1] - numbnr of radial parameters).
for (int i=0;i<dflt.length;i++){
dflt[i]=(i<dflt_sampleCorrSelect.length)?dflt_sampleCorrSelect[i]:false;
} }
/** return dflt;
}
public double [] getDefaultSampleCorrCost(){
double [] dflt=new double[getNumCurvars()[0]]; // number of Z parameters ( [1] - numbnr of radial parameters).
for (int i=0;i<dflt.length;i++){
dflt[i]=(i<dflt_sampleCorrCost.length)?dflt_sampleCorrCost[i]:1.0;
}
return dflt;
}
public double [] getDefaultSampleCorrSigma(){
double [] dflt=new double[getNumCurvars()[0]]; // number of Z parameters ( [1] - numbnr of radial parameters).
for (int i=0;i<dflt.length;i++){
dflt[i]=dflt_sampleCorrSigma;
}
return dflt;
}
public double [] getDefaultCorrPullZero(){
double [] dflt=new double[getNumCurvars()[0]]; // number of Z parameters ( [1] - numbnr of radial parameters).
for (int i=0;i<dflt.length;i++){
dflt[i]=dflt_sampleCorrPullZero;
}
return dflt;
}
/**
* Dialog to setup per-sample (coordinate) corrections * Dialog to setup per-sample (coordinate) corrections
* @param title Dialog title * @param title Dialog title
* @param individualChannels configure each of the six color/dir channels separately (false - apply to all) * @param individualChannels configure each of the six color/dir channels separately (false - apply to all)
...@@ -2567,6 +2845,7 @@ public boolean LevenbergMarquardt(boolean openDialog, int debugLevel){ ...@@ -2567,6 +2845,7 @@ public boolean LevenbergMarquardt(boolean openDialog, int debugLevel){
} }
// once per data set // once per data set
public void resetSampleCorr(){ public void resetSampleCorr(){
if (debugLevel>0) System.out.println("---resetSampleCorr()---");
for (int i=0; i<correctionParameters.length;i++) correctionParameters[i]=null; for (int i=0; i<correctionParameters.length;i++) correctionParameters[i]=null;
} }
...@@ -2582,16 +2861,21 @@ public boolean LevenbergMarquardt(boolean openDialog, int debugLevel){ ...@@ -2582,16 +2861,21 @@ public boolean LevenbergMarquardt(boolean openDialog, int debugLevel){
} }
} }
} }
System.out.println("getCorrVector 1");
sampleCorrVector=new double [numPars]; sampleCorrVector=new double [numPars];
for (int nChn=0; nChn< sampleCorrChnParIndex.length;nChn++) { for (int nChn=0; nChn< sampleCorrChnParIndex.length;nChn++) {
if (sampleCorrChnParIndex[nChn]!=null){ if (sampleCorrChnParIndex[nChn]!=null){
for (int nPar=0;nPar< sampleCorrChnParIndex[nChn].length;nPar++) { for (int nPar=0;nPar< sampleCorrChnParIndex[nChn].length;nPar++) {
if (sampleCorrChnParIndex[nChn][nPar]>=0){ if (sampleCorrChnParIndex[nChn][nPar]>=0){
for (int i=0;i<numberOfLocations;i++){ for (int i=0;i<numberOfLocations;i++){
if ((correctionParameters[nChn]!=null) && (correctionParameters[nChn][nPar]!=null)) if ((correctionParameters[nChn]!=null) && (correctionParameters[nChn][nPar]!=null) && (correctionParameters[nChn][nPar].length>i))
sampleCorrVector[sampleCorrChnParIndex[nChn][nPar]+i]=correctionParameters[nChn][nPar][i]; sampleCorrVector[sampleCorrChnParIndex[nChn][nPar]+i]=correctionParameters[nChn][nPar][i];
else else {
sampleCorrVector[sampleCorrChnParIndex[nChn][nPar]+i]=0.0; sampleCorrVector[sampleCorrChnParIndex[nChn][nPar]+i]=0.0;
if ((correctionParameters[nChn]!=null) && (correctionParameters[nChn][nPar]!=null) && (correctionParameters[nChn][nPar].length<i)){
System.out.println("correctionParameters["+nChn+"]["+nPar+"].length < "+i);
}
}
} }
} }
} }
...@@ -2601,6 +2885,7 @@ public boolean LevenbergMarquardt(boolean openDialog, int debugLevel){ ...@@ -2601,6 +2885,7 @@ public boolean LevenbergMarquardt(boolean openDialog, int debugLevel){
} }
public void commitCorrVector(){ public void commitCorrVector(){
System.out.println("commitCorrVector()");
commitCorrVector(sampleCorrVector); commitCorrVector(sampleCorrVector);
} }
...@@ -2611,8 +2896,11 @@ public boolean LevenbergMarquardt(boolean openDialog, int debugLevel){ ...@@ -2611,8 +2896,11 @@ public boolean LevenbergMarquardt(boolean openDialog, int debugLevel){
if (sampleCorrChnParIndex[nChn][nPar]>=0){ if (sampleCorrChnParIndex[nChn][nPar]>=0){
if(correctionParameters[nChn]==null) if(correctionParameters[nChn]==null)
correctionParameters[nChn]=new double [sampleCorrChnParIndex[nChn].length][]; correctionParameters[nChn]=new double [sampleCorrChnParIndex[nChn].length][];
if(correctionParameters[nChn][nPar]==null) if ((correctionParameters[nChn][nPar]==null) || (correctionParameters[nChn][nPar].length!=numberOfLocations)){
System.out.println("commitCorrVector(): correctionParameters["+nChn+"]["+nPar+"].length < "+numberOfLocations);
correctionParameters[nChn][nPar]=new double [numberOfLocations]; correctionParameters[nChn][nPar]=new double [numberOfLocations];
}
for (int i=0;i<numberOfLocations;i++){ for (int i=0;i<numberOfLocations;i++){
correctionParameters[nChn][nPar][i]=vector[sampleCorrChnParIndex[nChn][nPar]+i]; correctionParameters[nChn][nPar][i]=vector[sampleCorrChnParIndex[nChn][nPar]+i];
} }
...@@ -2687,6 +2975,8 @@ public boolean LevenbergMarquardt(boolean openDialog, int debugLevel){ ...@@ -2687,6 +2975,8 @@ public boolean LevenbergMarquardt(boolean openDialog, int debugLevel){
} }
// currently all correction parameters are initialized as zeros. // currently all correction parameters are initialized as zeros.
getCorrVector(); getCorrVector();
System.out.println("was resetting sampleCorrVector here");
// sampleCorrVector=new double [numPars]; // sampleCorrVector=new double [numPars];
// for (int i=0;i<numPars;i++)sampleCorrVector[i]=0.0; // for (int i=0;i<numPars;i++)sampleCorrVector[i]=0.0;
sampleCorrRadius=new double [numberOfLocations]; sampleCorrRadius=new double [numberOfLocations];
...@@ -2706,10 +2996,15 @@ public boolean LevenbergMarquardt(boolean openDialog, int debugLevel){ ...@@ -2706,10 +2996,15 @@ public boolean LevenbergMarquardt(boolean openDialog, int debugLevel){
else corr[i]=sampleCorrVector[sampleCorrChnParIndex[chn][i]+sampleIndex]; else corr[i]=sampleCorrVector[sampleCorrChnParIndex[chn][i]+sampleIndex];
} }
*/ */
// System.out.println("used sampleCorrVector here, now correctionParameters");
if (correctionParameters[chn]==null) return null; if (correctionParameters[chn]==null) return null;
double [] corr =new double [correctionParameters[chn].length]; double [] corr =new double [correctionParameters[chn].length];
for (int i=0;i<corr.length;i++){ for (int i=0;i<corr.length;i++){
if (correctionParameters[chn][i] !=null) corr[i]=correctionParameters[chn][i][sampleIndex]; if ((correctionParameters[chn][i] !=null) && (correctionParameters[chn][i].length<=i)){
System.out.println("getCorrPar(): correctionParameters["+chn+"]["+i+"].length="+correctionParameters[chn][i].length);
}
if ((correctionParameters[chn][i] !=null) && (correctionParameters[chn][i].length>i)) corr[i]=correctionParameters[chn][i][sampleIndex];
else corr[i]=0.0; else corr[i]=0.0;
} }
...@@ -2905,15 +3200,21 @@ public boolean LevenbergMarquardt(boolean openDialog, int debugLevel){ ...@@ -2905,15 +3200,21 @@ public boolean LevenbergMarquardt(boolean openDialog, int debugLevel){
index++; index++;
} }
} }
if (showCorrection && (getNumberOfCorrParameters()>0)){ // if (showCorrection && (getNumberOfCorrParameters()>0)){
if (showCorrection){
parList.add("\t ===== Per-sample correction parameters =====\t\t"); parList.add("\t ===== Per-sample correction parameters =====\t\t");
for (int n=0;n<correctionParameters.length;n++) if (correctionParameters[n]!=null){ for (int n=0;n<correctionParameters.length;n++) if (correctionParameters[n]!=null){
for (int np=0;np<correctionParameters[n].length;np++) if (correctionParameters[n][np]!=null){ for (int np=0;np<correctionParameters[n].length;np++)
// int numSamples=sampleCorrCrossWeights[n][np].length; if ((correctionParameters[n][np]!=null) && (correctionParameters[n][np].length==numberOfLocations)){
// int numSamples=sampleCorrCrossWeights[n][np].length;
parList.add("\t ----- correction parameters for \""+ getDescription(n)+" "+curvatureModel[n].getZDescription(np)+"\" -----\t\t"); parList.add("\t ----- correction parameters for \""+ getDescription(n)+" "+curvatureModel[n].getZDescription(np)+"\" -----\t\t");
for (int i=0;i<numberOfLocations;i++){ for (int i=0;i<numberOfLocations;i++){
parList.add(i+"\t"+curvatureModel[n].getZDescription(np)+":\t"+correctionParameters[n][np][i]+"\t"); parList.add(i+"\t"+curvatureModel[n].getZDescription(np)+":\t"+correctionParameters[n][np][i]+"\t");
} }
} else {
if ((correctionParameters[n][np]!=null) && (correctionParameters[n][np].length!=numberOfLocations)){
System.out.println("getParameterValueStrings(): correctionParameters["+n+"]["+np+"].length="+correctionParameters[n][np].length);
}
} }
} }
} }
...@@ -3056,6 +3357,8 @@ public boolean LevenbergMarquardt(boolean openDialog, int debugLevel){ ...@@ -3056,6 +3357,8 @@ public boolean LevenbergMarquardt(boolean openDialog, int debugLevel){
index++; index++;
} }
} }
System.out.println("createParameterVector(): using sampleCorrVector - do we need to create it first?");
getCorrVector(); // do we need that?
int nCorrPars=getNumberOfCorrParameters(); int nCorrPars=getNumberOfCorrParameters();
for (int i=0;i<nCorrPars;i++) pars[np++]=sampleCorrVector[i]; for (int i=0;i<nCorrPars;i++) pars[np++]=sampleCorrVector[i];
return pars; return pars;
...@@ -3084,6 +3387,7 @@ public boolean LevenbergMarquardt(boolean openDialog, int debugLevel){ ...@@ -3084,6 +3387,7 @@ public boolean LevenbergMarquardt(boolean openDialog, int debugLevel){
} }
} }
// copy correction parameters // copy correction parameters
System.out.println("commitParameterVector(): Creating and committing sampleCorrVector");
int nCorrPars=getNumberOfCorrParameters(); int nCorrPars=getNumberOfCorrParameters();
for (int i=0;i<nCorrPars;i++) sampleCorrVector[i]=pars[np++]; for (int i=0;i<nCorrPars;i++) sampleCorrVector[i]=pars[np++];
commitCorrVector(); commitCorrVector();
......
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