In [18]:
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

T1


In [19]:
h1 = np.array([-5.55,-3.14,-1.25,2.05,3.8,4.74,6,6.67,7.7,8.5,9.1,9.7,10.1,10.7,11.0,11.3,11.7])
t1 = np.array([10,15,20,25,30,35,40,45,50,55,60,65,70,75,80,85,90])

In [20]:
plt.figure(figsize=(12,6))
plt.scatter(t1,h1);
plt.xticks(size=16);
plt.yticks(size=16);
plt.ylim(-7,13)

plt.xlabel('Delay Time (ms)',size=20);
plt.ylabel('FID Amplitude (V)', size = 20);
plt.savefig('T1.png')



In [21]:
def myfun(t,M_o,T1):
    ans =  M_o*(1-2*np.exp(-t/T1))
    return ans

p0 = [-5,20] #guess

xspace = np.linspace(10,100) 

plsq, pcov = curve_fit(myfun, t1, h1, p0)  # curve fit returns p and covariance matrix
# these give the parameters and the uncertainties
M_o = plsq[0]
eM_o = np.sqrt(pcov[0,0])

T1 = plsq[1]
eT1 = 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(t1,h1,marker='.',label='Data');
plt.xticks(size = 15);
plt.yticks(size = 15);


#plt.xlabel('Accelerating Voltage (V)',size=20);
#plt.ylabel('Current (pA)',size=20);

plt.plot(xspace,yfit,label='Fit');
#plt.text(7,9.1, '$V_{min} = %.1f \pm %.1f$ V' % (V_min, dV) ,size=20)

plt.xticks(size=16);
plt.yticks(size=16);
plt.ylim(-7,13)

plt.text(80,0, '$T_1 = %.1f \pm %.1f$ $ms$' % (T1, eT1) ,size=20)

plt.legend(loc='best');

plt.savefig('T1Fit.png')



In [22]:
import heapq

In [23]:
data = np.loadtxt('glycerin.txt')

Voltages = np.array([data[i][1] for i in np.arange(0,len(data))])
Times = np.array([data[i][0] for i in np.arange(0,len(data))])

PeakIndices = heapq.nlargest(30, range(len(Voltages)), Voltages.take)

#PeakIndices = np.sort(PeakIndices)

TopV = np.array([Voltages[i] for i in PeakIndices])
#TopV = np.sort(TopV)
#TopV = TopV[::-1]

TopTimes = np.array([Times[i] for i in PeakIndices])
#TopTimes = np.sort(TopTimes)

In [24]:
TopV


Out[24]:
array([ 2.8140698 ,  2.49246182,  2.49246182,  2.33165783,  2.33165783,
        2.25125584,  2.01004986,  2.01004986,  1.84924587,  1.84924587,
        1.84924587,  1.84924587,  1.76884387,  1.68844188,  1.68844188,
        1.52763789,  1.52763789,  1.4472359 ,  1.4472359 ,  1.3668339 ,
        1.3668339 ,  1.28643191,  1.28643191,  1.20602991,  1.20602991,
        1.20602991,  1.12562792,  1.12562792,  1.04522593,  1.04522593])

In [25]:
TopTimes


Out[25]:
array([  7.59940000e-03,   1.51594000e-02,   1.52602000e-02,
         3.94000000e-05,   7.70020000e-03,   2.28202000e-02,
         3.03802000e-02,   3.04810000e-02,   1.40200000e-04,
         7.49860000e-03,   2.27194000e-02,   3.80410000e-02,
         3.79402000e-02,   2.29210000e-02,   4.56010000e-02,
         5.31610000e-02,   5.32618000e-02,   1.50586000e-02,
         1.53610000e-02,   3.02794000e-02,   4.57018000e-02,
         4.55002000e-02,   6.08218000e-02,   3.81418000e-02,
         6.09226000e-02,   6.83818000e-02,   1.14298000e-02,
         6.07210000e-02,   7.80100000e-03,   6.84826000e-02])

In [26]:
Top10V = np.array([2.8140698, 2.492461823, 2.25125584, 2.010049857, 1.849245869, 1.68844188, 1.527637891])
Top10V


Out[26]:
array([ 2.8140698 ,  2.49246182,  2.25125584,  2.01004986,  1.84924587,
        1.68844188,  1.52763789])

In [27]:
Top10t = np.array([0.0075994, 0.0151594, 0.0228202, 0.0303802, 0.038041, 0.045601, 0.053161])
Top10t


