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

Method fitCurve

ij/src/main/java/ij/macro/Functions.java:6124–6180  ·  view source on GitHub ↗
(boolean withWeights)

Source from the content-addressed store, hash-verified

6122 }
6123
6124 double fitCurve(boolean withWeights) {
6125 interp.getLeftParen();
6126 int fit = -1;
6127 String name = null;
6128 double[] initialValues = null;
6129 if (isStringArg()) {
6130 name = getString();
6131 if (!name.contains("Math."))
6132 name = name.toLowerCase(Locale.US);
6133 String[] list = CurveFitter.fitList;
6134 for (int i=0; i<list.length; i++) {
6135 if (name.equals(list[i].toLowerCase(Locale.US))) {
6136 fit = i;
6137 break;
6138 }
6139 }
6140 boolean isCustom = name.indexOf("y=")!=-1 || name.indexOf("y =")!=-1;
6141 if (fit==-1&&!isCustom)
6142 interp.error("Unrecognized fit");
6143 } else
6144 fit = (int)interp.getExpression();
6145 double[] x = getNextArray();
6146 interp.getComma();
6147 double[] y = getNumericArray();
6148 double[] weights = null;
6149 if (withWeights) {
6150 interp.getComma();
6151 weights = getNumericArray();
6152 }
6153 if (interp.nextToken()==',') {
6154 interp.getComma();
6155 initialValues = getNumericArray();
6156 }
6157 interp.getRightParen();
6158 if (x.length!=y.length)
6159 interp.error("Arrays not same length");
6160 if (x.length==0)
6161 interp.error("Zero length array");
6162 fitter = new CurveFitter(x, y);
6163 if (withWeights)
6164 fitter.setWeights(weights);
6165 fitter.setStatusAndEsc(null, true);
6166 if (fit==-1 && name!=null) {
6167 Interpreter instance = Interpreter.getInstance();
6168 int params = fitter.doCustomFit(name, initialValues, showFitDialog);
6169 Interpreter.instance = instance;
6170 if (params==0)
6171 interp.error("Invalid custom function");
6172 } else
6173 fitter.doFit(fit, showFitDialog);
6174 if (logFitResults) {
6175 IJ.log(fitter.getResultString());
6176 logFitResults = false;
6177 }
6178 showFitDialog = false;
6179 return Double.NaN;
6180 }
6181

Callers 1

fitMethod · 0.95

Calls 15

isStringArgMethod · 0.95
getStringMethod · 0.95
getNextArrayMethod · 0.95
getNumericArrayMethod · 0.95
getInstanceMethod · 0.95
logMethod · 0.95
getLeftParenMethod · 0.80
getExpressionMethod · 0.80
getCommaMethod · 0.80
getRightParenMethod · 0.80
setWeightsMethod · 0.80
doCustomFitMethod · 0.80

Tested by

no test coverage detected