Commit 289444d0 authored by Philippe Després's avatar Philippe Després

progress

parent be6617c9
......@@ -251,6 +251,98 @@
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Lecture de fichiers plus complexes"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"LabVIEW Measurement \n",
"Writer_Version 2\n",
"Reader_Version 2\n",
"Separator Tab\n",
"Decimal_Separator .\n",
"Multi_Headings No\n",
"X_Columns No\n",
"Time_Pref Absolute\n",
"Operator phdes19\n",
"Description Lab1\n",
"Date 2017/01/17\n",
"Time 10:29:25.3080300833532626614\n",
"***End_of_Header*** \n",
" \n",
"Channels 1 \n",
"Samples 10 \n",
"Date 2017/01/17 \n",
"Time 10:29:25.3080300833532626614 \n",
"Y_Unit_Label Volts \n",
"X_Dimension Time \n",
"X0 0.0000000000000000E+0 \n",
"Delta_X 0.100000 \n",
"***End_of_Header*** \n",
"X_Value Voltage Comment\n",
" 106.54818307898867\n",
" 104.54570150287036\n",
" 101.42198284739723\n",
" 107.90575575999935\n",
" 103.29030441443832\n",
" 88.44025801262951\n",
" 92.56747892817509\n",
" 86.93684957515455\n",
" 92.91979104466311\n",
" 94.6919990897716\n",
" 87.49432090776641\n",
" 92.9783986203956"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Écriture d'un script qui permettra de lire les informations contenues dans ce fichier et de les afficher"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"# programme qui prend un fichier LVM \n",
"# en argument et qui en fait un histogramme \n",
"# (une seule colonne de mesures) \n",
"\n",
"import matplotlib.pyplot as plt #matplotlib \n",
"import numpy as np #numpy \n",
"import sys #système et fichiers \n",
"from scipy.stats import norm #pour distribution normale \n",
"\n",
"file_in=\"Labo1_output.lvm\"\n",
"\n",
"#ouverture du fichier (structure LVM) \n",
"with open(file_in,'r') as f:\n",
" for line in f:\n",
" val=line.strip().split() #enlève les espaces avant/après et tokenize \n",
" if not val: #saute lignes vide \n",
" continue\n",
" if(val[0]==\"Y_Unit_Label\"):\n",
" xtitle=val[1] #récupère les unités \n",
" if(val[0]==\"X_Value\"): #on commence à lire les valeurs \n",
" nb_mesures=0\n",
" x=[]\n",
" for line_tmp in f:\n",
" x.append(float(line_tmp.replace(\",\",\".\").strip())) #liste de valeur \n",
" nb_mesures+=1\n",
"f.close() #fermeture fichier "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
......
#!/usr/bin/env python
# programme qui prend un fichier LVM
# en argument et qui en fait un histogramme
# (une seule colonne de mesures)
import matplotlib.pyplot as plt #matplotlib
import numpy as np #numpy
import sys #système et fichiers
from sys import argv #système et fichiers
from scipy.stats import norm #pour distribution normale
#vérification si l'usager a passé un argument au programme
if(len(sys.argv)!=2):
print("Usage: "+sys.argv[0]+" [fichier]")
sys.exit()
if(len(argv)!=2):
print("Usage: "+argv[0]+" [fichier]")
exit()
file_in=argv[1] #nom du fichier à traiter
x=[] #liste vide
#ouverture du fichier passé en argument (structure LVM)
with open(sys.argv[1],'r') as f:
with open(file_in,'r') as f:
for line in f:
val=line.strip().split() #enlève les espaces avant/après et tokenize
if not val: #saute lignes vide
......@@ -21,18 +25,25 @@ with open(sys.argv[1],'r') as f:
if(val[0]=="Y_Unit_Label"):
xtitle=val[1] #récupère les unités
if(val[0]=="X_Value"): #on commence à lire les valeurs
nb_mesures=0
x=[]
for line_tmp in f:
x.append(float(line_tmp.replace(",",".").strip())) #liste de valeur
nb_mesures+=1
f.close() #fermeture fichier
#création array numpy
volts=np.array(x)
print(str(nb_mesures)+" mesures lues")
print(str(len(x))+" mesures lues")
# deux graphiques côte à côte
f = plt.figure(figsize=(10,4))
fig1 = f.add_subplot(121)
fig2 = f.add_subplot(122)#time series
xtime=np.linspace(1,len(x),len(x))
fig1.plot(xtime,volts)
fig1.set_ylabel(xtitle)
fig1.set_xlabel("no. mesure")
#fit distribution normale
mu,std=norm.fit(volts)
# axes des x pour fit
......@@ -41,21 +52,18 @@ xlin = np.linspace(volts.min(),volts.max(), 100)
p = norm.pdf(xlin, mu, std)
#histogram
n, bins, patches = plt.hist(volts, 20, range=[volts.min(),volts.max()], normed=1, facecolor='green', alpha=0.75)
n, bins, patches = fig2.hist(volts, 20, range=[volts.min(),volts.max()], density=1, facecolor='green', alpha=0.75)
#graph distribution normale
plt.plot(xlin, p, 'k', linewidth=2, label=r"$\mu$: "+str("{:.2f}".format(mu))+r" $\sigma$: "+str("{:.2f}".format(std)))
plt.xlabel(xtitle)
plt.ylabel('Fréquence')
plt.title(str(nb_mesures)+" mesures")
plt.legend()
plt.grid(True)
fig2.plot(xlin, p, 'k', linewidth=2, label=r"$\mu$: "+str("{:.2f}".format(mu))+r" $\sigma$: "+str("{:.2f}".format(std)))
fig2.set_xlabel(xtitle)
fig2.set_ylabel('Fréquence')
fig2.set_title(str(len(x))+" mesures")
fig2.legend()
fig2.grid(True)
#plt.tight_layout()
plt.show()
#time series
plt.figure()
xtime=np.linspace(1,nb_mesures,nb_mesures)
plt.plot(xtime,volts)
plt.ylabel(xtitle)
plt.xlabel("no. mesure")
plt.show()
Markdown is supported
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