Example #1
0
jya = jarray.array(ya, 'd')

# construct a CurveFitter instance
cf = CurveFitter(jxa, jya)

# actual fitting
# fit models:
# see http://rsb.info.nih.gov/ij/developer/api/constant-values.html#ij.measure.CurveFitter.STRAIGHT_LINE
cf.doFit(CurveFitter.STRAIGHT_LINE)

#print out fitted parameters.
print(cf.getParams()[0], cf.getParams()[1])

print(cf.getFormula())

plt = cf.getPlot()
plt.draw()

left = 0
right = 5
bottom = 0
top = 5
nPoints = 4
rng = right - left

# Create filled plot
plt = Plot("Line plot", "X", "Y")
plt.setLimits(left, right, bottom, top)
plt.setFrameSize(600, 300)
plt.setColor("blue", "#ccccff")
# the circles are small. Can't figure out how to make
        # stack the scan correction measurements in one list to later
        # fit a single scan correction for all beams.
        # (even though a correction for each of the 61 beams is probably needed)
        x_to_fit = x_to_fit + [a[0] for a in spshifts]
        y_to_fit = y_to_fit + [8 - a[1] for a in spshifts]

        cv = CurveFitter([a[0] for a in spshifts],
                         [8 - a[1] for a in spshifts])

        # fit the distortion measurements
        cv.doFit(CurveFitter.EXP_WITH_OFFSET)
        # cv.doFit(CurveFitter.EXPONENTIAL)
        # cv.doFit(CurveFitter.POLY2)
        # cv.doFit(CurveFitter.POLY3)

        plot = cv.getPlot()
        plot.show()
        8 / 0
        plot_images.append(plot.getImagePlus())
        IJ.log('sFOV ' + str(sFOV))
        IJ.log('fitGoodness ' + str(cv.getFitGoodness()))
        IJ.log('formula ' + str(cv.getFormula()))
        fit_params = cv.getParams()
        IJ.log('fit_params' + str(fit_params))

        # write the fit results to file
        g.write('sFOV\t' + str(sFOV) + '\t' + 'a\t' + str(fit_params[0]) +
                '\t' + 'b\t' + str(fit_params[1]) + '\t' + 'c\t' +
                str(fit_params[2]) + '\t' + 'formula\t' +
                str(cv.getFormula()) + '\t' + 'fitGoodness\t' +
                str(cv.getFitGoodness()) + '\n')