In [1]:
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
In [2]:
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 [3]:
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 [18]:
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.xlabel('Delay Time (ms)',size=20);
plt.ylabel('FID Amplitude (V)', size = 20);
plt.savefig('T1Fit.png')
In [5]:
import heapq
In [6]:
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 [7]:
TopV
Out[7]:
In [8]:
TopTimes
Out[8]:
In [9]:
Top10V = np.array([2.8140698, 2.492461823, 2.25125584, 2.010049857, 1.849245869, 1.68844188, 1.527637891])
Top10V
Out[9]:
In [10]:
Top10t = np.array([0.0075994, 0.0151594, 0.0228202, 0.0303802, 0.038041, 0.045601, 0.053161])
Top10t
Out[10]:
In [11]:
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 [12]:
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 [13]:
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 [14]:
Top10V = np.array([4.11451022, 3.27028896, 2.46626872, 1.86325354, 1.54164544, 1.22003735, 0.938630264])
In [15]:
Top10t = np.array([9.54E-05, 0.00805865, 0.01602185, 0.02398505, 0.03204905, 0.04001225, 0.04797545])
In [16]:
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 [17]:
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 [ ]: