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
|
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
from scipy.signal import argrelextrema
data = pd.read_csv("C:\\Users\\Utilisateur général\\Desktop\\PI\\A1.csv")
col_names = ['time','amp']
data.columns = col_names
t = data.time
y = data.amp
L1=[]
L2=[]
Ly=[]
Lt=[]
x=np.zeros(len(y))
for i in range(len(y)):
x[i]=y[i]
c_max_index = argrelextrema(x, np.greater, order=10)
for i in range(np.size(c_max_index[0])):
if y[c_max_index[0][i]]>0.001:
L1.append(y[c_max_index[0][i]])
L2.append(t[c_max_index[0][i]])
for i in range(len(L1)):
if i<40:
Ly.append(L1[i])
Lt.append(L2[i])
else:
if L1[i]>0.002:
Ly.append(L1[i])
Lt.append(L2[i])
plt.scatter(Lt,Ly,c='r')
plt.plot(t,y)
plt.grid()
plt.ylim(0,0.02)
plt.show()
Lt=['time']+Lt
Ly=['amp']+Ly
indata = pd.read_csv("C:\\Users\\Utilisateur général\\Desktop\\A1n.csv")
zipped = pd.DataFrame(zip(Lt,Ly))
outdata = pd.concat([indata, zipped], axis=1)
outdata.to_csv("C:\\Users\\Utilisateur général\\Desktop\\PI\\A1n.csv", header=False, index=False, encoding='utf-8')
outdata2 = pd.read_csv("C:\\Users\\Utilisateur général\Desktop\\PI\\A1n.csv", usecols=[1,2])
outdata2.to_csv("C:\\Users\\Utilisateur général\\Desktop\\PI\\A1n.csv", index=False) |
Partager