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]:
<matplotlib.text.Text at 0x118aee748>

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]:
[<matplotlib.lines.Line2D at 0x118b4c048>]

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])


Length of peak array data: 2310
Maximum found at: t = 0.0256
Maximum value occurs at index: 1697
Maximum value: 7.44

In [9]:
second_peak = get_peak_data(x_peak_data, [0.028, 0.035])


Length of peak array data: 1775
Maximum found at: t = 0.0303
Maximum value occurs at index: 596
Maximum value: 5.0

In [10]:
third_peak = get_peak_data(x_peak_data, [0.035, 0.045])


Length of peak array data: 2525
Maximum found at: t = 0.0408
Maximum value occurs at index: 1469
Maximum value: 8.12

In [11]:
fourth_peak = get_peak_data(x_peak_data, [0.045, 0.055])


Length of peak array data: 2525
Maximum found at: t = 0.049
Maximum value occurs at index: 1017
Maximum value: 3.32

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]:
[<matplotlib.lines.Line2D at 0x11941aa90>]

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)


+----------+-------------+----------------+
| Time (s) | Voltage (V) | Difference (s) |
+----------+-------------+----------------+
|  0.0256  |     7.44    |       -        |
|  0.0303  |      5      |     0.0047     |
|  0.0408  |     8.12    |     0.0105     |
|  0.049   |     3.32    |     0.0082     |
+----------+-------------+----------------+

In [15]:
file = open('peaks_separation.txt', 'w')
file.write(x.get_string())
file.close()

In [ ]: