Skip to content

Commit

Permalink
version 1.3 simplification du code + ajout defilement des spectres et…
Browse files Browse the repository at this point in the history
… affichage nom
  • Loading branch information
YLefrais committed Nov 6, 2020
1 parent 754a24d commit 85b8bb3
Show file tree
Hide file tree
Showing 8 changed files with 741 additions and 737 deletions.
22 changes: 11 additions & 11 deletions LIBStick.ini
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
[LIBStick_traitement]
rep_travail_L_trait = /home/yannick/Bureau/LIBS/Scripts_divers_pour_LIBS/Fluorose_LIBS
rep_travail_L_trait = /home/yannick/Bureau/LIBS/Scripts_divers_pour_LIBS

[LIBStick_extraction]
flag_zone2_L_ext = 1
flag_2D_L_ext = 0
flag_3D_L_ext = 0
flag_image_brute_L_ext = False
borne_zone1_inf_L_ext = 528.0
borne_zone1_sup_L_ext = 543.0
borne_zone2_inf_L_ext = 580.0
borne_zone2_sup_L_ext = 608.0
rep_travail_L_ext = /home/yannick/Bureau/LIBS/Scripts_divers_pour_LIBS/Fluorose_LIBS
borne_zone1_inf_L_ext = 200.0
borne_zone1_sup_L_ext = 607.0
borne_zone2_inf_L_ext = 609.0
borne_zone2_sup_L_ext = 1000.0
rep_travail_L_ext = /home/yannick/Bureau/LIBS/Scripts_divers_pour_LIBS/Silex_LIBS/A5/zone1

[LIBStick_compare]
flag_denominateur_L_comp = 1
Expand All @@ -19,9 +19,9 @@ flag_3D_L_comp = 0
flag_traitement_L_comp = 1
flag_stat_L_comp = 1
type_extension_L_comp = *.mean
borne_zone1_inf_L_comp = 529.0
borne_zone1_sup_L_comp = 534.0
borne_zone2_inf_L_comp = 534.7
borne_zone2_sup_L_comp = 535.8
rep_travail_L_comp = /home/yannick/Bureau/LIBS/Scripts_divers_pour_LIBS/Fluorose_LIBS
borne_zone1_inf_L_comp = 218.4
borne_zone1_sup_L_comp = 500.0
borne_zone2_inf_L_comp = 410.0
borne_zone2_sup_L_comp = 600.0
rep_travail_L_comp = /home/yannick/Bureau/LIBS/Scripts_divers_pour_LIBS/Silex_LIBS/A5/zone1

733 changes: 425 additions & 308 deletions LIBStick.py

Large diffs are not rendered by default.

107 changes: 29 additions & 78 deletions LIBStick_comp_spectres.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,91 +9,36 @@
import numpy,os,pandas
import matplotlib.pyplot as plt
import mpl_toolkits.mplot3d as plt3d
import LIBStick_outils

limites_zone1=[534.5 , 535.8]
limites_zone2=[528.0 , 543.0]
limites_spectre=[528.0, 543.0]

###############################################################################
# 1- fonction qui liste des fichiers *.mean d'un répertoire
# fonctions création tableaux et DataFrame
###############################################################################
def repertoire_de_travail(rep_script,rep_travail_relatif):
rep_travail=rep_script+"/"+rep_travail_relatif
return rep_travail

def creation_liste_fichiers(rep_travail,type_fichier):
os.chdir(rep_travail)
liste=[]
if type_fichier == ".mean" :
for fichier in os.listdir():
if (os.path.isfile(fichier) and fichier[-4:] == "mean") :
liste.append(fichier)
if type_fichier == ".tsv" :
for fichier in os.listdir():
if (os.path.isfile(fichier) and fichier[-3:] == "tsv") :
liste.append(fichier)
if type_fichier == ".asc" :
for fichier in os.listdir():
if (os.path.isfile(fichier) and fichier[-3:] == "asc") :
liste.append(fichier)
liste.sort()
return liste

def lit_spectre(fichier,type_fichier):
if type_fichier == ".mean" :
spectre=numpy.loadtxt(fichier,delimiter="\t",dtype=float,encoding="Latin-1")
if type_fichier == ".tsv" :
spectre=numpy.loadtxt(fichier,delimiter="\t",dtype=float,encoding="Latin-1")
if type_fichier == ".asc" :
document=numpy.loadtxt(fichier,delimiter="\t",skiprows=64, usecols=[0,1],dtype=float,encoding="Latin-1")
spectre=numpy.zeros((0,2))
for ligne in document :
if (ligne[0]<=1013) :
spectre=numpy.row_stack((spectre,ligne))
return spectre

