def Angle_calibration(plot1=False, plot2=False, printA=False): plt.close('all') angle_data = np.load(nppath + "angle_cal.npy") X = angle_data[:, 0] # sec Y = angle_data[:, 1] # mRad x_minima = [62, 178, 293, 407] # sec x_maxima = [120, 235, 350] # sec minima, maxima = dg.extrema(X, Y, 10, x_minima, x_maxima) ext = minima + maxima ext = dg.sort(np.array(ext), 0) if plot1 == True: # '0_1_Angles_cal', angles for angle calibration # plots: X , Y , style , label p1 = dp.data(X, Y, '-', 'b', '$\\theta_{comp}$') p2 = dp.data(ext[:, 0], ext[:, 1], 'r*', 'r', 'Extrema') ax = dp.ax([p1, p2], 111, 'time [sec]', "$\\theta_{comp}$ [mRad]", "$\\theta_{comp}$ for Angle Calibration") dp.plot([ax], name=gp + '0_1_Angles_cal') X_data, Y_data = AuxOne(L.val, S.val, ext[:, 1]) m, m_err = df.m_exp(X_data, Y_data), df.sig_m(X_data, Y_data) b, b_err = df.b_exp(X_data, Y_data), df.sig_b(X_data, Y_data) m_err_p, b_err_p = m_err * 100 / m, b_err * 100 / b r2 = df.R2(X_data, Y_data) X_lin = np.linspace(0, max(X_data) + 10, 1000) Y_lin = df.lin_fit(X_data, Y_data, X_lin) if plot2 == True: p1 = dp.data(X_data, Y_data, 'bs', 'b', 'Laser vs Comp') p2 = dp.data(X_lin, Y_lin, 'r-', 'r', 'Linear Fit') n2 = dp.note( "Y = C x + B\nm = %s $\pm$ %s\nb = %s $\pm$ %s\nR$^2$ = %s" % (round(m, 2), round(m_err, 2), round(b, 1), round( b_err, 1), round(r2, 5)), 20, 7, p2.color) ax = dp.ax([p1, p2], 111, '$\\theta_{comp}$ [mRad]', '$\\theta_{laser}$ [mRad]', '$\\theta_{laser}$ vs. $\\theta_{comp}$') ax.notes = [n2] dp.plot([ax], name=gp + '0_2_laser_vs_comp') if printA == True: print("") print("Calibrtion:") print("theta_comp = %s" % X_data) print("theta_laser = %s" % Y_data) print("calibration constant = %s +/- %s (%s)" % (m, m_err, m_err_p)) print("intercept = %s +/- %s (%s)" % (b, b_err, b_err_p)) print("R2 = %s" % r2) print("") return m, m_err
def fig07(saveA=True): data = pd.read_table(three_d['txt']) B = data['MagField'].values * C['T'] # T I = data['MagCurr'].values # A X = B # T Y = I * C['L'] / C['A'] # T X_fit = np.linspace(min(X), max(X), 1000) FIT = df.lin_fit(X, Y, X_fit) Y_fit = FIT['Y_fit'] m = FIT['m'] b = FIT['b'] R2 = FIT['R2'] mu_rval = m.val mu_rerr = m.err mu_r = dg.var(mu_rval, mu_rerr) fig = plt.figure(figsize=pp['figsize']) plt.title('Finding $\mu_r$', fontsize=pp['fs'] + 2) plt.xlabel('B [ T ]', fontsize=pp['fs']) plt.ylabel('I L / A [ T ]', fontsize=pp['fs']) plt.xlim([min(X), max(X)]) plt.plot(X, Y, color='c', lw=pp['lw'], label='p-Ge') plt.plot(X_fit, Y_fit, pp['fit_style'], lw=pp['lw'], label='fit') plt.legend(loc='best', fontsize=pp['fs']) note = 'y = m x + b\n\ m = $\mu_r$ = %s $\pm$ %s [ H/m ]\n\ b = %s $\pm$ %s [ T ]\n\ R$^2$ = %s'\ % (m.pval,m.perr,b.pval,b.perr,"{0:.4f}".format(R2) ) plt.annotate(note, xy=(.097, 24500), color='r', fontsize=pp['fs']) if saveA: fig.savefig('png/fig07.png') plt.close() else: plt.show() dic = {'mu_val': mu_r.val, 'mu_err': mu_r.err, 'mu_r': mu_r} return pd.Series(dic)
def part3(printA=True,saveA=True,figsize=(15,15), fs=20, lw=2): print("") print("Part III") # compare G2 = 1*10*100 R = 10e3 # Ohm delta_f = 110961 # Hz vout = .94 # V vrms_conv = out2rms(G2,vout) # V vrms_calc = v_rms(delta_f,k_default,R_default) vrms, perr = err(vrms_conv,vrms_calc) if printA == True: print("compare") print("v_out = ", vout) print("v_rms_conv = ", vrms_conv) print("v_rms_calc = ", vrms_calc) print("v_rms = %s +/- %s V (%s percent)" % (vrms.pval,vrms.perr,perr) ) print("") # amplifier noise R = np.array([ 1, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6 ]) G2 = np.array([ 10*10*20, 10*10*20, 10*10*20, 10*10*20, 10*10*10, 1*10*40, 1*10*30 ]) VOUT = np.array([ .9727, .9722, .9715, .9718, .9743, .9773, .9747, .9755, 1.0005, 1.0025, .9998, 1.0010, 1.2441, 1.2492, 1.2468, 1.2435, .9323, .9319, .9355, .9337, .8912, .8882, .8863, .8877, .9585, .9550, .9595, .9650 ]).reshape([7,4]) VOUT = np.array([ np.average(VOUT[i]) for i in range(7) ]) Y_data = ( VOUT * (1e6)**2 ) / ( gain(G2)**2) # micro V^2 X_fit = np.linspace(0, 2e4, 1000) # Ohm cutoff = 2 # num Y_fit, m, b = df.lin_fit( R[:-cutoff] , Y_data[:-cutoff] , X_fit ) # micro V^2 R2 = df.R2(R[:-cutoff],Y_data[:-cutoff]) # num amp = np.sqrt(b.val) amp_err = b.err/(2*np.sqrt(b.val)) ampN = dg.var( amp,amp_err ) # micro V fig = plt.figure(figsize=figsize) plt.title('Part III: Amplifier Noise', fontsize=fs+2) plt.xlabel('R [$\\Omega$]', fontsize=fs) plt.ylabel('<Vj$^2$> [$\\mu$ V$^2$]', fontsize=fs) plt.xlim(min(X_fit),max(X_fit)) plt.plot(R[:-cutoff],Y_data[:-cutoff], 'bo', markersize=15, label='data') plt.plot(X_fit,Y_fit, color='r', lw=lw, label='fit') note = '$Vj^2 = mR + b$\n$m = %s \pm %s\ \\mu\ V^2/\\Omega$\n$b = %s \pm %s\ \\mu\ V^2$\n$R^2 = %s$' % (m.pval,m.perr,b.pval,b.perr,round(R2,6) ) plt.annotate(note, xy=(1e3,35), color='r', fontsize=fs) note2 = 'Pre-Amp Noise = $\sqrt{b} \pm \\Delta b/(2 \sqrt{b})$\n $= %s \pm %s\ \\mu V$' % (ampN.pval,ampN.perr) plt.annotate(note2, xy=(1e3,30), color='m', fontsize=fs+2) plt.legend(loc='best', fontsize=fs) if saveA == True: fig.savefig('../graphs/fig02.png') plt.close(fig) else: plt.show(fig) if printA == True: print('amplifier noise') print('R = %s Ohm' % R) print('Vj^2 = %s micro V^2' % Y_data ) print("The best fit was found by not considering the last %s data points" % cutoff ) print("n = %s +/- %s micro V^2/Ohm" % (m.pval,m.perr) ) print("b = %s +/- %s micro V^2/Ohm") print('amplifer noise = %s +/- %s micro V^2' % (ampN.pval,ampN.perr) ) print('') # experimental k DELTA_f = np.array([ 355, 1077, 3554, 10774, 35543, 107740 ]) # Hz G2 = np.array([ 10*10*60, 10*10*40, 10*10*20, 10*10*10, 1*10*60, 1*10*40 ]) VOUT = np.array([ .8, 1.0, .9, .7, .8, .9 ]) # V R = 100e3 # Ohm Y_data = ( VOUT * (1e9)**2 ) / ( gain(G2)**2 * 4 * R * T_room ) # nV^2/Ohm/K X_fit = np.linspace(0,120000,1000) # Hz Y_fit, m, b = df.lin_fit( DELTA_f , Y_data , X_fit ) R2 = df.R2(DELTA_f,Y_data) kval = m.val/(1e9)**2 # J/K kval_err = m.err/(1e9)**2 k = dg.var( kval,kval_err ) fig = plt.figure(figsize=figsize) plt.title('Part III: Bolzmann Constant', fontsize=fs+2) plt.xlabel('$\\Delta$ f [Hz]', fontsize=fs) plt.ylabel('<Vj$^2$>/R/T [nV$^2$/$\\Omega$/K]', fontsize=fs) plt.xlim(min(X_fit),max(X_fit)) plt.plot(DELTA_f,Y_data, 'bo', markersize=15, label='data') plt.plot(X_fit,Y_fit, color='r', lw=lw, label='fit') note = '$V^2 = m f + b$\n$m = %s \pm %s\ nV^2/ \\Omega/ K / Hz$\n$b = %s \pm %s\ nV^2/ \\Omega/ K$\n$R^2 = %s$' % (m.pval,m.perr,b.pval,b.perr,round(R2,3) ) plt.annotate(note, xy=(1.5e3,1.2), color='r', fontsize=fs) note2 = '$k = (m \pm \\Delta m)/(1_{+9})^2$\n $= %s \pm %s\ J/K$' % (k.pval,k.perr) plt.annotate(note2, xy=(1.5e3,1), color='m', fontsize=fs+2) plt.legend(loc='best', fontsize=fs) if saveA == True: fig.savefig('../graphs/fig03.png') plt.close(fig) else: plt.show(fig) if printA == True: print("Bolzmann constant") print("m = %s +/- %s 1e18 J/K" % (m.pval,m.perr) ) print("k = %s +/- %s J/K" % (k.pval,k.perr) ) return
def part4(printA=True,saveA=True,figsize=(15,15),fs=20,lw=2): print("") print("Part IV:") R = np.array([ 10, 10e3 ]) # Ohm G2 = np.array([ 10*10*20, 10*10*10 ]) # JOHNSON NOISE AT T_room with A_ext and B_ext VOUT = np.array([ np.average([.9831, .9843, .9841, .9820]), np.average([.7650, .7653, .7669, .7662]) ]) # V^2 Y_data = ( VOUT * (1e6)**2 ) / (gain(G2)**2) # (micro V)^2 X_fit = np.linspace(0, 11e3, 1000) # Ohm Y_fit, m, b = df.lin_fit( R , Y_data , X_fit ) R2 = df.R2(R,Y_data) mval = round(m.val,4) merr = 5e-4 bval = round(b.val,1) berr = .5 noise = round(np.sqrt(b.val),1) # micro V^2 noise_err = round(berr/(2*np.sqrt(b.val)),1) # ampN = dg.var( noise,noise_err ) fig = plt.figure(figsize=figsize) plt.title('Part IV: Amplifier Noise from A$_{ext}$ and B$_{ext}$', fontsize=fs+2) plt.xlabel('R [$\\Omega$]', fontsize=fs) plt.ylabel('<Vj$^2$> [$\\mu$V$^2$]', fontsize=fs) plt.xlim(min(X_fit),max(X_fit)) plt.plot(R,Y_data, 'bo', markersize=15, label='data') plt.plot(X_fit,Y_fit, color='r', lw=lw, label='fit') note = '$Vj^2 = mR + b$\n$m = %s \pm %s\ \\mu V^2/\\Omega$\n$b = %s \pm %s\ \\mu V^2$\n$R^2 = %s$' % (mval,merr,bval,berr,round(R2,4) ) plt.annotate(note, xy=(1e2,19), color='r', fontsize=fs) note2 = 'Pre-Amp Noise = $\sqrt{b} \pm \\Delta b/(2 \sqrt{b})$\n $= %s \pm %s\ \\mu V$' % (noise,noise_err) plt.annotate(note2, xy=(1e2,17), color='m', fontsize=fs+2 ) plt.legend(loc='best', fontsize=fs) if saveA == True: fig.savefig('../graphs/fig04.png') plt.close() else: plt.show() if printA == True: print('amplifier noise from Aext and Bext') print('it was found that Cext did not measure at an correct value and was discarded.') print('m = %s +/- %s micro V^2/Hz' % (mval,merr) ) print('b = %s +/- %s micro V^2' % (bval,berr) ) print('amplifer noise = %s +/- %s micro V' % (noise,noise_err) ) print('') # experimental k at T = 77 K VOUT2 = np.array([ np.average([.9825, .9832, .9804, .9827]), np.average([.3909, .3905, .3905, .3911]) ]) # V^2 Y_data2 = ( VOUT2 * (1e9)**2 ) / (gain(G2)**2 * 4 * 77 * 110961 ) # nV^2 / K / Hz Y_fit2, m, b = df.lin_fit( R , Y_data2 , X_fit ) R22 = df.R2(R,Y_data2) bval = round(b.val,2) berr = .05 mval = round(m.val,6) merr = 5e-6 kval = round(m.val/(1e9)**2,24) # J/K kerr = round(merr/(1e9)**2,24) # k = dg.var( kval,kval_err ) fig = plt.figure(figsize=figsize) plt.title('Part IV: Boltzmann Constant at 77 K', fontsize=fs+2) plt.xlabel('R [$\\Omega$]', fontsize=fs) plt.ylabel('[nVj$^2$/K/Hz]', fontsize=fs) plt.xlim(min(X_fit),max(X_fit)) plt.plot(R,Y_data2, 'bo', markersize=15, label='data') plt.plot(X_fit,Y_fit2, color='r', lw=lw, label='fit') note = '$nVj^2/T/\\Delta f = mR + b$\n$m = %s \pm %s\ nV^2/K/Hz/\\Omega$\n$b = %s \pm %s\ nV^2/K/Hz$\n$R^2 = %s$' % (mval,merr,bval,berr,round(R22,4) ) plt.annotate(note, xy=(1e2,3e-1), color='r', fontsize=fs) note2 = '$k = (m \pm \\Delta m)/(1_{+9})^2$\n $= %s \pm %s\ J/K$' % (kval,kerr) plt.annotate(note2, xy=(1e2, 2.8e-1), color='m', fontsize=fs+2) plt.legend(loc='best', fontsize=fs) if saveA == True: fig.savefig('../graphs/fig05.png') plt.close() else: plt.show() if printA == True: print('Bolzmann Constant at 77 K') print('it was found that Cext did not measure at an correct value and was discarded.') print('experimental k = %s +/- %s J/m' % (kval,kerr) ) print('')
def fig08(saveA=True): # raw data data = pd.read_table(three_c['txt']) T = data['Temp'].values + C['K'] # temperature [K] Vs = data['SampVolt'].values # sample voltage [V] Is = data['SampCurr'].values / 1000 # sample current [A] # form data into axis X = 1000 / T # [K] Y = (C['l_samp'] * Vs) / (C['a_samp'] * Is) # [ohm-cm] Y = np.log(Y) # start of semi-conductor phase (increase temperature -> lower resistance) semi0 = 2.95 i_semi0 = dg.nearest(X, semi0) # fit semi-conductor phase to line X_fit = np.linspace(2.7, 3.4, 1000) FIT = df.lin_fit(X[X > semi0], Y[X > semi0], X_fit) Y_fit = FIT['Y_fit'] m = FIT['m'] b = FIT['b'] R2 = FIT['R2'] fig = plt.figure(figsize=pp['figsize']) plt.title('Resistivity of p-Ge', fontsize=pp['fs'] + 2) plt.xlabel('1000/T [ 1/K ]', fontsize=pp['fs']) plt.ylabel('ln( $\\rho$ [ $\Omega$ cm ] )', fontsize=pp['fs']) plt.xlim([min(X), max(X_fit)]) plt.ylim([min(Y), max(Y_fit)]) plt.plot(X[i_semi0:], Y[i_semi0:], color='b', lw=pp['lw'], label='p-Ge data') plt.plot(X_fit, Y_fit, pp['fit_style'], lw=pp['lw'], label='semi-phase fit') plt.vlines(x=semi0, ymin=6.5, ymax=8, color='r', linewidth=1) plt.legend(loc='best', fontsize=pp['fs']) note = 'semi-conductor phase fit cut off = %.0f K' % (1000 / semi0) plt.annotate(note, xy=(semi0 + .005, 6.9), color='r', fontsize=pp['fs'] - 4, rotation=-90) note1 = 'y = m x + b\n\ m = %s $\pm$ %s [ $\Omega$ cm K ]\n\ b = %s $\pm$ %s [ $\Omega$ cm ]\n\ R$^2$ = %.4f'\ % (m.pval,m.perr,b.pval,b.perr,R2) plt.annotate(note1, xy=(3, 6.99), color='r', fontsize=pp['fs'] - 4) T_interest = 300 # K x_interest = 1000 / T_interest i_interest = dg.nearest(X_fit, x_interest) rho_val = np.exp(Y_fit[i_interest]) rho = equation5(rho_val, m, x_interest, b) note2 = '$\\rho$ ( T = %.0f K ) = %s $\pm$ %s $\Omega$ cm' % ( T_interest, rho.pval, rho.perr) plt.annotate(note2, xy=(3.17, 6.85), color='g', fontsize=pp['fs'] - 4, rotation=-41) plt.plot(X_fit[i_interest], Y_fit[i_interest], 'og', ms=pp['ms']) if saveA: fig.savefig('png/fig08.png') plt.close() else: plt.show() dic = { 'mval': m.val, 'merr': m.err, 'm': m, 'bval': b.val, 'berr': b.err, 'b': b, 'R2': R2 } return pd.Series(dic)
def fig05(saveA=True): data = pd.read_table(five_c['txt']) T = data['Temp'].values # K Vs = data['SampVolt'].values # V Is = data['SampCurr'].values / 1000 # A l = 20e-3 # m A = 10 / (1000)**2 # m^2 sigma = l * Is / A / Vs # 1/(Ohm m) # linearize X = 1 / (T + 273.15) # 1/K Y = np.log(Vs) X_fit = np.linspace(min(X), max(X), 1000) FIT = df.lin_fit(X, Y, X_fit) Y_fit = FIT['Y_fit'] m = FIT['m'] b = FIT['b'] R2 = FIT['R2'] E_gval = 2 * C['k'] * m.val E_gerr = 2 * C['k'] * m.err E_g = dg.var(E_gval, E_gerr) fig = plt.figure(figsize=pp['figsize']) plt.title('i-Ge Band Gap', fontsize=pp['fs'] + 2) plt.xlabel("1/T [ 1/K ]", fontsize=pp['fs']) plt.ylabel("ln ( V$_s$ [ V ] )", fontsize=pp['fs']) plt.xlim(min(X_fit), max(X_fit)) plt.plot(X, Y, 'b', lw=pp['lw'], label='data') plt.plot(X_fit, Y_fit, 'r', lw=pp['lw'], label='fit') note = ' Y=m x + b\n\ ln( V$_s$ ) = ( -E$_g$/2k ) ( 1/T ) + ln( A )\n\ m = %s $\pm$ %s\n\ b = %s $\pm$ %s\n\ R$^2$ = %.4f\n\ E$_g$ = 2 k m $\pm$ 2 k $\Delta$ m\n\ = %s $\pm$ %s eV'\ % (m.pval,m.perr,b.pval,b.perr,R2,E_g.pval,E_g.perr) plt.annotate(note, xy=(.00255, .9), color='r', fontsize=pp['fs']) plt.legend(loc='best', numpoints=1) if saveA: fig.savefig('png/fig05.png') plt.close() else: plt.show() dic = { 'm_val': m.val, 'm_err': m.err, 'm': m, 'E_g_val': E_g.val, 'E_gerr': E_g.err, 'E_g': E_g } return dic
def fig02(saveA=True): # data X = one_d['g'] Y1 = one_d['B'] Y = Y1 * X**2 # fit and theory X_fit = np.linspace(.2, 2.5, 1000) Y_T = equation1(1, X_fit) * X_fit**2 # find flux leak Y_T1 = equation1(1, X) * X**2 Y_L = (Y_T1 - Y) / Y_T1 yl_av = np.average(Y_L) yl_std = np.std(Y_L) yl = dg.var(yl_av, yl_std) FIT = df.lin_fit(X, Y, X_fit) Y_fit = FIT['Y_fit'] m = FIT['m'] b = FIT['b'] R2 = FIT['R2'] fig = plt.figure(figsize=pp['figsize']) plt.title('Magnetic Field Strength vs. Magnet Gap', fontsize=pp['fs'] + 2) plt.xlabel('Gap [cm]', fontsize=pp['fs']) plt.ylabel('B Gap$^2$ [%s cm$^2$]' % units['MagField'], fontsize=pp['fs']) plt.xlim([min(X_fit), max(X_fit)]) plt.plot(X, Y, pp['data_style'], markersize=pp['ms'], label='data') plt.plot(X_fit, Y_fit, pp['fit_style'], lw=pp['lw'], label='data fit') plt.plot(X_fit, Y_T, 'g', lw=pp['lw'], label='theory') plt.legend(loc='best', fontsize=pp['fs'], numpoints=1) note = 'y = m x + b\n\ m = %s $\pm$ %s [kG cm]\n\ b = %s $\pm$ %s [kG cm$^2$]\n\ R$^2$ = %s'\ % (m.pval,m.perr,b.pval,b.perr,"{0:.4f}".format(R2) ) plt.annotate(note, xy=(.3, 1.1), color='r', fontsize=pp['fs']) note1 = '100 (B$_T$ - B$_L$) / B$_T$ = %s $\pm$ %s percent' % (yl.pval, yl.perr) plt.annotate(note1, xy=(.3, 1), color='g', fontsize=pp['fs']) if saveA: fig.savefig('png/fig02.png') plt.close() else: plt.show() dic = { 'X': X, 'Y': Y, 'fit': FIT, 'theory': Y_T, 'leak': yl.val, 'leak_error': yl.err } return pd.Series(dic)