I'm trying to fit a 2-d voigt profile to a subsection of an image (impart), where position is an array that holds the corresponding x and y coordinates in the whole image for impart.
The following code seems to me like it really ought to work, based on the output of the two print statements.
Also, if anyone has any quick suggestions on how to construct the position array faster, I'd appreciate some advice with numpy ndarrays. I'm still a little new to them.
import numpy as np from scipy.special import wofz from scipy.optimize import curve_fit from math import pi def voigt2d(pos,a,bx,by,Gc,Lc): val = np.zeros((5,5)) for y in range(5): for x in range(5): dst = np.sqrt((pos[y][x][0]-bx)**2+(pos[y][x][1]-by)**2) z = ((dst+(Lc*1j))/(Gc*np.sqrt(2))) val[y][x] = a*wofz(z).real/(Gc*np.sqrt(2*pi)) print val print val.dtype return val x = np.arange(93,98) y = np.arange(7,12) xpos = np.array([x,x,x,x,x]) ypos = np.array([y,y,y,y,y]) ypos = np.rot90(ypos,k=3) position = np.dstack((xpos,ypos)) impart = np.array([ [971, 2425, 4331, 4280, 2697,], [1199, 3416, 6517, 4813, 2412], [1333, 3957, 7210, 4019, 2183], [1494, 4115, 4817, 3085, 1758], [1185, 2273, 2805, 2811, 1797] ],dtype=np.float64) p,cov = curve_fit(voigt2d,position,impart)