def creer_tableau(liste,type_traitement):
# if type_traitement == "Echantillons différents" :
def creer_tableau_avec_x(liste,type_traitement): # données en colonnes
if type_traitement == 0 : # On ne normalise pas les spectres
i=0
for nom_fichier in liste :
if i==0 :
fichier_entree=numpy.loadtxt(nom_fichier, delimiter="\t")
tableau_abscisses=fichier_entree[:,0]
tableau_comparatif=numpy.zeros((0,fichier_entree.shape[0]))
tableau_comparatif=numpy.row_stack((tableau_comparatif,fichier_entree[:,1]))
else :
fichier_entree=numpy.loadtxt(nom_fichier, delimiter="\t")
tableau_comparatif=numpy.row_stack((tableau_comparatif,fichier_entree[:,1]))
i=i+1
# if type_traitement == "Même échantillon" :
tableau=LIBStick_outils.creer_tableau_avec_x_colonne1(liste)
if type_traitement == 1 : # On normalise tous les spectres
i=0
for nom_fichier in liste :
if i==0 :
fichier_entree=numpy.loadtxt(nom_fichier, delimiter="\t")
tableau_abscisses=fichier_entree[:,0]
tableau_comparatif=numpy.zeros((0,fichier_entree.shape[0]))
tableau_comparatif=numpy.row_stack((tableau_comparatif,fichier_entree[:,1]))
else :
fichier_entree=numpy.loadtxt(nom_fichier, delimiter="\t")
tableau_comparatif=numpy.row_stack((tableau_comparatif,fichier_entree[:,1]))
i=i+1
tableau_comparatif=normalise_tableau_aire(tableau_comparatif)
return tableau_comparatif, tableau_abscisses

def normalise_tableau_aire(tableau):
for ligne in range(tableau.shape[0]):
minimum=tableau[ligne,:].min()
tableau[ligne,:] = (tableau[ligne,:] - minimum)
aire=tableau[ligne,:].sum()
tableau[ligne,:] = (tableau[ligne,:] /aire)
tableau=LIBStick_outils.creer_tableau_avec_x_colonne1(liste)
tableau=normalise_tableau_x_aire(tableau)
return tableau

def normalise_tableau_x_aire(tableau): # données en colonnes
for colonne in range(tableau.shape[1]-1):
minimum=tableau[:,colonne+1].min()
tableau[:,colonne+1] = (tableau[:,colonne+1] - minimum)
aire=tableau[:,colonne+1].sum()
tableau[:,colonne+1] = (tableau[:,colonne+1] /aire)
#tableau=tableau/tableau.max() #A ne pas faire car dépend de la liste à un instant t !!!
return tableau

def creer_DataFrame(tableau_comparatif,liste,tableau_abscisses):
DataFrame_comparatif=pandas.DataFrame(data=tableau_comparatif, index=liste, columns=tableau_abscisses)
return DataFrame_comparatif
#def creer_DataFrame_x(tableau, liste) :
## liste[0:0] = ["Lambda (nm)"]
# df=pandas.DataFrame(numpy.transpose(tableau[:,1:]), index=liste, columns=tableau[:,0])
# return df

def creer_DataFrame_resultats(DataFrame_comparatif, limites_zone1,limites_zone2,flag_denominateur):
if flag_denominateur == 1 :
Expand All @@ -109,17 +54,19 @@ def creer_DataFrame_resultats(DataFrame_comparatif, limites_zone1,limites_zone2,
DataFrame_tableau_calculs["Somme zone 1"] = Sous_DataFrame.sum(axis=1)
return DataFrame_tableau_calculs

def Convertir_Dataframe_tableau(DataFrame_comparatif):
def convertir_Dataframe_resultats_tableau(DataFrame_comparatif):
tableau=DataFrame_comparatif.values
# print(tableau.shape)
tableau= numpy.delete(tableau, -1 , axis=1)
# print(tableau.shape)
return tableau

def enregistre_DataFrame_resultats(DataFrame_resultats):
DataFrame_resultats.to_csv("Resultat_fichiers_classes.csv")
DataFrame_resultats.to_csv("Resultat_fichiers_classes.txt", sep='\t', decimal=",")

###############################################################################
# 2- fonction d'affichage graphique du tableau de résultats
# fonctions d'affichage graphique du tableau de résultats
###############################################################################
def tableau_256gris(tableau_norm):
tableau8bits=tableau_norm*255
Expand Down Expand Up @@ -179,8 +126,12 @@ def graphique_lit_tableau():
###############################################################################
def main(rep_travail, liste_fichiers, tableau_bornes,type_traitement,flag_denominateur, flag_2D, flag_3D):
os.chdir(rep_travail)
tableau_comparatif, tableau_abscisses = creer_tableau(liste_fichiers,type_traitement)
DataFrame_comparatif=creer_DataFrame(tableau_comparatif,liste_fichiers,tableau_abscisses)
tableau_comparatif = creer_tableau_avec_x(liste_fichiers,type_traitement)
DataFrame_comparatif=LIBStick_outils.creer_DataFrame_x_tableau_en_colonnes(tableau_comparatif,liste_fichiers)

# print(tableau_comparatif.shape)
# print(DataFrame_comparatif.info())

limites_zone1[0]=tableau_bornes[0,0]
limites_zone1[1]=tableau_bornes[0,1]
limites_zone2[0]=tableau_bornes[1,0]
Expand All @@ -199,7 +150,7 @@ def main(rep_travail, liste_fichiers, tableau_bornes,type_traitement,flag_denomi
DataFrame_resultats = DataFrame_resultats.sort_values(by=["Somme zone 1"])
enregistre_DataFrame_resultats(DataFrame_resultats)

tableau_comparatif=Convertir_Dataframe_tableau(DataFrame_comparatif)
tableau_comparatif=convertir_Dataframe_resultats_tableau(DataFrame_comparatif)
tableau8bits=tableau_256gris(tableau_comparatif)
if flag_2D :
graphique_creation(tableau8bits, "Echantillons classés", limites_spectre)
Expand Down
38 changes: 0 additions & 38 deletions LIBStick_creation_spectre_moyen.py

This file was deleted.

Loading

0 comments on commit 85b8bb3

Please sign in to comment.