def test_table(): x = array([1., 2., 3.]) y = array([ufloat(2, 0.1), ufloat(4, 0.5), ufloat(2, 0.04)]) f = open('test.tex', 'w') f.write(table(['x', 'y'], [x, y])) f.close()
(open('build/theta_D_theo.tex', 'w', 'utf-8'). write(r'$\Theta_\mathrm{{D}} = \SI{{{:.3f}}}{{\kelvin}}$'. format(theta_D))) f = open('build/Fit.txt', 'w', 'utf-8') f.write("Temperatur\n") for i in range(len(popt_temp)): f.write(str(popt_temp[i])+"\n") f.write('\nAlpha\n') for i in range(len(popt_alpha)): f.write(str(popt_alpha[i])+"\n") f.close() f = open('build/Berechnung_Alpha.tex', 'w', 'utf-8') f.write(table([r'$T/\si{\kelvin}$', r'$\alpha \cdot 10^{-6}/\si{1\per\kelvin}$', r'$T/\si{\kelvin}$', r'$\alpha \cdot 10^{-6}/\si{1\per\kelvin}$',], [Talpha[:12], alpha_plot[:12], Talpha[12:23], alpha_plot[12:23]])) f.close() f = open('build/Berechnung_Temperatur.tex', 'w', 'utf-8') f.write(table([r'$T/\si{\kelvin}$', r'$R/\si{\ohm}$', r'$T/\si{\kelvin}$', r'$R/\si{\ohm}$',], [Tt[:12], Rt[:12], Tt[12:24], Rt[12:24]])) f.close() f = open('build/Theta.tex', 'w', 'utf-8') f.write(table([r'$T/\si{\kelvin}$', r'$C_V/\si{\joule\per\mol\per\kelvin}$', r'$\frac{\Theta_\mathrm{{D}}}{T}/\si{}$', r'$\Theta_\mathrm{{D}}/\si{\kelvin}$',], [T_Cv[:11],Cv[:11],
r'$\Theta_\mathrm{{D}} = \SI{{{:.3f}}}{{\kelvin}}$'.format(theta_D))) f = open('build/Fit.txt', 'w', 'utf-8') f.write("Temperatur\n") for i in range(len(popt_temp)): f.write(str(popt_temp[i]) + "\n") f.write('\nAlpha\n') for i in range(len(popt_alpha)): f.write(str(popt_alpha[i]) + "\n") f.close() f = open('build/Berechnung_Alpha.tex', 'w', 'utf-8') f.write( table([ r'$T/\si{\kelvin}$', r'$\alpha \cdot 10^{-6}/\si{1\per\kelvin}$', r'$T/\si{\kelvin}$', r'$\alpha \cdot 10^{-6}/\si{1\per\kelvin}$', ], [Talpha[:12], alpha_plot[:12], Talpha[12:23], alpha_plot[12:23]])) f.close() f = open('build/Berechnung_Temperatur.tex', 'w', 'utf-8') f.write( table([ r'$T/\si{\kelvin}$', r'$R/\si{\ohm}$', r'$T/\si{\kelvin}$', r'$R/\si{\ohm}$', ], [Tt[:12], Rt[:12], Tt[12:24], Rt[12:24]])) f.close() f = open('build/Theta.tex', 'w', 'utf-8')
(open('build/polarisation_I0.tex', 'w', 'utf-8').write(r'$I_0 = \SI{{{:L}}}{{\milli\ampere}}$'.format(I0))) (open('build/polarisation_phi.tex', 'w', 'utf-8').write( r'$\varphi = \SI{{{:L}}}{{\degree}}$'.format(phi * 180 / np.pi))) plt.plot(xs, ys, 'r-', label='Fit') theta = theta[:-1] I = I[:-1] plt.errorbar(theta, I, yerr=0.05 * I, fmt='bo', label='Messpunkte') plt.xlabel(r'$\theta/^\circ$') plt.ylabel(r'$I/\mathrm{mA}$') plt.xlim(-10, 360) plt.legend(loc='best') plt.savefig('build/polarisation_lin.pdf') plt.clf() f = open('build/polarisation_tab.tex', 'w', 'utf-8') f.write( table([ r'$\theta/\si{\degree}$', r'$I/\si{\milli\ampere}$', r'$\theta/\si{\degree}$', r'$I/\si{\milli\ampere}$', r'$\theta/\si{\degree}$', r'$I/\si{\milli\ampere}$', r'$\theta/\si{\degree}$', r'$I/\si{\milli\ampere}$' ], [ theta[:9], I[:9], theta[9:18], I[9:18], theta[18:27], I[18:27], theta[27:36], I[27:36] ])) f.close()
period2E = (tTwo2E - tOne2E) / number2 with open('i_raw.tex', 'w') as f: f.write( table([ r'$V_\text{87} / \si{\volt}$', r'$t_\text{1,87} / \si{\micro\second}$', r'$t_\text{2,87} / \si{\micro\second}$', r'$T_\text{87} / \si{\micro\second}$', r'#Perioden$_\text{87}$', r'$V_\text{85} / \si{\volt}$', r'$t_\text{1,85} / \si{\micro\second}$', r'$t_\text{2,85} / \si{\micro\second}$', r'#Perioden$_\text{85}$', r'$T_\text{85} / \si{\micro\second}$' ],[ V1, tOne1E*10**6, tTwo1E*10**6, number1, period1E*10**6, V2, tOne2E*10**6, tTwo2E*10**6, number2, period2E*10**6 ] ) ) poptE1, pcovE1 = curve_fit( func_exp2, expX1[600:-1000], expY1[600:-1000],
sweep2Raw = unp.uarray(sweep2Raw, DELTA_I) hor0Raw = unp.uarray(hor0Raw, DELTA_I) hor1Raw = unp.uarray(hor1Raw, DELTA_I) hor2Raw = unp.uarray(hor2Raw, DELTA_I) with open('c_data_raw.tex', 'w') as f: f.write( table( [ r'$\nu / \si{\kilo\hertz}$', r'$I_\text{0,sweep} / \si{\milli\ampere}$', r'$I_\text{0,hor} / \si{\milli\ampere}$', r'$I_\text{87,sweep} / \si{\milli\ampere}$', r'$I_\text{87,hor} / \si{\milli\ampere}$', r'$I_\text{85,sweep} / \si{\milli\ampere}$', r'$I_\text{85,hor} / \si{\milli\ampere}$' ],[ nuArr*1e-3, sweep0Raw*1e3, hor0Raw*1e3, sweep1Raw*1e3, hor0Raw*1e3, sweep2Raw*1e3, hor0Raw*1e3 ] ) ) sweep0B = _calc_b(sweep0Raw, N_SWEEP, R_SWEEP) sweep1B = _calc_b(sweep1Raw, N_SWEEP, R_SWEEP) sweep2B = _calc_b(sweep2Raw, N_SWEEP, R_SWEEP)
U_e = unp.uarray(U_e_raw,dU_e) U_a = unp.uarray(U_a_raw,dU_a) U_a_m = I * R_N print(U_a_m) with open('build/c_U_a.tex', 'w') as f: f.write(r'\num{{{:L}}}'.format( U_a_m )) R_e = np.array(U_e / I) V = np.array(R_N / R_e) with open('build/c_table.tex', 'w', 'utf-8') as f: f.write(table([r'$\nu/\si{\kilo\hertz}$', r'$U_e/\si{\milli\volt}$', r'$U_a/\si{\volt}$', r'$R_e/\si{\ohm}$', r'$V$'], [nu/1e3, U_e*1e3, U_a, R_e, V])) def func(x,a,b): return a*x+b popt_1, pcov_1 = curve_fit(func,np.log(nu[:5]),np.log(unp.nominal_values(R_e[:5]))) popt_2, pcov_2 = curve_fit(func,np.log(nu[:5]),np.log(unp.nominal_values(V[:5]))) popt_3, pcov_3 = curve_fit(func,np.log(nu[:9]),np.log(unp.nominal_values(R_e[:9]))) popt_4, pcov_4 = curve_fit(func,np.log(nu[:9]),np.log(unp.nominal_values(V[:9]))) print(str(ufloat(popt_1[0],pcov_1[0][0])) + ' ' + str(ufloat(popt_1[1],pcov_1[1][1]))) print(str(ufloat(popt_2[0],pcov_2[0][0])) + ' ' + str(ufloat(popt_2[1],pcov_2[1][1]))) print(str(ufloat(popt_3[0],pcov_3[0][0])) + ' ' + str(ufloat(popt_3[1],pcov_3[1][1]))) print(str(ufloat(popt_4[0],pcov_4[0][0])) + ' ' + str(ufloat(popt_4[1],pcov_4[1][1])))
(open('build/polarisation_I0.tex', 'w', 'utf-8'). write(r'$I_0 = \SI{{{:L}}}{{\milli\ampere}}$'. format(I0))) (open('build/polarisation_phi.tex', 'w', 'utf-8'). write(r'$\varphi = \SI{{{:L}}}{{\degree}}$'. format(phi * 180 / np.pi))) plt.plot(xs, ys, 'r-', label='Fit') theta = theta[:-1] I = I[:-1] plt.errorbar(theta, I, yerr=0.05 * I, fmt='bo', label='Messpunkte') plt.xlabel(r'$\theta/^\circ$') plt.ylabel(r'$I/\mathrm{mA}$') plt.xlim(-10, 360) plt.legend(loc='best') plt.savefig('build/polarisation_lin.pdf') plt.clf() f = open('build/polarisation_tab.tex', 'w', 'utf-8') f.write(table([r'$\theta/\si{\degree}$', r'$I/\si{\milli\ampere}$', r'$\theta/\si{\degree}$', r'$I/\si{\milli\ampere}$', r'$\theta/\si{\degree}$', r'$I/\si{\milli\ampere}$', r'$\theta/\si{\degree}$', r'$I/\si{\milli\ampere}$'], [theta[:9], I[:9], theta[9:18], I[9:18], theta[18:27], I[18:27], theta[27:36], I[27:36]])) f.close()
nuRaw, sweep0Raw, hor0Raw, sweep1Raw, hor1Raw, sweep2Raw, \ hor2Raw = np.genfromtxt('data/aufg_c.dat', unpack=True) nuArr = unp.uarray(nuRaw * 10**3, DELTA_NU) sweep0Raw = unp.uarray(sweep0Raw, DELTA_I) sweep1Raw = unp.uarray(sweep1Raw, DELTA_I) sweep2Raw = unp.uarray(sweep2Raw, DELTA_I) hor0Raw = unp.uarray(hor0Raw, DELTA_I) hor1Raw = unp.uarray(hor1Raw, DELTA_I) hor2Raw = unp.uarray(hor2Raw, DELTA_I) with open('build/tex/c_data_raw_0.tex', 'w') as f: f.write( table([ r'$\nu / \si{\kilo\hertz}$', r'$I_\text{0,sweep} / \si{\milli\ampere}$', r'$I_\text{0,hor} / \si{\milli\ampere}$' ], [nuArr * 1e-3, sweep0Raw * 1e3, hor0Raw * 1e3])) with open('build/tex/c_data_raw_87.tex', 'w') as f: f.write( table([ r'$\nu / \si{\kilo\hertz}$', r'$I_\text{87,sweep} / \si{\milli\ampere}$', r'$I_\text{87,hor} / \si{\milli\ampere}$' ], [ nuArr * 1e-3, sweep1Raw * 1e3, hor1Raw * 1e3, ]))
tTwo2E = unp.uarray(tTwo2, DELTA_T) period1 = (tTwo1 - tOne1) / number1 period2 = (tTwo2 - tOne2) / number2 period1E = (tTwo1E - tOne1E) / number1 period2E = (tTwo2E - tOne2E) / number2 with open('i_raw.tex', 'w') as f: f.write( table([ r'$V_\text{87} / \si{\volt}$', r'$t_\text{1,87} / \si{\micro\second}$', r'$t_\text{2,87} / \si{\micro\second}$', r'$T_\text{87} / \si{\micro\second}$', r'#Perioden$_\text{87}$', r'$V_\text{85} / \si{\volt}$', r'$t_\text{1,85} / \si{\micro\second}$', r'$t_\text{2,85} / \si{\micro\second}$', r'#Perioden$_\text{85}$', r'$T_\text{85} / \si{\micro\second}$' ], [ V1, tOne1E * 10**6, tTwo1E * 10**6, number1, period1E * 10**6, V2, tOne2E * 10**6, tTwo2E * 10**6, number2, period2E * 10**6 ])) poptE1, pcovE1 = curve_fit(func_exp2, expX1[600:-1000], expY1[600:-1000], p0=(-1000000, 110, 9.3)) print(poptE1) print(expY1[700:-1]) print(np.sqrt(np.diag(pcovE1))) # with open('i_fit_em_87.tex', 'w') as f:
nuArr = unp.uarray(nuRaw * 10**3, DELTA_NU) sweep0Raw = unp.uarray(sweep0Raw, DELTA_I) sweep1Raw = unp.uarray(sweep1Raw, DELTA_I) sweep2Raw = unp.uarray(sweep2Raw, DELTA_I) hor0Raw = unp.uarray(hor0Raw, DELTA_I) hor1Raw = unp.uarray(hor1Raw, DELTA_I) hor2Raw = unp.uarray(hor2Raw, DELTA_I) with open('build/tex/c_data_raw_0.tex', 'w') as f: f.write( table( [ r'$\nu / \si{\kilo\hertz}$', r'$I_\text{0,sweep} / \si{\milli\ampere}$', r'$I_\text{0,hor} / \si{\milli\ampere}$' ], [ nuArr*1e-3, sweep0Raw*1e3, hor0Raw*1e3 ] ) ) with open('build/tex/c_data_raw_87.tex', 'w') as f: f.write( table( [ r'$\nu / \si{\kilo\hertz}$', r'$I_\text{87,sweep} / \si{\milli\ampere}$', r'$I_\text{87,hor} / \si{\milli\ampere}$' ], [
popt, pcov = curve_fit(func, val_x[0:6], val_log[0:6]) popt1, pcov1 = curve_fit(func2, val_x, val) print(ufloat(popt[0], pcov[0][0])) print(ufloat(popt[1], pcov[1][1])) x = np.linspace(val_x[0] - 0.0015, val_x[5] + 0.00001, 1e4) x1 = np.linspace(val_x[0], val_x[len(val_x) - 1], 1e4) plt.plot(x, func(x, *popt), 'g-', label=r'Regression $f_h(x)$') plt.plot(val_x, val_log, 'rx', label=r'Messpunkte') plt.grid() plt.xlabel(r'$t/\mathrm{s}$') plt.ylabel(r'$\log{U/\mathrm{V}}$') plt.legend(loc="best") plt.savefig('build/h_plot.pdf') with open('build/h_table.tex', 'w', 'utf-8') as f: f.write( table([ r'$t/\si{\second}$', r'$U/\si{\volt}$', r'$t/\si{\second}$', r'$U/\si{\volt}$' ], [val_x[0:19], val[0:19], val_x[19:38], val[19:38]])) val = val * 1e3 val_x = val_x * 1e3 print(val)
popt1, pcov1 = curve_fit(func2,val_x,val) print(ufloat(popt[0],pcov[0][0])) print(ufloat(popt[1],pcov[1][1])) x = np.linspace(val_x[0]-0.0015,val_x[5]+0.00001,1e4) x1 = np.linspace(val_x[0],val_x[len(val_x)-1],1e4) plt.plot(x,func(x,*popt),'g-',label=r'Regression $f_h(x)$') plt.plot(val_x,val_log,'rx',label=r'Messpunkte') plt.grid() plt.xlabel(r'$t/\mathrm{s}$') plt.ylabel(r'$\log{U/\mathrm{V}}$') plt.legend(loc="best") plt.savefig('build/h_plot.pdf') with open('build/h_table.tex', 'w', 'utf-8') as f: f.write( table( [r'$t/\si{\second}$', r'$U/\si{\volt}$', r'$t/\si{\second}$', r'$U/\si{\volt}$'], [val_x[0:19], val[0:19], val_x[19:38], val[19:38]] ) ) val = val*1e3 val_x = val_x*1e3 print(val)
I_cleaned -= I_min print(I_min) if name == 'set1': I1_cleaned = I_cleaned else: I2_cleaned = I_cleaned with open('{}data-{}.tex'.format(texdir, name), 'w') as f: f.write( table( 3 * [ r'$T/\si{\kelvin}$', r'$I/\si{\pico\ampere}$', r'$I_\mathrm{cl}/\si{\pico\ampere}$' ], [ np.around(T[:23], 1), np.around(I[:23], 2), np.around(I_cleaned[:23], 2), np.around(T[23:46], 1), np.around(I[23:46], 2), np.around(I_cleaned[23:46], 2), np.around(T[46:], 1), np.around(I[46:], 2), np.around(I_cleaned[46:], 2), ])) xs = np.linspace(240, 340) plt.plot(xs, fit_function(xs, *var), label='fit') plt.plot(T[~selection], I[~selection], 'b.', label='Data (ignored for fit)') plt.plot(T[selection], I[selection], 'g.', label='Data (used for fit)') plt.plot(T, I_cleaned + I_min, 'r.', label='Cleaned Data')
print(R_1_4) # Import Data nu_1, U_1, dU_1 = np.genfromtxt("data/data_a_1.txt",unpack=True) nu_2, U_2, dU_2 = np.genfromtxt("data/data_a_2.txt",unpack=True) nu_3, U_3, dU_3 = np.genfromtxt("data/data_a_3.txt",unpack=True) nu_4, U_4, dU_4 = np.genfromtxt("data/data_a_4.txt",unpack=True) print(len(nu_1)) print(len(nu_2)) print(len(nu_3)) print(len(nu_4)) with open('build/a_data_1.tex', 'w') as f: f.write(table([r'$\nu / \si{\kilo\hertz}$', r'$U / \si{\volt}$', r'$\nu / \si{\kilo\hertz}$', r'$U / \si{\volt}$'], [nu_1[0:7]/1e3, unp.uarray(U_1[0:7], dU_1[0:7]), nu_1[7:14]/1e3, unp.uarray(U_1[7:14], dU_1[7:14])] )) with open('build/a_data_2.tex', 'w') as f: f.write(table([r'$\nu / \si{\kilo\hertz}$', r'$U / \si{\volt}$', r'$\nu / \si{\kilo\hertz}$', r'$U / \si{\volt}$'], [nu_2[0:9]/1e3, unp.uarray(U_2[0:9], dU_2[0:9]), nu_2[9:18]/1e3, unp.uarray(U_2[9:18], dU_2[9:18])] )) with open('build/a_data_3.tex', 'w') as f: f.write(table([r'$\nu / \si{\kilo\hertz}$', r'$U / \si{\milli\volt}$', r'$\nu / \si{\kilo\hertz}$', r'$U / \si{\milli\volt}$'], [nu_3[0:10]/1e3, unp.uarray(U_3[0:10], dU_3[0:10])*1e3, nu_3[10:20]/1e3, unp.uarray(U_3[10:20], dU_3[10:20])*1e3] )) with open('build/a_data_4.tex', 'w') as f:
return s / n * unp.sin(alpha) lambdas_left = unp.uarray([lam(x, n=n+1).n for n, x in enumerate(left)], [lam(x, n=n+1).s for n, x in enumerate(left)]) lambdas_right = unp.uarray([lam(x, n=n+1).n for n, x in enumerate(right)], [lam(x, n=n+1).s for n, x in enumerate(right)]) lambdas = np.append(np.abs(lambdas_left), np.abs(lambdas_right)) (open('build/lambda_slot.tex', 'w', 'utf-8') .write(r'$\overline{{\lambda}}_\text{{Spalt}}' r'= \SI{{{:.0f}+-{:.0f}}}{{\nano\meter}}$' .format(unp.nominal_values(lambdas).mean() * 1e6, unp.std_devs(lambdas).mean() * 1e6))) f = open('build/lambdas_slot_mm_l.tex', 'w', 'utf-8') f.write(table([r'$x/\si{\milli\meter}$', r'$\lambda/\si{\nano\meter}$'], [left, lambdas_left*1e6])) f.close() f = open('build/lambdas_slot_mm_r.tex', 'w', 'utf-8') f.write(table([r'$x/\si{\milli\meter}$', r'$\lambda/\si{\nano\meter}$'], [right, lambdas_right*1e6])) f.close() # grid s = ufloat(0.01, 0.0) d = ufloat(980, 5) xs1 = 10 * np.genfromtxt('data/grid1.txt', unpack=True) xs2_right = np.genfromtxt('data/grid2_right.txt', unpack=True) xs2_left = np.genfromtxt('data/grid2_left.txt', unpack=True)
U_e = unp.uarray(U_e_raw, dU_e) U_a = unp.uarray(U_a_raw, dU_a) U_a_m = I * R_N print(U_a_m) with open('build/c_U_a.tex', 'w') as f: f.write(r'\num{{{:L}}}'.format(U_a_m)) R_e = np.array(U_e / I) V = np.array(R_N / R_e) with open('build/c_table.tex', 'w', 'utf-8') as f: f.write( table([ r'$\nu/\si{\kilo\hertz}$', r'$U_e/\si{\milli\volt}$', r'$U_a/\si{\volt}$', r'$R_e/\si{\ohm}$', r'$V$' ], [nu / 1e3, U_e * 1e3, U_a, R_e, V])) def func(x, a, b): return a * x + b popt_1, pcov_1 = curve_fit(func, np.log(nu[:5]), np.log(unp.nominal_values(R_e[:5]))) popt_2, pcov_2 = curve_fit(func, np.log(nu[:5]), np.log(unp.nominal_values(V[:5]))) popt_3, pcov_3 = curve_fit(func, np.log(nu[:9]), np.log(unp.nominal_values(R_e[:9]))) popt_4, pcov_4 = curve_fit(func, np.log(nu[:9]), np.log(unp.nominal_values(V[:9])))
tOne1E = unp.uarray(tOne1, DELTA_T) tTwo1E = unp.uarray(tTwo1, DELTA_T) tOne2E = unp.uarray(tOne2, DELTA_T) tTwo2E = unp.uarray(tTwo2, DELTA_T) period1 = (tTwo1 - tOne1) / number1 period2 = (tTwo2 - tOne2) / number2 period1E = (tTwo1E - tOne1E) / number1 period2E = (tTwo2E - tOne2E) / number2 with open('build/tex/i_exp_raw_87.tex', 'w') as f: f.write( table([ r'$t_\text{87} / \si{\milli\second}$', r'$U_\text{87} / \si{\volt}$' ], [ expX1E * 1e3, expY1E ]) ) with open('build/tex/i_exp_raw_85.tex', 'w') as f: f.write( table([ r'$t_\text{85} / \si{\milli\second}$', r'$U_\text{85} / \si{\volt}$' ], [ expX2E * 1e3, expY2E ]) )