gaussian - How do I fit my data to an Airy Function in python? -


my code takes image of pinhole aperture , fits data gaussian. using gaussian fit calculates full-width @ half maximum. tells me resolution of imaging system.

here fit code right now:

fit code

according theory pinhole diffraction images, data should correspond airy disk function. completeness want fit data bessel function or airy disk pattern. cannot find packages fit these functions.

here picture using:

picture using

you can just make out outer fringes around central bright spot. fringes want account in fit.

import numpy np import scipy.optimize opt import pil pil import imagefilter pylab import *  #defining gaussian def gauss(x, p): # p[0]==mean, p[1]==stdev     return 1.0/(p[1]*np.sqrt(2*np.pi))*np.exp(-(x-p[0])**2/(2*p[1]**2))  im = pil.image.open('c:/documents/user/3000.bmp').convert("l")  #convert array imarr = np.array(im, dtype=float) bg = np.average(imarr)  #find background, subtract imarr = imarr - bg  #get approx coordinates of brightest spot filtering im2 = im.filter(imagefilter.gaussianblur(radius=2)) imarr2 = np.array(im2, dtype=float) tuple = unravel_index(imarr2.argmax(), imarr2.shape)  #find , plot fwhm brightest spot x = np.arange(tuple[1] - 100, tuple[1] + 100, dtype=np.float) y = imarr[tuple[0], tuple[1] - 100:tuple[1] + 100]  y /= ((max(x) - min(x)) / len(x)) * np.sum(y) # renormalize proper gaussian  p0 = [tuple[1], tuple[0]] errfunc = lambda p, x, y: gauss(x, p) - y # distance target function p1, success = opt.leastsq(errfunc, p0[:], args=(x, y))  fit_mu, fit_stdev = p1  fwhm = 2*np.sqrt(2*np.log(2))*fit_stdev print "fwhm", fwhm  plt.plot(x,y) plt.plot(x, gauss(x,p1), lw=3, alpha=.5, color='r') plt.axvspan(fit_mu-fwhm/2, fit_mu+fwhm/2, facecolor='g', alpha=0.5) plt.show() 


Comments