Out[27]:
array([ 0.0075994,  0.0151594,  0.0228202,  0.0303802,  0.038041 ,
        0.045601 ,  0.053161 ])

In [28]:
plt.figure(figsize=(10,6));
plt.scatter(Top10t,Top10V);
plt.xlim(0.0055,0.058);
plt.xticks(size=16);
plt.yticks(size=16);
plt.xlabel('Time (s)',size=15);
plt.ylabel('Pulse Height (V)',size=15);



In [29]:
def myfun(t,V_o,tau):
    ans =  V_o*np.exp(-t/tau)
    return ans

p0 = [5,0.020] #guess

xspace = np.linspace(0.0055,0.058) 

plsq, pcov = curve_fit(myfun, Top10t, Top10V, p0)  # curve fit returns p and covariance matrix
# these give the parameters and the uncertainties
V_o = plsq[0]
eV_o = np.sqrt(pcov[0,0])

tau = plsq[1]
etau = 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(Top10t,Top10V,marker='.',label='Data');
plt.xticks(size = 15);
plt.yticks(size = 15);


#plt.xlabel('Accelerating Voltage (V)',size=20);
#plt.ylabel('Current (pA)',size=20);

plt.plot(xspace,yfit,label='Fit');
#plt.text(7,9.1, '$V_{min} = %.1f \pm %.1f$ V' % (V_min, dV) ,size=20)

plt.xlim(0.0055,0.058);
plt.xticks(size=16);
plt.yticks(size=16);
plt.xlabel('Time (s)',size=15);
plt.ylabel('Pulse Height (V)',size=15);

plt.text(0.04,2.5, '$T2 = %.1f \pm %.1f$ $ms$' % (tau*1e3, etau*1e3) ,size=20)

plt.legend(loc='best');

plt.savefig('T2Glycerol.png')



In [30]:
data = np.loadtxt('mineraloil.txt')

Voltages = np.array([data[i][1] for i in np.arange(0,len(data))])
Times = np.array([data[i][0] for i in np.arange(0,len(data))])

PeakIndices = heapq.nlargest(20, range(len(Voltages)), Voltages.take)

#PeakIndices = np.sort(PeakIndices)

TopV = np.array([Voltages[i] for i in PeakIndices])
#TopV = np.sort(TopV)
#TopV = TopV[::-1]

TopTimes = np.array([Times[i] for i in PeakIndices])
#TopTimes = np.sort(TopTimes)

In [31]:
Top10V = np.array([4.11451022,  3.27028896, 2.46626872, 1.86325354, 1.54164544,  1.22003735, 0.938630264])

In [32]:
Top10t = np.array([9.54E-05, 0.00805865, 0.01602185, 0.02398505, 0.03204905, 0.04001225, 0.04797545])

In [33]:
plt.figure(figsize=(10,6));
plt.scatter(Top10t,Top10V);
plt.xlim(0.0055,0.053);
plt.xticks(size=16);
plt.yticks(size=16);
plt.xlabel('Time (s)',size=15);
plt.ylabel('Pulse Height (V)',size=15);



In [34]:
def myfun(t,V_o,tau):
    ans =  V_o*np.exp(-t/tau)
    return ans

p0 = [5,0.020] #guess

xspace = np.linspace(0.0055,0.058) 

plsq, pcov = curve_fit(myfun, Top10t, Top10V, p0)  # curve fit returns p and covariance matrix
# these give the parameters and the uncertainties
V_o = plsq[0]
eV_o = np.sqrt(pcov[0,0])

tau = plsq[1]
etau = 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(Top10t,Top10V,marker='.',label='Data');
plt.xticks(size = 15);
plt.yticks(size = 15);


#plt.xlabel('Accelerating Voltage (V)',size=20);
#plt.ylabel('Current (pA)',size=20);

plt.plot(xspace,yfit,label='Fit');
#plt.text(7,9.1, '$V_{min} = %.1f \pm %.1f$ V' % (V_min, dV) ,size=20)

plt.xlim(0.0055,0.058);
plt.xticks(size=16);
plt.yticks(size=16);
plt.xlabel('Time (s)',size=15);
plt.ylabel('Pulse Height (V)',size=15);

plt.text(0.04,2.5, '$T2 = %.1f \pm %.1f$ $ms$' % (tau*1e3, etau*1e3) ,size=20)

plt.legend(loc='best');

plt.savefig('T2MineralOil.png')



In [ ]: