MCPcopy Create free account
hub / github.com/AstroImageJ/astroimagej / doFit

Method doFit

ij/src/main/java/ij/plugin/frame/Fitter.java:84–123  ·  view source on GitHub ↗

Fit data in the textArea, show result in log and create plot. @param fitType as defined in CurveFitter constants @return false on error.

(int fitType)

Source from the content-addressed store, hash-verified

82 * @return false on error.
83 */
84 public boolean doFit(int fitType) {
85 if (!getData()) {
86 IJ.beep();
87 return false;
88 }
89 cf = new CurveFitter(x, y);
90 cf.setStatusAndEsc("Optimization: Iteration ", true);
91 try {
92 if (fitType==USER_DEFINED) {
93 String eqn = getEquation();
94 if (eqn==null) return false;
95 int params = cf.doCustomFit(eqn, null, settings.getState());
96 if (params==0) {
97 IJ.beep();
98 IJ.log("Bad formula; should be:\n y = function(x, a, ...)");
99 return false;
100 }
101 } else
102 cf.doFit(fitType, settings.getState());
103 if (cf.getStatus() == Minimizer.INITIALIZATION_FAILURE) {
104 IJ.beep();
105 IJ.showStatus(cf.getStatusString());
106 IJ.log("Curve Fitting Error:\n"+cf.getStatusString());
107 return false;
108 }
109 if (Double.isNaN(cf.getSumResidualsSqr())) {
110 IJ.beep();
111 IJ.showStatus("Error: fit yields Not-a-Number");
112 return false;
113 }
114
115 } catch (Exception e) {
116 IJ.handleException(e);
117 return false;
118 }
119 IJ.log(cf.getResultString());
120 plot(cf);
121 this.fitType = fitType;
122 return true;
123 }
124
125 String getEquation() {
126 GenericDialog gd = new GenericDialog("Formula");

Callers 1

runMethod · 0.95

Calls 14

getDataMethod · 0.95
beepMethod · 0.95
getEquationMethod · 0.95
logMethod · 0.95
showStatusMethod · 0.95
handleExceptionMethod · 0.95
plotMethod · 0.95
doCustomFitMethod · 0.80
getStatusMethod · 0.80
getStatusStringMethod · 0.80
getSumResidualsSqrMethod · 0.80
setStatusAndEscMethod · 0.45

Tested by

no test coverage detected