In [55]:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit  # import the curve fitting function
%matplotlib inline

Travel Time in Air


In [56]:
Time = np.array([18,18.4,25.2,29.6,33.4,37.0,40.4])*1e-9 #seconds
Distance = np.array([133.1,167.6,347.5,482.6,586,682.1,796.5])*1e-2 #Meters

#Time = np.array([18,25.2,29.6,33.4,37.0,40.4])*1e-9 #seconds
#Distance = np.array([133.1,347.5,482.6,586,682.1,796.5])*1e-2 #Meters

dt = 0.2*1e-9 #time uncertainty
dD = np.array([0.33*2,0.33*2,0.33*2,0.33*2,0.33*2,0.33*4,0.33*4])*1e-2

In [68]:
plt.figure(figsize=(5,3));
plt.scatter(Distance,Time*1e9);

plt.xlabel('Path Length (m)',fontsize=20);
plt.ylabel('Time (ns)',fontsize = 20);
plt.xticks(size = 13);
plt.yticks(size = 13);
#plt.xlim(17e-9,41.5e-9);
#plt.ylim(0,1.2e-28);



In [99]:
def myfun(t,c,k):
    ans =  c*t + k #Distance traveled with offset
    return ans

def myfun(d,c,to):
    ans =  d/c + to
    return ans

p0 = [3e8,1e-2] #guess

xspace = np.linspace(1.33,8.00) 

plsq, pcov = curve_fit(myfun, Distance, Time, p0,sigma=dt)  # curve fit returns p and covariance matrix
# these give the parameters and the uncertainties
c = plsq[0]
ec = np.sqrt(pcov[0,0])
to = plsq[1]
eto = np.sqrt(pcov[1,1])


yfit = myfun(xspace,plsq[0],plsq[1])  # use fit results for a, b, c

plt.figure(figsize=(10,6));

plt.scatter(Distance,Time*1e9, marker='.',label='Data');
plt.errorbar(Distance, Time*1e9, yerr=dt*1e9,xerr=dD,fmt='none')
plt.plot(xspace,yfit*1e9,label='Fit')

plt.legend(loc='lower right')
plt.xlabel('Path Length (m)',fontsize=20);
plt.ylabel('Time (ns)',fontsize = 20);
plt.text(0.5,42,'$c = (%.2f \pm %.2f)\cdot 10^8$ m/s' % (plsq[0]*1e-8, np.sqrt(pcov[0,0])*1e-8),size=20)
plt.text(0.5,38,'$t_{delay} = (%.1f \pm %.1f) $ ns' % (plsq[1]*1e9, np.sqrt(pcov[1,1])*1e9),size=20)

#plt.errorbar(mub*B_Rb87,E_Rf,xerr = mub*16*muo*N*dV/(np.sqrt(125)*2*R),fmt='none');
plt.yticks(size = 15);
plt.xticks(size = 15);
plt.savefig('cInAir.png')


Travel Time in Fiber Cable


In [86]:
Times = np.array([37.2,17.4,19.6,48.8,37.6,17.4,24.2])*1e-9 #seconds
Distances = np.array([466.6,66.4,124.8,702.4,468.6,79.4,209])*1e-2 #Meters

dD2 = 0.2*1e-2

In [91]:
plt.figure(figsize=(5,3));
plt.scatter(Distances,Times*1e9);

plt.xlabel('Path Length (m)',fontsize=20);
plt.ylabel('Time (ns)',fontsize = 20);
plt.xticks(size = 13);
plt.yticks(size = 13);
#plt.ylim(16.8e-9,50e-9);
#plt.ylim(0,1.2e-28);



In [100]:
def myfun2(t,c,k):
    ans =  c*t + k #Distance traveled with offset
    return ans

def myfun2(d,c,to):
    ans =  d/c + to
    return ans

p02 = [3e8,-1e2] #guess

xspace2 = np.linspace(0.5,8) 

plsq, pcov = curve_fit(myfun2,  Distances, Times, p02, sigma = dt)  # curve fit returns p and covariance matrix
# these give the parameters and the uncertainties
c2 = plsq[0]
ec2 = np.sqrt(pcov[0,0])
to2 = plsq[1]
eto2 = np.sqrt(pcov[1,1])


yfit2 = myfun(xspace2,plsq[0],plsq[1])  # use fit results for a, b, c

plt.figure(figsize=(10,6));

plt.scatter(Distances,Times*1e9, marker='.',label='Data');
plt.errorbar(Distances,Times*1e9,yerr=dt,xerr=dD2,fmt='none')
plt.plot(xspace2,yfit2*1e9,label='Fit')

#plt.xlim(17e-9,50e-9);

plt.legend(loc='lower right')
plt.xlabel('Path Length (m)',fontsize=20);
plt.ylabel('Time (ns)',fontsize = 20);

plt.text(0.5,52,'$v_c = (%.2f \pm %.2f)\cdot 10^8$ m/s' % (plsq[0]*1e-8, np.sqrt(pcov[0,0])*1e-8),size=20)
plt.text(0.5,48,'$t_{prcs} = (%.1f \pm %.1f) $ ns' % (plsq[1]*1e9, np.sqrt(pcov[1,1])*1e9),size=20)


#plt.errorbar(mub*B_Rb87,E_Rf,xerr = mub*16*muo*N*dV/(np.sqrt(125)*2*R),fmt='none');
plt.yticks(size = 15);
plt.xticks(size = 15);
plt.savefig('cInFiber.png')



In [ ]: