examples/flopping_f_simulation: use numpy array in scipy curve_fit

Python lists cause problems with certain Scipy versions
This commit is contained in:
Sebastien Bourdeauducq 2015-01-31 16:56:38 +08:00
parent 3a2bd02efd
commit 47f1e3d7be
1 changed files with 8 additions and 1 deletions

View File

@ -16,6 +16,13 @@ def model(x, F0):
return A+(B-A)/2/(4*tpi**2*(x-F0)**2+1)*(1-cos(pi*t/tpi*sqrt(4*tpi**2*(x-F0)**2+1)))
def model_numpy(xdata, F0):
r = np.zeros(len(xdata))
for i, x in enumerate(xdata):
r[i] = model(x, F0)
return r
class FloppingF(AutoDB):
class DBKeys:
implicit_core = False
@ -48,7 +55,7 @@ class FloppingF(AutoDB):
self.analyze()
def analyze(self):
popt, pcov = curve_fit(lambda xdata, F0: [model(x, F0) for x in xdata],
popt, pcov = curve_fit(model_numpy,
self.frequency.read, self.brightness.read,
p0=[self.flopping_freq])
perr = np.sqrt(np.diag(pcov))