Commit 4dfc2d03 authored by MEULE Samuel's avatar MEULE Samuel
Browse files

Mise en place sous gitlab.osupytheas.fr

# Historique
* [X] Ajout d'un debut de script TD7 (a remplir) + ajout des fichiers 2 à 10.txt (différentes series temporelles)
* [X] Ajout des notebooks TD2 à TD8 + ajout des fichiers
* [X] Ajout de requirements.txt pour gestion des dépendances
* [X] Ajout du fichier .py et du notebook jupyter .ipynb pour TD1
* [X] Création d'un git pour Stat
parent 36c7f9f4
......@@ -18,7 +18,6 @@ t = np.arange(0, Tmax, Te) # Time vector
# Functions
u1=0.5*1.0*np.cos(2*np.pi*f1*t)
u2=0.3*np.cos(2*2*np.pi*f1*t-np.pi/3)
u=u1+u2
# Figure
......@@ -37,6 +36,6 @@ plt.grid()
# Save the figure
fig1.savefig('Figure_TD1',dpi=200)
# Show the figure
plt.show()
#!/usr/bin/python
# coding: utf-8
#################################################"
## MODULES #####"
#################################################"
import matplotlib.pyplot as plt
import numpy as np
#################################################"
# Parameters
N = 500 # Number of sampling
Tmax = 2.0 # Max time
Te = Tmax/N # Delta time between each measurements
f1=1 # Acquisition frequency
t = np.arange(0, Tmax, Te) # Time vector
# Functions
u1=0.5*1.0*np.cos(2*np.pi*f1*t)
u2=0.3*np.cos(2*2*np.pi*f1*t-np.pi/3)
u=u1+u2
# fft analysis
Puu=np.abs(np.fft.fft(u,N)/N)**2 # Density spectrum
freqs=np.linspace(0,1/Te,len(Puu)) # frequencies
# Figure
fig1=plt.figure(figsize=(10,5))
plt.plot(freqs,Puu, 'ko-', label='u')
plt.axis([0,11,0,0.1])
plt.xlabel("Frequency (Hz)")
plt.ylabel("Power spectrum")
plt.grid()
plt.show()
# Save the figure
fig1.savefig('Figure_TD2',dpi=200)
#!/usr/bin/python
# coding: utf-8
#################################################"
## MODULES #####"
#################################################"
import matplotlib.pyplot as plt
import numpy as np
#################################################"
# Parameters
N = 500 # Number of sampling
Tmax = 2.0 # Max time
Te = Tmax/N # Delta time between each measurements
f1=1 # Acquisition frequency
t = np.arange(0, Tmax, Te) # Time vector
# Functions
u1=2*1.0*np.cos(2*np.pi*f1*t)
u2=2*np.cos(2*2*np.pi*f1*t-np.pi/3)
u=u1+u2
# Analyse statistique
nbrv=(np.diff(np.sign(u)) < 0).sum()# Nbr d'oscillations
hist, bin_edges = np.histogram(u, bins=20) #Fonction de repartition des hauteurs de vagues.
X = np.sort(u)
F = np.array(range(N))*100/float(N)
H13=np.mean(X[np.where(F>66)]) # Calcul de la moyenne du tiers superieur des oscillations
fu=np.where((np.diff(np.sign(u)) < 0))
Tm=np.mean(np.diff(fu))*Te # Calcul de la periode moyenne
# Figure
fig1=plt.figure(figsize=(10,5))
plt.bar(bin_edges[:-1], hist, width=bin_edges[1]-bin_edges[0], color='red', alpha=0.5, label='Histogramm')
plt.plot(X, F, label=u'cumulative frequency')
plt.xlabel("oscillation amplitude")
plt.ylabel(u"Probability")
titre='Amplitude histogram: H1/3=' + str(np.around(H13,2))+'; Tm='+str(np.around(Tm,2))
plt.title(titre)
plt.legend()
plt.grid()
plt.ylim(0,100)
plt.show()
# Save the figure
fig1.savefig('Figure_TD3',dpi=200)
#!/usr/bin/python
# coding: utf-8
#################################################"
## MODULES #####"
#################################################"
import matplotlib.pyplot as plt
import numpy as np
#################################################"
# Parameters
N = 1000 # Number of sampling
Tmax = 4.0 # Max time
Te = Tmax/N # Delta time between each measurements
f1=1 # Acquisition frequency (Hz)
t = np.arange(0, Tmax, Te) # Time vector
# Functions
u1=0.5*np.cos(1*2*np.pi*f1*t)
u2=0.3*np.cos(2*2*np.pi*f1*t-np.pi/3)
u=u1+u2
# fft analysis
y=np.fft.rfft(u,N)/N # Fast Fourier Transform
a0=2*y[0].real # Fourier coeff a0
a=2*y.real # Fourier coeff a
b=-2*y.imag # Fourier coeff b
# Rebuilding the harmonics
n=1 # Number of harmonics
m=int(Tmax)*f1*n
v1=a[m]*np.cos(2*np.pi*f1*t)+b[m]*np.sin(2*np.pi*f1*t)
#
n=2 # Number of harmonics
m=int(Tmax)*f1*n
v2=a[m]*np.cos(n*2*np.pi*f1*t)+b[m]*np.sin(n*2*np.pi*f1*t)
#
v=a0+v1+v2
# Figure
fig1=plt.figure(figsize=(10,5))
#plt.hold(True)
plt.plot(t,u, 'r--', label='u')
plt.plot(t,u1, 'y--', label='u1')
plt.plot(t,u2, 'g--', label='u2')
plt.plot(t,v, 'ro', label='v')
plt.plot(t,v1, 'yo', label='v1')
plt.plot(t,v2, 'go', label='v2')
plt.legend()
plt.xlabel("t")
plt.ylabel("f(t)")
#plt.axis([0,2,-2,2])
plt.grid()
plt.show()
# Save the figure
fig1.savefig('Figure_TD3',dpi=200)
#!/usr/bin/python
# coding: utf-8
#################################################"
## MODULES #####"
#################################################"
import matplotlib.pyplot as plt
import numpy as np
#################################################"
# Parameters
N = 1000 # Number of sampling
Tmax = 4.0 # Max time
Te = Tmax/N # Delta time between each measurements
f1=1 # Acquisition frequency (Hz)
t = np.arange(0, Tmax, Te) # Time vector
n=4 # Number of harmonics
# Functions
u1=0.5*np.cos(1*2*np.pi*f1*t)
u2=0.3*np.cos(2*2*np.pi*f1*t-np.pi/3)
u3=0.5*np.cos(3*2*np.pi*f1*t+np.pi/3)
u4=0.1*np.cos(4*2*np.pi*f1*t)
u=u1+u2+u3+u4
# fft analysis
y=np.fft.fft(u) #Fast Fourier Transform
# order of the filtering
m=int(Tmax)*f1*n+1
y[m:-m]=0
# Reverse fft and normalize
Y=np.fft.ifft(y)
Y=Y.real
# Figure
fig1=plt.figure(figsize=(10,5))
plt.plot(t, Y, 'k.', label='filtered dataset')
plt.plot(t,u, 'r--', label="Original dataset")
plt.legend()
plt.xlabel("t")
plt.ylabel("u")
plt.show()
# Save the figure
fig1.savefig('Figure_TD5',dpi=200)
#!/usr/bin/python
# coding: utf-8
#################################################"
## MODULES #####"
#################################################"
import matplotlib.pyplot as plt
import numpy as np
#################################################"
n=500 # Number of harmonics
# Read ascii file
filename='fichier10.txt'
with open(filename, 'r') as f:
lines=f.readlines()
t=[]
u=[]
for l in lines:
value=l.strip().split("\t")
t.append(float(value[0])) # Read the first column: time t
u.append(float(value[1])) # Read the second column: function u
t=np.array(t)
u=np.array(u)
# Parameters
f1=1
N=len(t)
Tmax=np.round(max(t))
# fft analysis
y=np.fft.fft(u) #Fast Fourier Transform
# order of the filtering
m=int(Tmax)*f1*n+1
y[m:-m]=0
# Reverse fft and normalize
Y=np.fft.ifft(y)
Y=Y.real
# Figure
fig1=plt.figure(figsize=(10,5))
plt.plot(t,u, 'r--', label="Original dataset")
plt.plot(t, Y, 'k', label='filtered dataset')
plt.legend()
plt.grid()
plt.show()
# Save the figure
fig1.savefig('Figure_TD6',dpi=200)
#!/usr/bin/python
# coding: utf-8
#################################################"
## MODULES #####"
#################################################"
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
#################################################"
n=1 # Number of harmonics
# Read ascii file
filename1='fichier21.txt'
filename2='fichier22.txt'
t= pd.read_table(filename1, delim_whitespace=True)
u= pd.read_table(filename2, delim_whitespace=True)
t=t.values
u=u.values
t=np.reshape(t, [41*12])
u=np.reshape(u, [124*4])
#u=u[np.where(np.isnan(u)==True)]
t=t[0:488]
u=u[0:488]*np.cos(3*np.pi*t)-0.4
plt.plot(t,u, '.')
df = pd.DataFrame()
df['t']=t
df['u']=u
df.to_csv('fichier10.txt', sep='\t', index=False, header=False)
#!/usr/bin/python
# coding: utf-8
#################################################"
## MODULES #####"
#################################################"
from scipy.signal import detrend
import matplotlib.pyplot as plt
import matplotlib.dates as dt
from datetime import datetime
import scipy.io as scio
import pandas as pd
import numpy as np
import os as os
#####################################################################################################
def load_wisens(filename):
""" Load a ascii file from a wisens NKE"""
[adr, ext]=os.path.splitext(os.path.basename(filename))
# open
rawdata=pd.read_csv(filename, skiprows=1,sep='\t',names=['DateTime', 'Temp', 'Pressure'])
Date=[]
# Datetime manipulation
dateheure=rawdata.DateTime.values
for l in dateheure:
temp=(datetime.strptime(l,'%Y-%m-%d %H:%M:%S.%f'))
T=dt.date2num(temp)
Date.append(T)
#Output
Date=np.array(Date)
Temperature=np.array(rawdata.Temp)
Pressure=np.array(rawdata.Pressure)
print ('-----------------------------------------------')
print ('Lecture ', adr, '............OK')
print ('-----------------------------------------------')
return Date, Temperature, Pressure
#
###
# # #
#
#
##########################################################################################################################################################
#
#
# # #
###
#
##########################################################
### OPEN FILE ###
##########################################################
filename='4292_data_20190118_095748.csv'
# Load file
Date, Temperature, Pressure= load_wisens(filename) # Pressure in dbar
##########################################################
### PROCESS ###
##########################################################
# Figure
fig0=plt.figure(figsize=(10,5))
plt.plot(Date,Pressure, 'r--', label="Original dataset")
date_format = dt.DateFormatter('%d %H:%M')
plt.gca().xaxis.set_major_formatter(date_format)
plt.legend()
plt.grid()
# Save the figure
fig0.savefig('Série temporelle',dpi=200)
n1=7241
n2=42322
u=Pressure[n1:n2]
#####################"
# Parameters
N = n2-n1 # Number of sampling, il faut vérifier le nombre de donnée
Te = 0.1 # Delta time between each measurements
# et l'analyse statistique
nbrv=(np.diff(np.sign(u)) < 0).sum()# Nbr d'oscillations
hist, bin_edges = np.histogram(u, bins=20) #Fonction de repartition des hauteurs de vagues.
X = np.sort(u)
F = np.array(range(N))*100/float(N)
H13=np.mean(X[np.where(F>66)]) # Calcul de la moyenne du tiers superieur des oscillations
fu=np.where((np.diff(np.sign(u)) < 0))
Tm=np.mean(np.diff(fu))*Te # Calcul de la periode moyenne
# Figure
fig1=plt.figure(figsize=(10,5))
plt.bar(bin_edges[:-1], hist*100/max(hist), width=bin_edges[1]-bin_edges[0], color='red', alpha=0.5, label='Histogramm')
plt.plot(X, F, label=u'cumulative frequency')
plt.xlabel("oscillation amplitude")
plt.ylabel(u"Probability")
titre='Amplitude histogram: H1/3=' + str(np.around(H13,2))+'; Tm='+str(np.around(Tm,2))
plt.title(titre)
plt.legend()
plt.grid()
plt.ylim(0,100)
# Save the figure
fig1.savefig('analyse statistique',dpi=200)
# et maintenant une analyse spectrale
# fft analysis
Puu=np.abs(np.fft.rfft(u,N)/(N/2)) # Density spectrum
fa=1/Te
freqs=np.linspace(0,fa/2,int(np.ceil(N/2)))
### Spectral analysis
## Pxx=np.abs(np.fft.rfft(X2,N)/(N/2))
## a,N2=np.shape(Pxx)
## freqs=np.linspace(0,fa/2,N2)
## df=freqs[1]-freqs[0]
# Figure
fig1=plt.figure(figsize=(10,5))
plt.plot(freqs,Puu, 'ko-', label='u')
#plt.axis([0,10,0,2]) # Je change ici l'axe des abscisses pour voir ou il y a de l'énergie spectrale
# On en voit un peu partout mais de faible énergie.
# Tout semble être largement concentré sur les basses fréquences
plt.xlabel("Frequency (Hz)")
plt.ylabel("Power spectrum")
plt.grid()
# Save the figure
fig1.savefig('Analyse spectrale',dpi=200)
#########################
# Maintenant reconstruisons un signal
localisation=np.where(freqs>0.3)
Puu[localisation]=0
# Reverse fft and normalize
Y=np.fft.irfft(Puu)*N/2
# Figure
fig1=plt.figure(figsize=(10,5))
plt.plot(Date[n1:n2],u, 'r--', label="Original dataset")
plt.plot(Date[n1:n2-1], Y, 'k.', label='filtered dataset')
plt.legend()
plt.grid()
plt.show()
# Save the figure
fig1.savefig('Reconstruction',dpi=200)
#
###
# # #
#
#
##########################################################################################################################################################
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment