-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdetect_peaks.py
More file actions
107 lines (90 loc) · 4.59 KB
/
Copy pathdetect_peaks.py
File metadata and controls
107 lines (90 loc) · 4.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
from matplotlib import pyplot as plt
import peak_detection
import heatmaps_function
import numpy as np
'''
Import functions from peak_detection.py and heatmaps_function.py
INPUT:
CSV Text file of data (columns must correspond)
--> Must include(IN ORDER):
"Saturated Absorption", "NA", "Error", "NaN", "Voltage"
(1) Saturated Absorption
(2) Fabry Perot
(3) Error
(4) NaN (Fabry Perot?)
(5) Voltage
Note-- Fabry Perot is input in the line:
conv, q = heatmaps_function.fabry_perot_conversions(df["Fabry Perot"],df)
'''
#df = peak_detection.import_data("testScan.txt")
df = peak_detection.import_data("testScan_Test32_comb.txt")
# Imports the data from a CSV text file and returns it as a dataframe
filtered = peak_detection.butterworth_filter(df["Saturated Absorption"])
# Filters a signal using a butterworth filter returns the filtered signal
peaks, properties = peak_detection.find_saturated_abs_peaks(filtered)
# Finds the peaks in the saturated absorbtion data, returns an array of peak locations
peaks = peak_detection.shift(peaks)
# Shifts peaks by set value
possible_combos = peak_detection.generate_all_attempts(peaks)
# Generates all 5 inorder peak combinations form a set of input peaks
error = peak_detection.error_filter(df["Error"])
# Filter error signal. Takes in error signal and outputs the filtered signal
error_peaks, error_properties = peak_detection.find_error_peaks(error)
# Find how many transitions in an error signal
fp_peaks, conversions, converted_trap = heatmaps_function.fabry_perot_conversions(df["Fabry Perot"], df, possible_combos)
print("CONVERSIONS")
print(conversions)
# Takes fabry perot input data, finds free spectral range and converts the fsr from voltage to MHz/V.
# Ouputs MHz per voltage conversion factor as well as the 10MHz conversion for trap transition tuning.
for i in range(len(possible_combos)):
print("Element in possible peak list: %.0f"%i)
peak_freq = heatmaps_function.raw_to_frequency_coords(possible_combos[i],conversions[i],df)
# Convert raw coordinates to corresponding voltage values in dataframe. Outputs voltage of each peak, from raw input.
peak_freq, Rb87t_perc, Rb87p_perc, Rb85t_perc, Rb85_perc = heatmaps_function.frequency_percent_difference(peak_freq)
# Ouputs frequency data percent difference corresponding to the known values of the respective peaks. With first peak at zero.
interval = heatmaps_function.frequency_intervals(peak_freq) # interval_col also stored
# Outputs the frequency interval between peaks.
Rb87t_pint, Rb87p_pint, Rb85t_pint, Rb85_pint = heatmaps_function.interval_percent_difference(interval)
# Outputs the data intervals between peaks percent difference with respect to the known data values.
transition = heatmaps_function.lowest_perc_diff(Rb87t_perc, Rb87p_perc, Rb85t_perc, Rb85_perc,Rb87t_pint, Rb87p_pint, Rb85t_pint, Rb85_pint)
# Outputs the transition.
heatmaps_function.percent_diff_heatmap(Rb87t_perc,Rb87p_perc,Rb85t_perc,Rb85_perc)
# Percentage Heat Map (difference from transition)
heatmaps_function.percent_int_heatmap(Rb87t_pint,Rb87p_pint,Rb85t_pint,Rb85_pint)
# Interval Percentage Heat Map
error_idx = peak_detection.get_thumb(possible_combos[i])
error_value = df["Voltage"][error_idx]
print("Error: ",error_value, "V")
print("Error_Index: ",error_idx)
#%% Plots
# plt.plot(error)
# plt.plot(df["Saturated Absorption"], 'g')
#plt.plot(error_peaks, error[error_peaks], "o")
# plt.plot(peaks, df["Saturated Absorption"][peaks], "rx")
#plt.plot(fp_peaks, df["Fabry Perot"][fp_peaks], "rx")
df.plot(x = "Voltage", y = "Saturated Absorption", legend=False, color = "g")
plt.plot(df["Voltage"],error)
#plt.plot(df["Voltage"][error_peaks], error[error_peaks], "o")
plt.plot(df["Voltage"][333], error[333], "ro")
#plt.plot(df["Voltage"][error_idx], error_value, "ro")
plt.plot(df["Voltage"][peaks], df["Saturated Absorption"][peaks], "rx")
#plt.plot(df["Fabry Perot"][fp_peaks], "rx")
plt.title("Trap Transition")
plt.xlabel("Voltage [V]")
plt.ylabel("Signal Voltage [V]")
plt.legend(["Saturated Absorption", "Error Signal"])
plt.grid()
plt.hlines(0,-10,-.4,"r")
plt.xlim(-10, -.4)
plt.xticks(np.arange(-10, -.4, step=1))
plt.show()
df.plot(x = "Voltage", y = "Fabry Perot", legend=False)
plt.plot(df["Voltage"][fp_peaks], df["Fabry Perot"][fp_peaks], "rx")
#plt.plot(df["Fabry Perot"][fp_peaks], "rx")
plt.title("Fabry Perot")
plt.xlabel("Voltage [V]")
plt.ylabel("Signal Voltage [V]")
plt.grid()
plt.xlim(-10, -.4)
plt.xticks(np.arange(-10, -.4, step=1))
plt.show()