scientific_comp_projects/CODE/[python]thesis_old_scripts/tracer_courbe_from_rheometr...

100 lines
4.0 KiB
Python

# -*- coding: utf-8 -*-
"""
Created on Tue Mar 20 11:12:53 2018
@author: Armando
This python script is used to graph the courbe from the csv files obtained from Anton Paars Rheometre
Only take into account the values that have "TruStrain™" and hence, that are correct
"""
import csv
import codecs
#Type of writing to call custom programs saved in my_py
import matplotlib.pyplot as plt
"""Path to the folder where the csv file is"""
path = "C:\\Users\\Armando\\Desktop\\These\\Tests\\Visco-elasticite\\Test_Visco-elasticite-28.11.2017\\"
"""Here you need to declare the csv file to use ! """
#'\t' is the tabulation value
rdr = csv.reader(codecs.open(path + "Test_Visco-elasticite-28_11_2017-XG50ppm 1.csv",'rU','utf-16'), dialect='excel',delimiter = '\t')
"""Here you declare the columns you want to take to the plot"""
column_for_abscisse = 1 #Declare column for the abscisse
column_for_ordonnee = 4 #Declare column for the ordonnee
nbr_of_experiments =6 #Declare the total number of experiment and hence of graphs to do
"""Normally this dont change as long as the same Anton Paars rheometer is used. If it is not the case you may need to change some values"""
nbr_of_lignes_per_experiment = 22 #Total number of lines the experiment data takes (this includes the data in itself but also the titles and everyother info)
lines_unites_data = 5 #This are the lines you need to skip before you get to the chart really starts (the real data). Normally this line is the heading of the chart
line_of_title = 0 #This is the line in which the title of the graph is obtained
line_of_type_experience = 1 #This is the line that have the type of experiment realized
line_parameter_name = 3 #This is where the axes of the names are obtained
"""These are the variables to store the values obtained from csv file and to make code work (dont touch unless you know what you are doing)"""
x = []
y = []
x_values = []
y_values =[]
titre_experience = []
i = -1
for e in range(0,nbr_of_experiments,1):
lignes_to_jump = e*nbr_of_lignes_per_experiment
i = lignes_to_jump-1
for row in rdr:
i = i+1
if ((i>(lines_unites_data+lignes_to_jump)) and (row[0] != '') and (row[8]=='TruStrain™')): #Added a TruStrain™ to account for true data only
x.append(float(row[column_for_abscisse].replace(',','.'))) #Here we use replace function because rheometer creates
y.append(float(row[column_for_ordonnee].replace(',','.'))) #a csv file that separates by commas the decimals
# ligne = row
# print(ligne)
# break
# print("%5.lf %5.lf" % (x[-1],y[-1]))
elif (i==(line_of_title + lignes_to_jump)):
titre_experience.append(row[1])
elif (i== (line_of_type_experience + lignes_to_jump)):
type_experience = row[1]
elif (i==(line_parameter_name)):
titre_x = row[column_for_abscisse]
titre_y = row[column_for_ordonnee]
elif (i== (lines_unites_data)):
unites_x = row[column_for_abscisse]
unites_y = row[column_for_ordonnee]
elif ((i>(lines_unites_data+ lignes_to_jump)) and (row[0] == '')):
x_values.append(x)
y_values.append(y)
x = []
y = []
break
l_plot=[]
plt.xscale('log')
plt.title(titre_experience[0] + type_experience)
plt.xlabel(titre_x + unites_x, color='C1')
plt.ylabel(titre_y + unites_y, color='0.5') # grayscale color
plt.grid(b=True, which='major', color='k', linestyle='-')
plt.grid(b=True, which='minor', color='k', linestyle='--')
print(range(len(y_values)))
for i in range(len(y_values)):
l_plot.append(plt.plot(x_values[i],y_values[i],'.-',label="%s " % (titre_experience[i],)))
#"%s " % (
plt.legend()
plt.show()