-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
1,599 additions
and
573 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Created on Thu Apr 2 11:31:54 2020 | ||
@author: yannick | ||
""" | ||
|
||
import numpy,os,pandas | ||
import matplotlib.pyplot as plt | ||
import mpl_toolkits.mplot3d as plt3d | ||
import LIBStick_echange_vars | ||
|
||
#rep_travail="/home/yannick/Bureau/LIBS/Scripts_divers_pour_LIBS/Fluorose_LIBS/Spectres_moyen/528-543/" | ||
#bornes_moyenne_spectres=numpy.linspace(528,543,150) | ||
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 | ||
############################################################################### | ||
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): | ||
os.chdir(rep_travail) | ||
liste=[] | ||
for fichier in os.listdir(): | ||
if (os.path.isfile(fichier) and fichier[-4:] == "mean") : | ||
liste.append(fichier) | ||
liste.sort() | ||
return liste | ||
|
||
def lit_spectre(fichier,tableau_abscisses): | ||
spectre=numpy.loadtxt(fichier,delimiter="\t",usecols=[0],dtype=float,encoding="Latin-1") | ||
#tableau_abscisses=lit_tableau_abscisses() | ||
spectre=numpy.vstack((tableau_abscisses,spectre)) | ||
# spectre=numpy.zeros((0,document.shape[0])) | ||
# for ligne in document : | ||
# spectre=numpy.row_stack((spectre,ligne)) | ||
return spectre | ||
|
||
def lit_tableau_abscisses(): | ||
global tableau_abscisses | ||
tableau_abscisses=numpy.loadtxt("tableau_abscisses.txt", delimiter="\t", usecols=[0]) | ||
return tableau_abscisses | ||
|
||
def creer_tableau(liste): | ||
i=0 | ||
for nom_fichier in liste : | ||
if i==0 : | ||
fichier_entree=numpy.loadtxt(nom_fichier, delimiter="\t", usecols=[0]) | ||
#print(fichier_entree) | ||
tableau_comparatif=numpy.zeros((0,fichier_entree.shape[0])) | ||
tableau_comparatif=numpy.row_stack((tableau_comparatif,fichier_entree)) | ||
else : | ||
fichier_entree=numpy.loadtxt(nom_fichier, delimiter="\t", usecols=[0]) | ||
tableau_comparatif=numpy.row_stack((tableau_comparatif,fichier_entree)) | ||
i=i+1 | ||
#print(tableau_comparatif.shape) | ||
return tableau_comparatif | ||
|
||
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_resultats(DataFrame_comparatif, limites_zone1,limites_zone2): | ||
DataFrame_tableau_calculs=pandas.DataFrame() | ||
Sous_DataFrame = DataFrame_comparatif.loc[ : , limites_zone1[0]:limites_zone1[1]] | ||
#print(Sous_DataFrame) | ||
DataFrame_tableau_calculs["Somme zone 1"] = Sous_DataFrame.sum(axis=1) | ||
Sous_DataFrame = DataFrame_comparatif.loc[ : , limites_zone2[0]:limites_zone2[1]] | ||
#print(Sous_DataFrame) | ||
DataFrame_tableau_calculs["Somme zone 2"] = Sous_DataFrame.sum(axis=1) | ||
DataFrame_tableau_calculs["Rapport"]=DataFrame_tableau_calculs["Somme zone 1"] / DataFrame_tableau_calculs["Somme zone 2"] | ||
return DataFrame_tableau_calculs | ||
|
||
def Convertir_Dataframe_tableau(DataFrame_comparatif): | ||
tableau=DataFrame_comparatif.values | ||
tableau= numpy.delete(tableau, -1 , axis=1) | ||
return tableau | ||
|
||
def enregistre_DataFrame_resultats(DataFrame_resultats): | ||
DataFrame_resultats.to_csv("Resultat_fichiers_classes.csv") | ||
DataFrame_resultats.to_csv("Resultat_fichiers_classes.tsv", sep='\t') | ||
|
||
############################################################################### | ||
# 2- fonction d'affichage graphique du tableau de résultats | ||
############################################################################### | ||
def tableau_256gris(tableau_norm): | ||
tableau8bits=tableau_norm*255 | ||
tableau8bits=tableau8bits.astype(int) | ||
return tableau8bits | ||
|
||
def graphique_creation(tableau8bits,nom_echantillon,limites_spectre): | ||
#fig=plt.figure() | ||
fig, ax=plt.subplots() | ||
#plt.imshow(tableau8bits, cmap="gray", extent=[limites_spectre[0],limites_spectre[1],tableau8bits.shape[0],0], aspect="auto") | ||
plt.imshow(tableau8bits, cmap="inferno", extent=[limites_spectre[0],limites_spectre[1],tableau8bits.shape[0],0], aspect="auto") | ||
#print(tableau8bits.shape[0]) | ||
#print(tableau8bits.shape[1]) | ||
|
||
#imageplot=plt.imshow(tableau8bits, cmap="hot") | ||
#imageplot=plt.imshow(tableau8bits, cmap="nipy_spectral") | ||
#plt.colorbar() | ||
plt.title(nom_echantillon) | ||
plt.xlabel("Longueur d'onde (nm)") | ||
plt.ylabel( "Spectres echantillons classés") | ||
plt.yticks(range(0,tableau8bits.shape[0],5)) | ||
ax.yaxis.get_ticklocs(minor=True) | ||
ax.minorticks_on() | ||
ax.xaxis.set_tick_params(which='minor', bottom=False) | ||
plt.savefig("figure_plot.png") | ||
#plt.xlim(limites_spectre[0], limites_spectre[1]) | ||
#plt.ioff() | ||
plt.show(block=False) | ||
|
||
def graphique_3D_creation(tableau8bits,nom_echantillon,limites_spectre): | ||
xx, yy = numpy.mgrid[0:tableau8bits.shape[0], 0:tableau8bits.shape[1]] | ||
#fig = plt.figure(figsize=(15,15)) | ||
fig = plt.figure() | ||
ax = fig.gca(projection='3d') | ||
ax.plot_surface(xx, yy, tableau8bits ,rstride=1, cstride=1, cmap="inferno",linewidth=0, antialiased=False) | ||
ax.view_init(80, 30) | ||
|
||
plt.title(nom_echantillon) | ||
plt.ylabel("Longueur d'onde (nm)") | ||
plt.xlabel( "Spectres suivant z") | ||
#ax.set_ylim(limites_spectre[0],limites_spectre[1]) | ||
|
||
plt.xticks(range(0,tableau8bits.shape[0],5)) | ||
ax.xaxis.get_ticklocs(minor=True) | ||
ax.minorticks_on() | ||
ax.yaxis.set_tick_params(which='minor', bottom=False) | ||
|
||
plt.show(block=False) | ||
|
||
def graphique_sauvegarde(tableau8bits) : | ||
plt.imsave("figure.png",tableau8bits, cmap="inferno") | ||
|
||
############################################################################### | ||
# programme principal | ||
############################################################################### | ||
def main(rep_travail, tableau_bornes): | ||
os.chdir(rep_travail) | ||
liste=LIBStick_echange_vars.L_comp_liste_fichiers | ||
tableau_comparatif=creer_tableau(liste) | ||
#tableau_abscisses=lit_tableau_abscisses() | ||
DataFrame_comparatif=creer_DataFrame(tableau_comparatif,liste,tableau_abscisses) | ||
limites_zone1[0]=tableau_bornes[0,0] | ||
limites_zone1[1]=tableau_bornes[0,1] | ||
limites_zone2[0]=tableau_bornes[1,0] | ||
limites_zone2[1]=tableau_bornes[1,1] | ||
DataFrame_resultats=creer_DataFrame_resultats(DataFrame_comparatif,limites_zone1,limites_zone2) | ||
DataFrame_comparatif=pandas.concat([DataFrame_comparatif, DataFrame_resultats["Rapport"]], axis=1) | ||
DataFrame_comparatif=DataFrame_comparatif.sort_values(by=["Rapport"]) | ||
#print(DataFrame_comparatif) | ||
LIBStick_echange_vars.L_comp_DataFrame_resultats = DataFrame_resultats = DataFrame_resultats.sort_values(by=["Rapport"]) | ||
print(DataFrame_resultats.shape) | ||
enregistre_DataFrame_resultats(DataFrame_resultats) | ||
|
||
tableau_comparatif=Convertir_Dataframe_tableau(DataFrame_comparatif) | ||
#print (tableau_comparatif) | ||
#print (tableau_comparatif.shape) | ||
|
||
tableau8bits=tableau_256gris(tableau_comparatif) | ||
if LIBStick_echange_vars.L_comp_flag_2D : | ||
graphique_creation(tableau8bits, "Echantillons classés", limites_spectre) | ||
if LIBStick_echange_vars.L_comp_flag_3D : | ||
graphique_3D_creation(tableau8bits, "Echantillons classés", limites_spectre) | ||
graphique_sauvegarde(tableau8bits) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Created on Mon Mar 23 14:42:42 2020 | ||
@author: yannick | ||
""" | ||
|
||
import numpy,os | ||
import LIBStick_echange_vars | ||
|
||
############################################################################### | ||
# 1- fonctions | ||
############################################################################### | ||
def extraction_spectres(tableau_norm): | ||
#tableau_extrait=LIBStick_creation_tableau_norm.tableau_norm.copy() | ||
tableau_extrait=tableau_norm.copy() | ||
print ("format tableau initial : ") | ||
print(tableau_extrait.shape) | ||
indice_premier=(LIBStick_echange_vars.L_ext_bornes_moyenne_spectres[0]-1) | ||
indice_dernier=(LIBStick_echange_vars.L_ext_bornes_moyenne_spectres[1]-1) | ||
cols_supprime_debut=list() | ||
cols_supprime_fin=list() | ||
if indice_premier > 0 : | ||
for i in range(0,indice_premier) : | ||
cols_supprime_debut.append(i) | ||
if indice_dernier < LIBStick_echange_vars.L_ext_nombre_fichiers : | ||
for i in range(indice_dernier+1, LIBStick_echange_vars.L_ext_nombre_fichiers): | ||
cols_supprime_fin.append(i) | ||
cols_supprime=cols_supprime_debut+cols_supprime_fin | ||
print ("colonnes à supprimer : ") | ||
print(cols_supprime) | ||
tableau_extrait=numpy.delete(tableau_extrait, cols_supprime, axis=1) | ||
print ("format tableau extrait : ") | ||
print(tableau_extrait.shape) | ||
return tableau_extrait | ||
|
||
def creation_spectre_moyen(tableau_extrait): | ||
spectre_moyen=tableau_extrait.sum(axis=1) | ||
spectre_moyen=spectre_moyen/tableau_extrait.shape[1] | ||
print("format spectre moyen : ") | ||
print(spectre_moyen.shape) | ||
return spectre_moyen | ||
|
||
def enregistre_fichier(spectre_moyen, nom_echantillon, bornes): | ||
nom_fichier=nom_echantillon+"_spectre_moyen_"+ str(bornes[0])+"_"+str(bornes[1])+".mean" | ||
nom_fichier=str(numpy.char.replace(nom_fichier, " ", "_")) | ||
numpy.savetxt(nom_fichier,spectre_moyen,delimiter="\t", newline="\n") | ||
print (nom_fichier) | ||
|
||
############################################################################### | ||
# programme principal | ||
############################################################################### | ||
def main (rep_travail,nom_echantillon, bornes) : | ||
print("===========================================") | ||
os.chdir(rep_travail) | ||
tableau_norm=numpy.loadtxt("tableau_normalisé.txt",delimiter="\t",dtype=float,encoding="Latin-1") | ||
tableau_extrait=extraction_spectres(tableau_norm) | ||
spectre_moyen=creation_spectre_moyen(tableau_extrait) | ||
enregistre_fichier(spectre_moyen, nom_echantillon, bornes) | ||
return spectre_moyen |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.