Commit b869c4f31d547466607b3f761d0f9f3d7e66742c
1 parent
c437a22764
Exists in
master
more explicit display of results
Showing 1 changed file with 10 additions and 3 deletions Side-by-side Diff
fit_waist.py
... | ... | @@ -26,7 +26,11 @@ |
26 | 26 | |
27 | 27 | '''optimization with non-linear least squares method''' |
28 | 28 | Ppopt, Pcov = curve_fit(P, xmes, Pmes, method = 'trf') |
29 | - data_waist.append([int(f.split('-')[-1].split('.')[0]), Ppopt[3]]) | |
29 | + z = int(f.split('-')[-1].split('.')[0]) | |
30 | + w = Ppopt[3] | |
31 | + w_sig = numpy.sqrt(numpy.diag(Pcov))[3] | |
32 | + data_waist.append([z, w, w_sig]) | |
33 | + print('z = %.3f mm\t w = %.3f mm (+-%.3f mm)'%(z, w, 1.96*w_sig)) | |
30 | 34 | |
31 | 35 | '''plot''' |
32 | 36 | p[0].plot(xmes, Pmes, 'o') |
33 | 37 | |
... | ... | @@ -36,14 +40,17 @@ |
36 | 40 | |
37 | 41 | '''return waist(z) table''' |
38 | 42 | data_waist = numpy.asarray(data_waist, dtype = float) |
39 | -print(data_waist) | |
40 | 43 | |
41 | 44 | '''waist function to optimize''' |
42 | 45 | def W(z, w0, z0): |
43 | 46 | return w0*(1.+((z-z0)*1542e-6/(numpy.pi*w0**2))**2)**0.5 |
44 | 47 | |
45 | 48 | popt, cov = curve_fit(W, data_waist[:,0], data_waist[:,1]) |
46 | -print(popt[0], popt[1]) | |
49 | +w0 = popt[0] | |
50 | +w0_sig = numpy.sqrt(numpy.diag(cov))[0] | |
51 | +z0 = popt[1] | |
52 | +z0_sig = numpy.sqrt(numpy.diag(cov))[1] | |
53 | +print('\nz0 = %.3f mm (+-%.3f mm)\t w0 = %.3f mm (+-%.3f mm)'%(z0, 1.96*z0_sig, w0, 1.96*w0_sig)) | |
47 | 54 | |
48 | 55 | p[1].plot(data_waist[:,0], data_waist[:,1], 'bo') |
49 | 56 | p[1].plot(data_waist[:,0], -data_waist[:,1], 'bo') |