In [1]:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline
In [2]:
##Loading the full saturated absorption spectrum data
df_ch1_full_sas = pd.DataFrame.from_csv("2017-09-26 Rb SAS full Ch1.csv")
df_ch2_full_sas = pd.DataFrame.from_csv("2017-09-26 Rb SAS full Ch2.csv")
In [3]:
##Plotting saturated absorption spectrum
plt.title("Voltage vs. Time, Saturdated Absorption Spectrum")
plt.plot(df_ch2_full_sas)
plt.ylabel("Voltage, V")
plt.xlabel("Time, s")
Out[3]:
In [4]:
##Loading in the data with the background subtracted to remove the Doppler Broadening
df_ch2_full_sas_no_doppler = pd.DataFrame.from_csv("2017-09-26 Rb SAS no doppler Ch2.csv")
In [5]:
##Plotting the saturated absorption spectrum with no doppler broadening
plt.title("Voltage vs. Time, Saturdated Absorption Spectrum")
plt.ylabel("Voltage, V")
plt.xlabel("Time, s")
plt.plot(df_ch2_full_sas_no_doppler)
Out[5]:
In [6]:
##Defining function to pull desired information from the data
def get_peak_data(array, plotrange):
peak = []
maximum = 0
maximum_loc = 0
for i in range(len(df_ch2_full_sas_no_doppler.index)):
if (df_ch2_full_sas_no_doppler.index[i] >= plotrange[0]) and (df_ch2_full_sas_no_doppler.index[i] <= plotrange[1]):
peak.append(x_peak_data[i])
if x_peak_data[i] >= maximum:
maximum = x_peak_data[i]
maximum_loc = df_ch2_full_sas_no_doppler.index[i]
print("Length of peak array data: {}".format(len(peak)))
print("Maximum found at: t = {}".format(maximum_loc))
print("Maximum value occurs at index: {}".format(np.argmax(peak)))
print("Maximum value: {}".format(np.max(peak)))
plt.plot(peak)
return peak
In [7]:
x_peak_data = df_ch2_full_sas_no_doppler['Voltage'].values
In [8]:
first_peak = get_peak_data(x_peak_data, [0,0.028])
In [9]:
second_peak = get_peak_data(x_peak_data, [0.028, 0.035])
In [10]:
third_peak = get_peak_data(x_peak_data, [0.035, 0.045])
In [11]:
fourth_peak = get_peak_data(x_peak_data, [0.045, 0.055])
In [12]:
plt.plot(0.0256, 7.44, 'pr')
plt.plot(0.0303, 5, 'pr')
plt.plot(0.0408, 8.12, 'pr')
plt.plot(0.049, 3.32, 'pr')
plt.plot(df_ch2_full_sas_no_doppler)
Out[12]:
In [13]:
from prettytable import PrettyTable
In [14]:
x = PrettyTable()
times = [0.0256, 0.0303, 0.0408, 0.049]
voltages = [7.44, 5, 8.12, 3.32]
x.add_column("Time (s)", times)
x.add_column("Voltage (V)", voltages)
x.add_column("Difference (s)", ["-", round(times[1]-times[0],5), round(times[2]-times[1],5), round(times[3]-times[2],5)])
print(x)
In [15]:
file = open('peaks_separation.txt', 'w')
file.write(x.get_string())
file.close()
In [ ]: