Commit 0a57888e authored by Andrey Filippov's avatar Andrey Filippov
Browse files

preparing for LMA just after scanning

parent cec2fe59
Loading
Loading
Loading
Loading
+15 −9
Original line number Original line Diff line number Diff line
@@ -4079,12 +4079,25 @@ if (MORE_BUTTONS) {
					pY0,
					pY0,
					sampleCoord,
					sampleCoord,
					this.SYNC_COMMAND.stopRequested);
					this.SYNC_COMMAND.stopRequested);
			FOCUSING_FIELD.setDebugLevel(DEBUG_LEVEL);
			FOCUSING_FIELD.setAdjustMode(false);
			if (PROPERTIES!=null) FOCUSING_FIELD.getProperties("FOCUSING_FIELD.", PROPERTIES);
			if (PROPERTIES!=null) FOCUSING_FIELD.getProperties("FOCUSING_FIELD.", PROPERTIES);
			System.out.println("Saving measurement history to "+path);
			MOTORS.addCurrentHistoryToFocusingField(FOCUSING_FIELD);
			MOTORS.addCurrentHistoryToFocusingField(FOCUSING_FIELD);
			System.out.println("Saving measurement history to "+path);
			FOCUSING_FIELD.saveXML(path);
			FOCUSING_FIELD.saveXML(path);
			
			saveCurrentConfig();
			saveCurrentConfig();
// for now just copying from "Restore History". TODO: Make both more automatic (move number of parameters outside?)			
			if (!FOCUSING_FIELD.configureDataVector("Configure curvature - TODO: fix many settings restored from properties",true,true)) return;
			System.out.println("TODO: fix many settings restored from properties, overwriting entered fields. Currently run \"Modify LMA\" to re-enter values");
			System.out.println("TODO: Probably need to make a separate dialog that enters number of parameters.");
	    	double [] sv=          FOCUSING_FIELD.fieldFitting.createParameterVector(FOCUSING_FIELD.sagittalMaster);
			FOCUSING_FIELD.setDataVector(
					true, // calibrate mode
					FOCUSING_FIELD.createDataVector());
			double [] focusing_fx= FOCUSING_FIELD.createFXandJacobian(sv, false);
			double rms=            FOCUSING_FIELD.calcErrorDiffY(focusing_fx, false);
			double rms_pure=       FOCUSING_FIELD.calcErrorDiffY(focusing_fx, true);
			System.out.println("rms="+rms+", rms_pure="+rms_pure+" - with old parameters may be well off.");
			return;
			return;
		}
		}
		
		
@@ -4408,13 +4421,6 @@ if (MORE_BUTTONS) {
			if (!FOCUSING_FIELD.configureDataVector("Configure curvature - TODO: fix many settings restored from properties",true,true)) return;
			if (!FOCUSING_FIELD.configureDataVector("Configure curvature - TODO: fix many settings restored from properties",true,true)) return;
			System.out.println("TODO: fix many settings restored from properties, overwriting entered fields. Currently run \"Modify LMA\" to re-enter values");
			System.out.println("TODO: fix many settings restored from properties, overwriting entered fields. Currently run \"Modify LMA\" to re-enter values");
			System.out.println("TODO: Probably need to make a separate dialog that enters number of parameters.");
			System.out.println("TODO: Probably need to make a separate dialog that enters number of parameters.");
			///			FOCUSING_FIELD.fieldFitting.initSampleCorrChnParIndex(FOCUSING_FIELD.flattenSampleCoord()); //+
///			FOCUSING_FIELD.setDataVector(
///					true, // calibrate mode
///					FOCUSING_FIELD.createDataVector());
//			FOCUSING_FIELD.fieldFitting.initSampleCorrVector( //+
//					FOCUSING_FIELD.flattenSampleCoord(), //double [][] sampleCoordinates,
//					FOCUSING_FIELD.getSeriesWeights()); //double [][] sampleSeriesWeights);
	    	double [] sv=          FOCUSING_FIELD.fieldFitting.createParameterVector(FOCUSING_FIELD.sagittalMaster);
	    	double [] sv=          FOCUSING_FIELD.fieldFitting.createParameterVector(FOCUSING_FIELD.sagittalMaster);
			FOCUSING_FIELD.setDataVector(
			FOCUSING_FIELD.setDataVector(
					true, // calibrate mode
					true, // calibrate mode
+34 −5
Original line number Original line Diff line number Diff line
@@ -4472,6 +4472,7 @@ public boolean LevenbergMarquardt(
            double tMax,
            double tMax,
            double tStep
            double tStep
            ){
            ){
		debugDerivativesFxDxDy=false;
    	int retryLimit=20;
    	int retryLimit=20;
    	fieldFitting.mechanicalFocusingModel.setAdjustMode(true);
    	fieldFitting.mechanicalFocusingModel.setAdjustMode(true);
    	setDataVector(
    	setDataVector(
@@ -5635,9 +5636,6 @@ public boolean LevenbergMarquardt(
        }
        }
        public boolean maskSetDialog(
        public boolean maskSetDialog(
        		String title//,
        		String title//,
//         		String strategyComment,
//        		double lambda,
//        		boolean lastInSeries
        		){
        		){
        	GenericDialog gd = new GenericDialog(title);
        	GenericDialog gd = new GenericDialog(title);
        	boolean editMechMask=false;
        	boolean editMechMask=false;
@@ -5647,6 +5645,7 @@ public boolean LevenbergMarquardt(
        	boolean setupCorrectionPars=false;
        	boolean setupCorrectionPars=false;
        	boolean commonCorrectionPars=true;
        	boolean commonCorrectionPars=true;
        	boolean disabledCorrectionPars=false;
        	boolean disabledCorrectionPars=false;
            gd.addCheckbox("Only use measurements acquired during parallel moves (false - use all)",parallelOnly); //parallelOnly - parent class 
        	if (centerSelect==null) centerSelect=centerSelectDefault.clone();
        	if (centerSelect==null) centerSelect=centerSelectDefault.clone();
        	gd.addCheckbox("Adjust aberration center (pX0)", centerSelect[0]);
        	gd.addCheckbox("Adjust aberration center (pX0)", centerSelect[0]);
        	gd.addCheckbox("Adjust aberration center (pY0)", centerSelect[1]);
        	gd.addCheckbox("Adjust aberration center (pY0)", centerSelect[1]);
@@ -5674,6 +5673,7 @@ public boolean LevenbergMarquardt(
        	//         gd.enableYesNoCancel("Keep","Apply"); // default OK (on enter) - "Keep"
        	//         gd.enableYesNoCancel("Keep","Apply"); // default OK (on enter) - "Keep"
        	gd.showDialog();
        	gd.showDialog();
        	if (gd.wasCanceled()) return false;
        	if (gd.wasCanceled()) return false;
        	parallelOnly=gd.getNextBoolean();
        	centerSelect[0]=gd.getNextBoolean();
        	centerSelect[0]=gd.getNextBoolean();
        	centerSelect[1]=gd.getNextBoolean();
        	centerSelect[1]=gd.getNextBoolean();
        	for (int i=0;i<channelSelect.length;i++) {
        	for (int i=0;i<channelSelect.length;i++) {
@@ -7290,6 +7290,7 @@ f_corr: d_fcorr/d_zcorr=0, other: a, reff, kx -> ar[1], ar[2], ar[3], ar[4]
    		this.lastInSeries=fs.isStopAfterThis(strategyIndex);
    		this.lastInSeries=fs.isStopAfterThis(strategyIndex);
    		this.keepCorrectionParameters=!fs.isResetCorrection(strategyIndex);
    		this.keepCorrectionParameters=!fs.isResetCorrection(strategyIndex);
    		this.resetCenter=fs.isResetCenter(strategyIndex);
    		this.resetCenter=fs.isResetCenter(strategyIndex);
    		this.parallelOnly=fs.isParallelOnly(strategyIndex);
    		return true;
    		return true;
    	} else return false;
    	} else return false;
    }
    }
@@ -7365,6 +7366,7 @@ f_corr: d_fcorr/d_zcorr=0, other: a, reff, kx -> ar[1], ar[2], ar[3], ar[4]
        		fs.setStopAfterThis(selectedStrategyIndex,this.lastInSeries);
        		fs.setStopAfterThis(selectedStrategyIndex,this.lastInSeries);
        		fs.setResetCorrection(selectedStrategyIndex,!this.keepCorrectionParameters);
        		fs.setResetCorrection(selectedStrategyIndex,!this.keepCorrectionParameters);
        		fs.setResetCenter(selectedStrategyIndex,this.resetCenter);
        		fs.setResetCenter(selectedStrategyIndex,this.resetCenter);
        		fs.setParallelOnly(selectedStrategyIndex,this.parallelOnly);
        		break;
        		break;
        	case 4:
        	case 4:
        		fs.removeStrategy(selectedStrategyIndex);
        		fs.removeStrategy(selectedStrategyIndex);
@@ -7383,6 +7385,7 @@ f_corr: d_fcorr/d_zcorr=0, other: a, reff, kx -> ar[1], ar[2], ar[3], ar[4]
        		fs.setStopAfterThis(selectedStrategyIndex,this.lastInSeries);
        		fs.setStopAfterThis(selectedStrategyIndex,this.lastInSeries);
        		fs.setResetCorrection(selectedStrategyIndex,!this.keepCorrectionParameters);
        		fs.setResetCorrection(selectedStrategyIndex,!this.keepCorrectionParameters);
        		fs.setResetCenter(selectedStrategyIndex,this.resetCenter);
        		fs.setResetCenter(selectedStrategyIndex,this.resetCenter);
        		fs.setParallelOnly(selectedStrategyIndex,this.parallelOnly);
        		break;
        		break;
        	}
        	}
        	
        	
@@ -7481,6 +7484,11 @@ f_corr: d_fcorr/d_zcorr=0, other: a, reff, kx -> ar[1], ar[2], ar[3], ar[4]
			return strategies.get(strategyIndex).isResetCenter();
			return strategies.get(strategyIndex).isResetCenter();
		}
		}


		public boolean isParallelOnly(
				int strategyIndex) {
			return strategies.get(strategyIndex).isParallelOnly();
		}
		
		public boolean isLast(
		public boolean isLast(
				int strategyIndex) {
				int strategyIndex) {
			if (strategyIndex < 0) return true;
			if (strategyIndex < 0) return true;
@@ -7503,6 +7511,13 @@ f_corr: d_fcorr/d_zcorr=0, other: a, reff, kx -> ar[1], ar[2], ar[3], ar[4]
				boolean resetCenter) {
				boolean resetCenter) {
			strategies.get(strategyIndex).setResetCenter(resetCenter);
			strategies.get(strategyIndex).setResetCenter(resetCenter);
		}
		}

		public void setParallelOnly(
				int strategyIndex,
				boolean parallelOnly) {
			strategies.get(strategyIndex).setParallelOnly(parallelOnly);
		}

		public String getComment(
		public String getComment(
				int strategyIndex){
				int strategyIndex){
			return strategies.get(strategyIndex).getComment();
			return strategies.get(strategyIndex).getComment();
@@ -7623,6 +7638,7 @@ f_corr: d_fcorr/d_zcorr=0, other: a, reff, kx -> ar[1], ar[2], ar[3], ar[4]
			private boolean stopAfterThis=true;
			private boolean stopAfterThis=true;
			private boolean resetCorrection=false;
			private boolean resetCorrection=false;
			private boolean resetCenter=false;
			private boolean resetCenter=false;
			private boolean parallelOnly=true;
			private String strategyComment="";
			private String strategyComment="";
			private Properties properties=null;
			private Properties properties=null;
			private String prefix=null;
			private String prefix=null;
@@ -7634,13 +7650,15 @@ f_corr: d_fcorr/d_zcorr=0, other: a, reff, kx -> ar[1], ar[2], ar[3], ar[4]
					double lambda,
					double lambda,
					boolean lastInSeries,
					boolean lastInSeries,
					boolean resetCorrection,
					boolean resetCorrection,
					boolean resetCenter
					boolean resetCenter,
					boolean parallelOnly
					){
					){
				this.strategyComment=strategyComment;
				this.strategyComment=strategyComment;
				initialLambda=lambda;
				initialLambda=lambda;
				stopAfterThis=lastInSeries;
				stopAfterThis=lastInSeries;
				this.resetCorrection=resetCorrection;
				this.resetCorrection=resetCorrection;
				this.resetCenter=resetCenter;
				this.resetCenter=resetCenter;
				this.parallelOnly=parallelOnly;
				setDefaults();
				setDefaults();
			}
			}
			private void setDefaults(){
			private void setDefaults(){
@@ -7769,10 +7787,18 @@ f_corr: d_fcorr/d_zcorr=0, other: a, reff, kx -> ar[1], ar[2], ar[3], ar[4]
			public boolean isResetCenter() {
			public boolean isResetCenter() {
				return resetCenter;
				return resetCenter;
			}
			}
			
			public void setResetCenter(boolean resetCenter) {
			public void setResetCenter(boolean resetCenter) {
				this.resetCenter = resetCenter;
				this.resetCenter = resetCenter;
			}
			}


			public boolean isParallelOnly() {
				return parallelOnly;
			}
			public void setParallelOnly(boolean parallelOnly) {
				this.parallelOnly = parallelOnly;
			}

			public void setStrategy( // any of the arguments can be null - do not set this array
			public void setStrategy( // any of the arguments can be null - do not set this array
            		boolean [] centerSelect,
            		boolean [] centerSelect,
                	boolean [] channelSelect,
                	boolean [] channelSelect,
@@ -7851,6 +7877,7 @@ f_corr: d_fcorr/d_zcorr=0, other: a, reff, kx -> ar[1], ar[2], ar[3], ar[4]
				properties.setProperty(prefix+"stopAfterThis",isStopAfterThis()+"");
				properties.setProperty(prefix+"stopAfterThis",isStopAfterThis()+"");
				properties.setProperty(prefix+"resetCorrection",isResetCorrection()+"");
				properties.setProperty(prefix+"resetCorrection",isResetCorrection()+"");
				properties.setProperty(prefix+"resetCenter",isResetCenter()+"");
				properties.setProperty(prefix+"resetCenter",isResetCenter()+"");
				properties.setProperty(prefix+"parallelOnly",isParallelOnly()+"");
				properties.setProperty(prefix+"strategyComment","<![CDATA["+strategyComment+ "]]>");
				properties.setProperty(prefix+"strategyComment","<![CDATA["+strategyComment+ "]]>");
            }
            }
            public void getProperties(String prefix,Properties properties){
            public void getProperties(String prefix,Properties properties){
@@ -7872,6 +7899,8 @@ f_corr: d_fcorr/d_zcorr=0, other: a, reff, kx -> ar[1], ar[2], ar[3], ar[4]
            	if (s!=null) resetCorrection=Boolean.parseBoolean(s);
            	if (s!=null) resetCorrection=Boolean.parseBoolean(s);
            	s=properties.getProperty(prefix+"resetCenter");
            	s=properties.getProperty(prefix+"resetCenter");
            	if (s!=null) resetCenter=Boolean.parseBoolean(s);
            	if (s!=null) resetCenter=Boolean.parseBoolean(s);
            	s=properties.getProperty(prefix+"parallelOnly");
            	if (s!=null) parallelOnly=Boolean.parseBoolean(s);
            	s=properties.getProperty(prefix+"strategyComment");
            	s=properties.getProperty(prefix+"strategyComment");
            	if (s!=null){
            	if (s!=null){
            		strategyComment=s;
            		strategyComment=s;