-
Notifications
You must be signed in to change notification settings - Fork 0
/
Joy_Division_Plot_5th_Degree_Polynomial_Fit.py
52 lines (40 loc) · 1.72 KB
/
Joy_Division_Plot_5th_Degree_Polynomial_Fit.py
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Jul 7 2022
@author: cloealcaria
"""
import pandas as pd
import tkinter
import matplotlib
matplotlib.use("TkAgg")
import matplotlib.pyplot as plt
import numpy as np
from scipy.optimize import curve_fit
data = pd.read_csv('attempt_new.txt',sep='\s+',header=None) # this is the data corresponding to the .tim timeseries file, converted to txtto be able to use it here
data = pd.DataFrame(data)
data.columns = ['time', 'amp']
array_data = data.to_numpy()
peaks_data = pd.read_csv('attempt_new.pls',sep='\s+',header=None)
peaks_data = pd.DataFrame(peaks_data)
peaks_data.columns = ['DM', 'width', 'sample_num', 'SNR', 'pow2']
array_peaks = peaks_data.to_numpy()
peak_bins = array_peaks[:,2]
peak_bins = peak_bins.tolist()
side_width = 500
def objective(x, a, b, c, d, e, f): # define the true objective function
return (a * x) + (b * x**2) + (c * x**3) + (d * x**4) + (e * x**5) + f
plt.figure(figsize=(5,20))
plt.rcParams['axes.facecolor'] = 'black'
for i in peak_bins:
start = int(i) - side_width
end = int(i) + side_width
y = array_data[start:end,1] / 1e7
x = np.arange(0,len(array_data[start:end,1]))
popt, _ = curve_fit(objective, x, y) # curve fit
a, b, c, d, e, f = popt # summarize the parameter values
x_line = np.arange(min(x), max(x), 1) # define a sequence of inputs between the smallest and largest known inputs
y_line = objective(x_line, a, b, c, d, e, f) # calculate the output for the range
plt.plot(x_line, y_line - .1 * peak_bins.index(i), '-', color='w',zorder=1 + 1 * peak_bins.index(i), linewidth=3)
plt.fill_between(x_line, y_line - .1 * peak_bins.index(i), -9.15 , color='k', zorder=2 + 1 * peak_bins.index(i))
plt.show()