From 8487e5018b70d8ba8b1164822f2e62bb5264123a Mon Sep 17 00:00:00 2001 From: YLefrais Date: Fri, 9 Oct 2020 16:25:57 +0200 Subject: [PATCH] 2 IHM compare et extraction --- LIBStick.py | 433 ------------------ LIBStick_GUI_compare.py | 588 ++++++++++++++++++++++++ LIBStick_GUI_extraction.py | 692 +++++++++++++++++++++++++++++ LIBStick_comp_spectres.py | 174 ++++++++ LIBStick_creation_spectre_moyen.py | 61 +++ LIBStick_creation_tableau_norm.py | 79 +--- LIBStick_echange_vars.py | 41 +- LIBStick_extraction_spectres.py | 104 +---- 8 files changed, 1599 insertions(+), 573 deletions(-) delete mode 100755 LIBStick.py create mode 100755 LIBStick_GUI_compare.py create mode 100755 LIBStick_GUI_extraction.py create mode 100644 LIBStick_comp_spectres.py create mode 100644 LIBStick_creation_spectre_moyen.py mode change 100755 => 100644 LIBStick_creation_tableau_norm.py mode change 100755 => 100644 LIBStick_echange_vars.py mode change 100755 => 100644 LIBStick_extraction_spectres.py diff --git a/LIBStick.py b/LIBStick.py deleted file mode 100755 index a5a3444..0000000 --- a/LIBStick.py +++ /dev/null @@ -1,433 +0,0 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- -""" -Created on Tue Feb 18 15:05:40 2020 - -@author: yannick -""" - -import tkinter, numpy, tkinter.filedialog -import os, math -import PIL.Image, PIL.ImageTk -import LIBStick_extraction_spectres -import LIBStick_echange_vars - -############################################################################### -# 0- initialisations -############################################################################### -tableau_bornes=numpy.array([[528, 543],[592, 608]]) -rep_travail="~/Bureau/LIBS/Scripts_divers_pour_LIBS/repertoire_Zone_1" -x1=250.0 -y1=100.0 -x2=250.0 -y2=100.0 - -############################################################################### -# 1- fonctions traitement des données -############################################################################### -def affiche_tableau() : -# tableau_bornes=numpy.array([[eval(entree1.get()), eval(entree2.get())],[eval(entree3.get()), eval(entree4.get())]]) - print(tableau_bornes) - -#def creation_tab_bornes_0() : -# global tableau_bornes -# #tableau_bornes=numpy.array([[528, 543],[592, 608]]) -# tableau_bornes=numpy.array([[variable1.get(),variable2.get()],[variable3.get(),variable4.get()]]) -# #print (tableau_bornes) - -def creation_tab_bornes() : - tableau_bornes[0,0]=variable1.get() - tableau_bornes[0,1]=variable2.get() - tableau_bornes[1,0]=variable3.get() - tableau_bornes[1,1]=variable4.get() - -def reset_tableau() : - tableau_bornes[0,0]=528 - tableau_bornes[0,1]=543 - tableau_bornes[1,0]=592 - tableau_bornes[1,1]=608 - variable1.set(tableau_bornes[0,0]) - variable2.set(tableau_bornes[0,1]) - variable3.set(tableau_bornes[1,0]) - variable4.set(tableau_bornes[1,1]) - deplace_lignes() - #affiche_tableau() - -def choix_rep(): - global rep_travail - rep_travail = tkinter.filedialog.askdirectory(initialdir="~/Bureau/LIBS/Scripts_divers_pour_LIBS/repertoire_Zone_1",title='Choisissez un repertoire') - LIBStick_echange_vars.liste_fichiers=LIBStick_extraction_spectres.creation_liste_fichiers(rep_travail) - affiche_spectre() - bouton_execute.configure(state="normal") - -def affiche_rep(): - print(rep_travail) - -def execute_scripts(): - creation_tab_bornes() - LIBStick_extraction_spectres.main(rep_travail, tableau_bornes) - global photo1, photo2 - global nbr_fichier - fichier1=rep_travail+"/"+str(tableau_bornes[0,0])+"_"+str(tableau_bornes[0,1])+"/figure.png" - fichier2=rep_travail+"/"+str(tableau_bornes[1,0])+"_"+str(tableau_bornes[1,1])+"/figure.png" - image1_zoom=PIL.Image.open(fichier1) - image2_zoom=PIL.Image.open(fichier2) -# image1_zoom=image1_zoom.resize((image1_zoom.width*2, image1_zoom.height*2)) -# image2_zoom=image2_zoom.resize((image2_zoom.width*2, image2_zoom.height*2)) - image1_zoom=image1_zoom.resize((500, 200)) - image2_zoom=image2_zoom.resize((500,200)) - photo1=PIL.ImageTk.PhotoImage(image1_zoom) - photo2=PIL.ImageTk.PhotoImage(image2_zoom) - canevas1.create_image(250 ,100 ,image=photo1) - canevas2.create_image(250,100 ,image=photo2) - nbr_fichier=LIBStick_echange_vars.nombre_fichiers - print("nombre de spectres : " + str(nbr_fichier)) - #plt.show(block=False) - -#def affiche_images() : -# global image1 -# global image2 -# image1=tkinter.PhotoImage(file=rep_travail+"/528_543/figure.png") -# image2=tkinter.PhotoImage(file=rep_travail+"/592_608/figure.png") -# canevas1.create_image(150 ,50 ,image=image1) -# canevas2.create_image(150,50 ,image=image2) - -def change_flag_3D(): - LIBStick_echange_vars.flag_3D=flag_3D.get() - -############################################################################### -# 2- fonctions graphiques du caneva du spectre (frame1) -############################################################################### -def affiche_spectre(): - os.chdir(rep_travail) - canevas0.delete("all") - #if LIBStick_echange_vars.nombre_fichiers > 0 : - spectre=LIBStick_extraction_spectres.lit_spectre(LIBStick_echange_vars.liste_fichiers[0]) - minimum=spectre[:,1].min() - maximum=spectre[:,1].max() - spectre[:,1] = (200-(spectre[:,1] - minimum)*200/(maximum - minimum)) - #spectre[:,0] = (spectre[:,0] - spectre[0,0])*1000/(spectre[len(spectre),0]-spectre[0,0]) - spectre[:,0] = (spectre[:,0] - 197)*1000/(608-197) - for i in range(len(spectre) - 1) : - canevas0.create_line(spectre[i,0],spectre[i,1],spectre[i+1,0],spectre[i+1,1]) - affiche_lignes_spectre() - -def affiche_lignes_spectre(): - global ligne0_1 - global ligne0_2 - global ligne0_3 - global ligne0_4 - ligne0_1=canevas0.create_line(((variable1.get()-198)*1000/410),0,((variable1.get()-198)*1000/410),200, fill="red") - ligne0_2=canevas0.create_line(((variable2.get()-198)*1000/410),0,((variable2.get()-198)*1000/410),200, fill="red") - ligne0_3=canevas0.create_line(((variable3.get()-198)*1000/410),0,((variable3.get()-198)*1000/410),200, fill="blue") - ligne0_4=canevas0.create_line(((variable4.get()-198)*1000/410),0,((variable4.get()-198)*1000/410),200, fill="blue") - -def deplace_lignes(): - deplace_ligne0_1() - deplace_ligne0_2() - deplace_ligne0_3() - deplace_ligne0_4() - -def deplace_ligne0_1(): - global ligne0_1 - canevas0.delete(ligne0_1) - ligne0_1=canevas0.create_line(((variable1.get()-198)*1000/410),0,((variable1.get()-198)*1000/410),200, fill="red") - if variable1.get() > variable2.get(): - variable2.set(variable1.get()) - deplace_ligne0_2() - -def deplace_ligne0_2(): - global ligne0_2 - canevas0.delete(ligne0_2) - ligne0_2=canevas0.create_line(((variable2.get()-198)*1000/410),0,((variable2.get()-198)*1000/410),200, fill="red") - if variable2.get() < variable1.get() : - variable1.set(variable2.get()) - deplace_ligne0_1() - -def deplace_ligne0_3(): - global ligne0_3 - canevas0.delete(ligne0_3) - ligne0_3=canevas0.create_line(((variable3.get()-198)*1000/410),0,((variable3.get()-198)*1000/410),200, fill="blue") - if variable3.get() > variable4.get(): - variable4.set(variable3.get()) - deplace_ligne0_4() - -def deplace_ligne0_4(): - global ligne0_4 - canevas0.delete(ligne0_4) - ligne0_4=canevas0.create_line(((variable4.get()-198)*1000/410),0,((variable4.get()-198)*1000/410),200, fill="blue") - if variable4.get() < variable3.get() : - variable3.set(variable4.get()) - deplace_ligne0_3() - -def deplace_ligne0_1_return(event): - deplace_ligne0_1() - -def deplace_ligne0_2_return(event): - deplace_ligne0_2() - -def deplace_ligne0_3_return(event): - deplace_ligne0_3() - -def deplace_ligne0_4_return(event): - deplace_ligne0_4() - -############################################################################### -# 3- fonctions graphiques du caneva de l'image 1 (frame2) -############################################################################### -def coordonnees1 (event) : - global x1,y1 - x1=event.x - y1=event.y - coord1_to_vars_5_6(x1,y1) - deplace_cible1() - -def deplace_cible1(): - global x1,y1 - global ligne1_vert, ligne1_hori - canevas1.delete(ligne1_vert) - canevas1.delete(ligne1_hori) - ligne1_vert=canevas1.create_line(x1,0,x1,200, fill="white") - ligne1_hori=canevas1.create_line(0,y1,500,y1, fill="white") -# canevas1.coords(ligne1_vert, x1,0,x1,200) -# canevas1.coords(ligne1_hori, 0,y1,400,y1) - -def coord1_to_vars_5_6(x,y): - variable5.set(variable1.get() + (x * (variable2.get()-variable1.get()) / 500)) - variable6.set(math.ceil(y * nbr_fichier / 200)) - -def vars_5_6_to_coord1(): - global x1,y1 - x1=round( ((variable5.get()-variable1.get())*500) / (variable2.get()-variable1.get())) - y1= round(200*(variable6.get()-0.5)/nbr_fichier) - deplace_cible1() - -def vars_5_6_to_coord1_return(event): - vars_5_6_to_coord1() - -############################################################################### -# 4- fonctions graphiques du caneva de l'image 2 (frame2) -############################################################################### -def coordonnees2 (event) : - global x2,y2 - x2=event.x - y2=event.y - coord2_to_vars_7_8(x2,y2) - deplace_cible2() - -def deplace_cible2(): - global x2,y2 - global ligne2_vert, ligne2_hori - canevas2.delete(ligne2_vert) - canevas2.delete(ligne2_hori) - ligne2_vert=canevas2.create_line(x2,0,x2,200, fill="white") - ligne2_hori=canevas2.create_line(0,y2,500,y2, fill="white") - -def coord2_to_vars_7_8(x,y): - variable7.set(variable3.get() + (x * (variable4.get()-variable3.get()) / 500)) - variable8.set(math.ceil(y * nbr_fichier / 200)) - -def vars_7_8_to_coord2(): - global x2,y2 - x2= round((variable7.get()-variable3.get())*500/(variable4.get()-variable3.get())) - y2= round(200*(variable8.get()-0.5)/nbr_fichier) - deplace_cible2() - -def vars_7_8_to_coord2_return(event): - vars_7_8_to_coord2() - -############################################################################### -# 5- fonctions graphiques du choix des spectres à moyenner (frame3) -############################################################################### -def creation_spectre_moyen(): - LIBStick_echange_vars.bornes_moyenne_spectres.insert(0,variable9.get()) - LIBStick_echange_vars.bornes_moyenne_spectres.insert(1,variable10.get()) - - -def retro_action_entree10(): - if variable9.get() > variable10.get(): - variable10.set(variable9.get()) - -def retro_action_entree9(): - if variable10.get() < variable9.get(): - variable9.set(variable10.get()) - -def change_entree9(event): - retro_action_entree10() - -def change_entree10(event): - retro_action_entree9() - -############################################################################### -# 6- Interface graphique : nouvelles classes -############################################################################### -class AutoScrollbar(tkinter.Scrollbar): - # a scrollbar that hides itself if it's not needed. only - # works if you use the grid geometry manager. - # cf. : http://effbot.org/zone/tkinter-autoscrollbar.htm - def set(self, lo, hi): - if float(lo) <= 0.0 and float(hi) >= 1.0: - # grid_remove is currently missing from Tkinter! - self.tk.call("grid", "remove", self) - else: - self.grid() - tkinter.Scrollbar.set(self, lo, hi) - -############################################################################### -# 7- Interface graphique : création fenêtre principale avec scrolls -############################################################################### -fenetre= tkinter.Tk() -fenetre.title("LIBStick") -fenetre.geometry("1020x600+100+50") -fenetre.maxsize(width=1035, height=615) - -vscrollbar = AutoScrollbar(fenetre,orient=tkinter.VERTICAL) -vscrollbar.grid(row=0, column=1, sticky=tkinter.N+tkinter.S) -hscrollbar = AutoScrollbar(fenetre,orient=tkinter.HORIZONTAL) -hscrollbar.grid(row=1, column=0, sticky=tkinter.E+tkinter.W) - -canevas_scroll=tkinter.Canvas(fenetre,yscrollcommand=vscrollbar.set, xscrollcommand=hscrollbar.set) -canevas_scroll.grid(row=0, column=0, sticky=tkinter.N+tkinter.S+tkinter.E+tkinter.W) - -vscrollbar.config(command=canevas_scroll.yview) -hscrollbar.config(command=canevas_scroll.xview) -# make the canvas expandable -fenetre.grid_rowconfigure(0, weight=1) -fenetre.grid_columnconfigure(0, weight=1) - -frame_scroll=tkinter.Frame(canevas_scroll) -frame_scroll.rowconfigure(1, weight=1) -frame_scroll.columnconfigure(1, weight=1) - -############################################################################### -# 8- Interface graphique : création des différentes zones/étapes (frames 1-2-3) -############################################################################### -frame1=tkinter.Frame(frame_scroll,borderwidth=2,relief=tkinter.RAISED) -frame2=tkinter.Frame(frame_scroll,borderwidth=2,relief=tkinter.RAISED) -frame3=tkinter.Frame(frame_scroll,borderwidth=2,relief=tkinter.RAISED) - -frame1.grid(row=10, column=10, padx=5, pady=5,sticky = tkinter.W) -frame2.grid(row=20, column=10, padx=5, pady=5,sticky = tkinter.W) -frame3.grid(row=30, column=10, padx=5, pady=5, sticky = tkinter.W) - -############################################################################### -# 9- Interface graphique frame1: création selection répertoire, affiche spectre et bouton executer -############################################################################### -canevas0=tkinter.Canvas(frame1, width=1000, height=200, bg="white") -canevas0.grid(row=1, column=0, columnspan=5) - -text1=tkinter.Label(frame1, text="Première borne inf. en nm") -text2=tkinter.Label(frame1, text="Première borne sup. en nm") -text3=tkinter.Label(frame1, text="Seconde borne inf. en nm") -text4=tkinter.Label(frame1, text="Seconde borne sup. en nm") -text1.grid(row=2, column=0) -text2.grid(row=2, column=2) -text3.grid(row=3, column=0) -text4.grid(row=3, column=2) - -variable1=tkinter.IntVar(value=528) -variable2=tkinter.IntVar(value=543) -variable3=tkinter.IntVar( value=592) -variable4=tkinter.IntVar(value=608) -entree1=tkinter.Spinbox(frame1, from_=198, to=1013, textvariable=variable1, command=deplace_ligne0_1) -entree2=tkinter.Spinbox(frame1, from_=198, to=1013, textvariable=variable2, command=deplace_ligne0_2) -entree3=tkinter.Spinbox(frame1, from_=198, to=1013, textvariable=variable3, command=deplace_ligne0_3) -entree4=tkinter.Spinbox(frame1, from_=198, to=1013, textvariable=variable4, command=deplace_ligne0_4) -entree1.grid(row=2, column=1) -entree2.grid(row=2, column=3) -entree3.grid(row=3, column=1) -entree4.grid(row=3, column=3) - -bouton_reset=tkinter.Button(frame1, text="Reset", command=reset_tableau) -bouton_rep=tkinter.Button(frame1, text="Repertoire de travail" ,command=choix_rep) -bouton_execute=tkinter.Button(frame1, text="Exécute", command=execute_scripts, state="disable") -bouton_reset.grid(row=2, column=4, rowspan=2) -bouton_rep.grid(row=4, column=0) -bouton_execute.grid(row=4, column=1) - -flag_3D=tkinter.IntVar(value=0) -coche_3D=tkinter.Checkbutton(frame1, text="Sortie 3D", variable=flag_3D, command=change_flag_3D) -coche_3D.grid(row=4, column=2) - -############################################################################### -# 10- Interface graphique frame2: création visues des résultats et aide à la sélection -############################################################################### -canevas1=tkinter.Canvas(frame2, width=500, height=200, bg="white") -canevas2=tkinter.Canvas(frame2, width=500, height=200, bg="white") -canevas1.grid(row=1, column=0, columnspan=2) -canevas2.grid(row=1, column=2, columnspan=2) - -variable5=tkinter.DoubleVar(value=0) -variable6=tkinter.IntVar(value=0) -variable7=tkinter.DoubleVar(value=0) -variable8=tkinter.IntVar(value=0) -entree5=tkinter.Spinbox(frame2, from_=198, to=1013, textvariable=variable5, command=vars_5_6_to_coord1, increment=0.5) -entree6=tkinter.Spinbox(frame2, from_=0, to=100, textvariable=variable6, command=vars_5_6_to_coord1) -entree7=tkinter.Spinbox(frame2, from_=198, to=1013, textvariable=variable7, command=vars_7_8_to_coord2, increment=0.5) -entree8=tkinter.Spinbox(frame2, from_=0, to=100, textvariable=variable8, command=vars_7_8_to_coord2) -entree5.grid(row=2, column=0) -entree6.grid(row=2, column=1) -entree7.grid(row=2, column=2) -entree8.grid(row=2, column=3) - -text5 = tkinter.Label(frame2, text="Position x (nm)") -text6 = tkinter.Label(frame2, text="Position y (n° de spectre)") -text7 = tkinter.Label(frame2, text="Position x (nm)") -text8 = tkinter.Label(frame2, text="Position y (n° de spectre)") -text5.grid(row=3, column=0) -text6.grid(row=3, column=1) -text7.grid(row=3, column=2) -text8.grid(row=3, column=3) - -ligne1_vert=canevas1.create_line(x1,0,x1,200, fill="white") -ligne1_hori=canevas1.create_line(0,y1,500,y1, fill="white") -ligne2_vert=canevas1.create_line(x1,0,x1,200, fill="white") -ligne2_hori=canevas1.create_line(0,y1,500,y1, fill="white") - -affiche_lignes_spectre() - -############################################################################### -# 11- Interface graphique frame3 : création selection des spectres à moyenner -############################################################################### -text9=tkinter.Label(frame3, text="Du spectre n° :") -text10=tkinter.Label(frame3, text="Au spectre n° :") -text9.grid(row=1, column=0) -text10.grid(row=1, column=2) - -variable9=tkinter.IntVar(value=0) -variable10=tkinter.IntVar(value=0) -entree9=tkinter.Spinbox(frame3,from_=0, to=100, textvariable=variable9, command=retro_action_entree10) -entree10=tkinter.Spinbox(frame3,from_=0, to=100, textvariable=variable10, command=retro_action_entree9) -entree9.grid(row=1, column=1) -entree10.grid(row=1, column=3) - -bouton_extraction=tkinter.Button(frame3, text="Extraction", command=creation_spectre_moyen) -bouton_extraction.grid(row=1, column=4) - -############################################################################### -# 12- Interface graphique : gestion du redimentionnement de la fenêtre principale -############################################################################### -canevas_scroll.create_window(0, 0, anchor='nw', window=frame_scroll) -frame_scroll.update_idletasks() -canevas_scroll.config(scrollregion=canevas_scroll.bbox("all")) - -############################################################################### -# 13- Interface graphique : gestion de évènements -############################################################################### -canevas1.bind("", coordonnees1) -canevas2.bind("", coordonnees2) - -entree1.bind("", deplace_ligne0_1_return) -entree2.bind("", deplace_ligne0_2_return) -entree3.bind("", deplace_ligne0_3_return) -entree4.bind("", deplace_ligne0_4_return) - -entree5.bind("", vars_5_6_to_coord1_return) -entree6.bind("", vars_5_6_to_coord1_return) -entree7.bind("", vars_7_8_to_coord2_return) -entree8.bind("", vars_7_8_to_coord2_return) - -entree9.bind("", change_entree9) -entree10.bind("", change_entree10) - -fenetre.mainloop() \ No newline at end of file diff --git a/LIBStick_GUI_compare.py b/LIBStick_GUI_compare.py new file mode 100755 index 0000000..61c7395 --- /dev/null +++ b/LIBStick_GUI_compare.py @@ -0,0 +1,588 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Tue Feb 18 15:05:40 2020 + +@author: yannick +""" + +import tkinter, numpy, pandas +import tkinter.ttk, tkinter.filedialog +import os, math +import PIL.Image, PIL.ImageTk +import LIBStick_echange_vars +import LIBStick_comp_spectres + +############################################################################### +# 0- initialisations +############################################################################### +limites_spectre_L_comp=numpy.array([198.0,1013.0]) +limites_affichage_spectre_L_comp=numpy.array([198.0,1013.0]) +coord_zoom_L_comp=numpy.array([198,0,1013,0]) +delta_limites_L_comp=limites_affichage_spectre_L_comp[1]-limites_affichage_spectre_L_comp[0] +flag_premier_lamda_L_comp=True +l_L_comp=0.0 +spectre_entier_L_comp=numpy.zeros((0,2)) +tableau_bornes_init_L_comp=numpy.array([ [529.0, 542.0] , [534.7, 535.8] ]) +tableau_bornes_L_comp=numpy.array([ [529.0, 542.0] , [534.7, 535.8] ]) +rep_travail_L_comp="./" +#rep_travail_L_comp="~/Bureau/LIBS/Scripts_divers_pour_LIBS/repertoire_Zone_1" +x1_L_comp=250.0 +y1_L_comp=100.0 +#x2_L_comp=250.0 +#y2_L_comp=100.0 + +############################################################################### +# 1- fonctions traitement des données +############################################################################### +def creation_tab_bornes_L_comp() : + global tableau_bornes_L_comp + tableau_bornes_L_comp[0,0]=variable_1_L_comp.get() + tableau_bornes_L_comp[0,1]=variable_2_L_comp.get() + #entree5_L_comp.configure(from_=tableau_bornes_L_comp[0,0], to=tableau_bornes_L_comp[0,1]) + if flag_denominateur_L_comp.get() : + tableau_bornes_L_comp[1,0]=variable_3_L_comp.get() + tableau_bornes_L_comp[1,1]=variable_4_L_comp.get() + return tableau_bornes_L_comp + +def reset_tableau_L_comp() : + global tableau_bornes_L_comp + tableau_bornes_L_comp=tableau_bornes_init_L_comp.copy() + variable_1_L_comp.set(tableau_bornes_L_comp[0,0]) + variable_2_L_comp.set(tableau_bornes_L_comp[0,1]) + variable_3_L_comp.set(tableau_bornes_L_comp[1,0]) + variable_4_L_comp.set(tableau_bornes_L_comp[1,1]) + deplace_lignes_L_comp() + +def choix_rep_L_comp(): + global rep_travail_L_comp + global nbr_fichier + rep_travail_L_comp = tkinter.filedialog.askdirectory(initialdir="./",title='Choisissez un repertoire') + LIBStick_echange_vars.L_comp_liste_fichiers=LIBStick_comp_spectres.creation_liste_fichiers(rep_travail_L_comp) + LIBStick_echange_vars.L_comp_nombre_fichiers=len(LIBStick_echange_vars.L_comp_liste_fichiers) + nbr_fichier=LIBStick_echange_vars.L_comp_nombre_fichiers + lit_affiche_spectre_L_comp() + bouton_execute_L_comp.configure(state="normal") + entree6_L_comp.configure(to=LIBStick_echange_vars.L_comp_nombre_fichiers) + +def lit_affiche_spectre_L_comp(): + global spectre_entier_L_comp + os.chdir(rep_travail_L_comp) + #if LIBStick_echange_vars.L_comp_nombre_fichiers > 0 : + tableau_abscisses=lit_fichier_abscisses_L_comp() + spectre_entier_L_comp=LIBStick_comp_spectres.lit_spectre(LIBStick_echange_vars.L_comp_liste_fichiers[0], tableau_abscisses) + spectre_entier_L_comp=numpy.transpose(spectre_entier_L_comp) + #print(spectre_entier_L_comp.shape) + affiche_spectre_L_comp() + +def lit_fichier_abscisses_L_comp(): + global tableau_abscisses + global limites_spectre_L_comp + tableau_abscisses=LIBStick_comp_spectres.lit_tableau_abscisses() + limites_spectre_L_comp[0]=limites_affichage_spectre_L_comp[0]=tableau_abscisses[0] + limites_spectre_L_comp[1]=limites_affichage_spectre_L_comp[1]=tableau_abscisses[-1] + LIBStick_echange_vars.L_comp_limites_affichage_spectre=limites_affichage_spectre_L_comp + variable_zoom_inf_L_comp.set(limites_affichage_spectre_L_comp[0]) + variable_zoom_sup_L_comp.set(limites_affichage_spectre_L_comp[1]) + entree_zoom_inf_L_comp.configure(from_=limites_spectre_L_comp[0], to=limites_spectre_L_comp[1]) + entree_zoom_sup_L_comp.configure(from_=limites_spectre_L_comp[0], to=limites_spectre_L_comp[1]) + entree1_L_comp.configure(from_=limites_affichage_spectre_L_comp[0], to=limites_affichage_spectre_L_comp[1]) + entree2_L_comp.configure(from_=limites_affichage_spectre_L_comp[0], to=limites_affichage_spectre_L_comp[1]) + entree3_L_comp.configure(from_=limites_affichage_spectre_L_comp[0], to=limites_affichage_spectre_L_comp[1]) + entree4_L_comp.configure(from_=limites_affichage_spectre_L_comp[0], to=limites_affichage_spectre_L_comp[1]) + return tableau_abscisses + +def execute_scripts_L_comp(): + tableau_bornes_L_comp=creation_tab_bornes_L_comp() + LIBStick_comp_spectres.main(rep_travail_L_comp, tableau_bornes_L_comp) + global photo + fichier=rep_travail_L_comp+"/figure.png" + image_zoom=PIL.Image.open(fichier) + image_zoom=image_zoom.resize((1000, 200)) + photo=PIL.ImageTk.PhotoImage(image_zoom) + canevas1_L_comp.create_image(500 ,100 ,image=photo) + affiche_tableau_resultats_L_comp() + +############################################################################### +# 2- fonctions graphiques du caneva du spectre (frame1_L_comp) +############################################################################### +def change_flag_denominateur_L_comp(): + LIBStick_echange_vars.L_comp_flag_denominateur=flag_denominateur_L_comp.get() + if flag_denominateur_L_comp.get() == 0 : + efface_lignes_3_4_L_comp() + entree3_L_comp.configure(state="disable") + entree4_L_comp.configure(state="disable") + if flag_denominateur_L_comp.get() == 1 : + affiche_lignes_3_4_L_comp() + entree3_L_comp.configure(state="normal") + entree4_L_comp.configure(state="normal") + +def change_flag_2D_L_comp(): + LIBStick_echange_vars.L_comp_flag_2D=flag_2D_L_comp.get() + +def change_flag_3D_L_comp(): + LIBStick_echange_vars.L_comp_flag_3D=flag_3D_L_comp.get() + +def change_zoom_inf_L_comp() : +# global limites_affichage_spectre_L_comp + if variable_zoom_inf_L_comp.get() >= variable_zoom_sup_L_comp.get() : + variable_zoom_sup_L_comp.set(variable_zoom_inf_L_comp.get()) +# limites_affichage_spectre_L_comp[0]=variable_zoom_inf_L_comp.get() +# limites_affichage_spectre_L_comp[1]=variable_zoom_sup_L_comp.get() + affiche_spectre_L_comp() + +def change_zoom_sup_L_comp(): +# global limites_affichage_spectre_L_comp + if variable_zoom_sup_L_comp.get() <= variable_zoom_inf_L_comp.get() : + variable_zoom_inf_L_comp.set(variable_zoom_sup_L_comp.get()) +# limites_affichage_spectre_L_comp[0]=variable_zoom_inf_L_comp.get() +# limites_affichage_spectre_L_comp[1]=variable_zoom_sup_L_comp.get() + affiche_spectre_L_comp() + +def change_zoom_inf_return_L_comp(event): + change_zoom_inf_L_comp() + +def change_zoom_sup_return_L_comp(event): + change_zoom_sup_L_comp() + +def zoom_clic_L_comp(event): + global coord_zoom_L_comp + coord_zoom_L_comp[0]=event.x + coord_zoom_L_comp[1]=event.y + +def zoom_drag_and_drop_L_comp(event): + global ligne_position_L_comp + global coord_zoom_L_comp + global limites_affichage_spectre_L_comp + global lambda_texte_spectre + global flag_premier_lamda_L_comp + canevas0_L_comp.delete(ligne_position_L_comp) + ligne_position_L_comp=canevas0_L_comp.create_line(event.x,0,event.x,200, fill="green") + coord_zoom_L_comp[2]=event.x + coord_zoom_L_comp[3]=event.y + if coord_zoom_L_comp[2] > coord_zoom_L_comp[0] : + debut= coord_zoom_L_comp[0]*delta_limites_L_comp/1000+limites_affichage_spectre_L_comp[0] + fin = coord_zoom_L_comp[2]*delta_limites_L_comp/1000+limites_affichage_spectre_L_comp[0] + variable_zoom_inf_L_comp.set(format(debut, "4.1f")) + variable_zoom_sup_L_comp.set(format(fin, "4.1f")) + #affiche la longueur d'onde : + if flag_premier_lamda_L_comp == False : + canevas0_L_comp.delete(lambda_texte_spectre) + l_L_comp= event.x*delta_limites_L_comp/1000+limites_affichage_spectre_L_comp[0] + lambda_texte_spectre = canevas0_L_comp.create_text(event.x, event.y, text=str(format(l_L_comp, "4.1f")), fill="blue") + lambda_texte_L_comp.configure(text="Lambda = " + str(format(l_L_comp, "4.1f") + " nm" )) + flag_premier_lamda_L_comp=False + if coord_zoom_L_comp[2] < coord_zoom_L_comp[0] : + variable_zoom_inf_L_comp.set(limites_spectre_L_comp[0]) + variable_zoom_sup_L_comp.set(limites_spectre_L_comp[1]) + #limites_affichage_spectre_L_comp[0]=variable_zoom_inf_L_comp.get() + #limites_affichage_spectre_L_comp[1]=variable_zoom_sup_L_comp.get() + +def zoom_clic_release_L_comp(event): + affiche_spectre_L_comp() + +def affiche_lambda_L_comp(event): + global lambda_texte_spectre + global flag_premier_lamda_L_comp + #affiche_spectre_L_comp() + if flag_premier_lamda_L_comp == False : + canevas0_L_comp.delete(lambda_texte_spectre) + l_L_comp= event.x*delta_limites_L_comp/1000+limites_affichage_spectre_L_comp[0] + lambda_texte_spectre = canevas0_L_comp.create_text(event.x, event.y, text=str(format(l_L_comp, "4.1f")), fill="blue") + lambda_texte_L_comp.configure(text="Lambda = " + str(format(l_L_comp, "4.1f") + " nm" )) + flag_premier_lamda_L_comp=False + +def affiche_position_souris_L_comp(event): + global ligne_position_L_comp + canevas0_L_comp.delete(ligne_position_L_comp) + ligne_position_L_comp=canevas0_L_comp.create_line(event.x,0,event.x,200, fill="green") + +def affiche_position_souris_motion_L_comp(event): + global ligne_position_L_comp + global lambda_texte_spectre + global flag_premier_lamda_L_comp + canevas0_L_comp.delete(ligne_position_L_comp) + ligne_position_L_comp=canevas0_L_comp.create_line(event.x,0,event.x,200, fill="green") + if flag_premier_lamda_L_comp == False : + canevas0_L_comp.delete(lambda_texte_spectre) + l_L_comp= event.x*delta_limites_L_comp/1000+limites_affichage_spectre_L_comp[0] + lambda_texte_spectre = canevas0_L_comp.create_text(event.x, event.y, text=str(format(l_L_comp, "4.1f")), fill="blue") + lambda_texte_L_comp.configure(text="Lambda = " + str(format(l_L_comp, "4.1f") + " nm" )) + flag_premier_lamda_L_comp=False + +def affiche_spectre_L_comp(): + global limites_affichage_spectre_L_comp + global delta_limites_L_comp + global spectre_entier_L_comp + limites_affichage_spectre_L_comp[0]=variable_zoom_inf_L_comp.get() + limites_affichage_spectre_L_comp[1]=variable_zoom_sup_L_comp.get() + delta_limites_L_comp=limites_affichage_spectre_L_comp[1]-limites_affichage_spectre_L_comp[0] + canevas0_L_comp.delete("all") + spectre=numpy.zeros((0,2)) + for ligne in spectre_entier_L_comp : + if (ligne[0] >= limites_affichage_spectre_L_comp[0] and ligne[0] <= limites_affichage_spectre_L_comp[1]) : + spectre=numpy.row_stack((spectre,ligne)) + minimum=spectre[:,1].min() + maximum=spectre[:,1].max() + spectre[:,1] = (200-(spectre[:,1] - minimum)*200/(maximum - minimum)) + #spectre[:,0] = (spectre[:,0] - spectre[0,0])*1000/(spectre[len(spectre),0]-spectre[0,0]) + spectre[:,0] = (spectre[:,0] - limites_affichage_spectre_L_comp[0])*1000/delta_limites_L_comp + for i in range(len(spectre) - 1) : + canevas0_L_comp.create_line(spectre[i,0],spectre[i,1],spectre[i+1,0],spectre[i+1,1]) + affiche_lignes_spectre_L_comp() + +def affiche_lignes_spectre_L_comp(): + global ligne0_1 + global ligne0_2 + global ligne0_3 + global ligne0_4 + x_ligne0_1=((variable_1_L_comp.get()-limites_affichage_spectre_L_comp[0])*1000/delta_limites_L_comp) + x_ligne0_2=((variable_2_L_comp.get()-limites_affichage_spectre_L_comp[0])*1000/delta_limites_L_comp) + ligne0_1=canevas0_L_comp.create_line(x_ligne0_1,0,x_ligne0_1,200, fill="red") + ligne0_2=canevas0_L_comp.create_line(x_ligne0_2,0,x_ligne0_2,200, fill="red") + if flag_denominateur_L_comp.get() : + x_ligne0_3=((variable_3_L_comp.get()-limites_affichage_spectre_L_comp[0])*1000/delta_limites_L_comp) + x_ligne0_4=((variable_4_L_comp.get()-limites_affichage_spectre_L_comp[0])*1000/delta_limites_L_comp) + ligne0_3=canevas0_L_comp.create_line(x_ligne0_3,0,x_ligne0_3,200, fill="blue") + ligne0_4=canevas0_L_comp.create_line(x_ligne0_4,0,x_ligne0_4,200, fill="blue") + +def deplace_lignes_L_comp(): + deplace_ligne0_1_L_comp() + deplace_ligne0_2_L_comp() + if flag_denominateur_L_comp.get() : + deplace_ligne0_3_L_comp() + deplace_ligne0_4_L_comp() + +def deplace_ligne0_1_L_comp(): + global ligne0_1 + canevas0_L_comp.delete(ligne0_1) + x_ligne0_1=((variable_1_L_comp.get()-limites_affichage_spectre_L_comp[0])*1000/delta_limites_L_comp) + ligne0_1=canevas0_L_comp.create_line(x_ligne0_1,0,x_ligne0_1,200, fill="red") + if variable_1_L_comp.get() >= variable_2_L_comp.get(): + variable_2_L_comp.set(variable_1_L_comp.get()) + deplace_ligne0_2_L_comp() + +def deplace_ligne0_2_L_comp(): + global ligne0_2 + canevas0_L_comp.delete(ligne0_2) + x_ligne0_2=((variable_2_L_comp.get()-limites_affichage_spectre_L_comp[0])*1000/delta_limites_L_comp) + ligne0_2=canevas0_L_comp.create_line(x_ligne0_2,0,x_ligne0_2,200, fill="red") + if variable_2_L_comp.get() <= variable_1_L_comp.get() : + variable_1_L_comp.set(variable_2_L_comp.get()) + deplace_ligne0_1_L_comp() + +def deplace_ligne0_3_L_comp(): + global ligne0_3 + canevas0_L_comp.delete(ligne0_3) + if flag_denominateur_L_comp.get() : + x_ligne0_3=((variable_3_L_comp.get()-limites_affichage_spectre_L_comp[0])*1000/delta_limites_L_comp) + ligne0_3=canevas0_L_comp.create_line(x_ligne0_3,0,x_ligne0_3,200, fill="blue") + if variable_3_L_comp.get() >= variable_4_L_comp.get(): + variable_4_L_comp.set(variable_3_L_comp.get()) + deplace_ligne0_4_L_comp() + +def deplace_ligne0_4_L_comp(): + global ligne0_4 + canevas0_L_comp.delete(ligne0_4) + if flag_denominateur_L_comp.get() : + x_ligne0_4=((variable_4_L_comp.get()-limites_affichage_spectre_L_comp[0])*1000/delta_limites_L_comp) + ligne0_4=canevas0_L_comp.create_line(x_ligne0_4,0,x_ligne0_4,200, fill="blue") + if variable_4_L_comp.get() <= variable_3_L_comp.get() : + variable_3_L_comp.set(variable_4_L_comp.get()) + deplace_ligne0_3_L_comp() + +def efface_lignes_3_4_L_comp(): + global ligne0_3 + global ligne0_4 + canevas0_L_comp.delete(ligne0_3) + canevas0_L_comp.delete(ligne0_4) + +def affiche_lignes_3_4_L_comp(): + global ligne0_3 + global ligne0_4 + canevas0_L_comp.delete(ligne0_3) + canevas0_L_comp.delete(ligne0_4) + x_ligne0_3=((variable_3_L_comp.get()-limites_affichage_spectre_L_comp[0])*1000/delta_limites_L_comp) + x_ligne0_4=((variable_4_L_comp.get()-limites_affichage_spectre_L_comp[0])*1000/delta_limites_L_comp) + ligne0_3=canevas0_L_comp.create_line(x_ligne0_3,0,x_ligne0_3,200, fill="blue") + ligne0_4=canevas0_L_comp.create_line(x_ligne0_4,0,x_ligne0_4,200, fill="blue") + +def deplace_ligne0_1_return_L_comp(event): + deplace_ligne0_1_L_comp() + +def deplace_ligne0_2_return_L_comp(event): + deplace_ligne0_2_L_comp() + +def deplace_ligne0_3_return_L_comp(event): + deplace_ligne0_3_L_comp() + +def deplace_ligne0_4_return_L_comp(event): + deplace_ligne0_4_L_comp() + +############################################################################### +# 3- fonctions graphiques du caneva de l'image 1 (frame2_L_comp) +############################################################################### +def coordonnees1_L_comp (event) : + global x1_L_comp,y1_L_comp + x1_L_comp=event.x + y1_L_comp=event.y + coord1_to_vars_5_6_L_comp(x1_L_comp,y1_L_comp) + deplace_cible1_L_comp() + +def deplace_cible1_L_comp(): + global x1_L_comp,y1_L_comp + global ligne1_vert_L_comp, ligne1_hori_L_comp + canevas1_L_comp.delete(ligne1_vert_L_comp) + canevas1_L_comp.delete(ligne1_hori_L_comp) + ligne1_vert_L_comp=canevas1_L_comp.create_line(x1_L_comp,0,x1_L_comp,200, fill="white") + ligne1_hori_L_comp=canevas1_L_comp.create_line(0,y1_L_comp,1000,y1_L_comp, fill="white") +# canevas1_L_comp.coords(ligne1_vert_L_comp, x1_L_comp,0,x1_L_comp,200) +# canevas1_L_comp.coords(ligne1_hori_L_comp, 0,y1_L_comp,400,y1_L_comp) + +def coord1_to_vars_5_6_L_comp(x,y): + variable_5_L_comp.set(format(limites_spectre_L_comp[0] + (x * (limites_spectre_L_comp[1]-limites_spectre_L_comp[0]) / 1000), "4.1f")) + variable_6_L_comp.set(math.ceil(y * nbr_fichier / 200)) + +def vars_5_6_to_coord1_L_comp(): + global x1_L_comp,y1_L_comp + x1_L_comp=round( ((variable_5_L_comp.get()-limites_spectre_L_comp[0])*1000) / (limites_spectre_L_comp[1]-limites_spectre_L_comp[0])) + y1_L_comp= round(200*(variable_6_L_comp.get()-0.5)/nbr_fichier) + deplace_cible1_L_comp() + +def vars_5_6_to_coord1_return_L_comp(event): + vars_5_6_to_coord1_L_comp() + +############################################################################### +# 4- fonctions graphiques du caneva de l'image 2 (frame2_L_comp) +############################################################################### + + +############################################################################### +# 5- fonctions graphiques du tableau de résultats (frame3_L_comp) +############################################################################### +def affiche_tableau_resultats_L_comp(): + num_ligne=1 + for ligne_tableau in LIBStick_echange_vars.L_comp_DataFrame_resultats.iterrows() : + ID_L_comp=tree_resultats_L_comp.insert("","end", values=(num_ligne, ligne_tableau[0], LIBStick_echange_vars.L_comp_DataFrame_resultats.iloc[num_ligne-1, 2])) + #print(ID) + num_ligne=num_ligne+1 + +def selectionne_spectre_L_comp(event): + selection=tree_resultats_L_comp.item(tree_resultats_L_comp.selection())["values"] + variable_6_L_comp.set(selection[0]) + vars_5_6_to_coord1_L_comp() + +############################################################################### +# 6- Interface graphique : nouvelles classes +############################################################################### +class AutoScrollbar(tkinter.Scrollbar): + # a scrollbar that hides itself if it's not needed. only + # works if you use the grid geometry manager. + # cf. : http://effbot.org/zone/tkinter-autoscrollbar.htm + def set(self, lo, hi): + if float(lo) <= 0.0 and float(hi) >= 1.0: + # grid_remove is currently missing from Tkinter! + self.tk.call("grid", "remove", self) + else: + self.grid() + tkinter.Scrollbar.set(self, lo, hi) + +############################################################################### +# 7- Interface graphique : création fenêtre principale avec scrolls +############################################################################### +fenetre= tkinter.Tk() +fenetre.title("LIBStick : Comparaison des spectres moyens") +fenetre.geometry("1120x775+100+50") +fenetre.maxsize(width=1125, height=785) + +vscrollbar = AutoScrollbar(fenetre,orient=tkinter.VERTICAL) +vscrollbar.grid(row=0, column=1, sticky=tkinter.N+tkinter.S) +hscrollbar = AutoScrollbar(fenetre,orient=tkinter.HORIZONTAL) +hscrollbar.grid(row=1, column=0, sticky=tkinter.E+tkinter.W) + +canevas_scroll=tkinter.Canvas(fenetre,yscrollcommand=vscrollbar.set, xscrollcommand=hscrollbar.set) +canevas_scroll.grid(row=0, column=0, sticky=tkinter.N+tkinter.S+tkinter.E+tkinter.W) + +vscrollbar.config(command=canevas_scroll.yview) +hscrollbar.config(command=canevas_scroll.xview) +# make the canvas expandable +fenetre.grid_rowconfigure(0, weight=1) +fenetre.grid_columnconfigure(0, weight=1) + +frame_scroll=tkinter.Frame(canevas_scroll) +frame_scroll.rowconfigure(1, weight=1) +frame_scroll.columnconfigure(1, weight=1) + +############################################################################### +# 8- Interface graphique : création des différentes zones/étapes (frames 1-2-3) +############################################################################### +frame1_L_comp=tkinter.Frame(frame_scroll,borderwidth=2,relief=tkinter.RAISED) +frame2_L_comp=tkinter.Frame(frame_scroll,borderwidth=2,relief=tkinter.RAISED) +frame3_L_comp=tkinter.Frame(frame_scroll,borderwidth=2,relief=tkinter.RAISED) + +frame1_L_comp.grid(row=10, column=10, padx=5, pady=5,sticky = tkinter.W) +frame2_L_comp.grid(row=20, column=10, padx=5, pady=5,sticky = tkinter.W) +frame3_L_comp.grid(row=30, column=10, padx=5, pady=5, sticky = tkinter.W) + +############################################################################### +# 9- Interface graphique frame1_L_comp : création selection répertoire, affiche spectre et bouton executer +############################################################################### +canevas0_L_comp=tkinter.Canvas(frame1_L_comp, width=1000, height=200, bg="white") +canevas0_L_comp.grid(row=1, column=1, columnspan=5) + +ligne_position_L_comp=canevas0_L_comp.create_line(0,0,0,200, fill="white") + +lambda_texte_L_comp = tkinter.Label(frame1_L_comp, text="Lambda = " + str(format(l_L_comp, "4.1f") + " nm")) +lambda_texte_L_comp.grid(row=2, column=5) + +text1_L_comp=tkinter.Label(frame1_L_comp, text="Numérateur borne inf. en nm") +text2_L_comp=tkinter.Label(frame1_L_comp, text="Numérateur borne sup. en nm") +text3_L_comp=tkinter.Label(frame1_L_comp, text="Dénominateur borne inf. en nm") +text4_L_comp=tkinter.Label(frame1_L_comp, text="Dénominateur borne sup. en nm") +text1_L_comp.grid(row=2, column=1) +text2_L_comp.grid(row=2, column=3) +text3_L_comp.grid(row=3, column=1) +text4_L_comp.grid(row=3, column=3) + +#variable_1_L_comp=tkinter.DoubleVar(value=534.7) +#variable_2_L_comp=tkinter.DoubleVar(value=535.5) +#variable_3_L_comp=tkinter.DoubleVar( value=529) +#variable_4_L_comp=tkinter.DoubleVar(value=542) +variable_1_L_comp=tkinter.DoubleVar(value=529) +variable_2_L_comp=tkinter.DoubleVar(value=542) +variable_3_L_comp=tkinter.DoubleVar( value=534.7) +variable_4_L_comp=tkinter.DoubleVar(value=535.5) +entree1_L_comp=tkinter.Spinbox(frame1_L_comp, from_=198, to=1013, increment=0.5, textvariable=variable_1_L_comp, command=deplace_ligne0_1_L_comp) +entree2_L_comp=tkinter.Spinbox(frame1_L_comp, from_=198, to=1013, increment=0.5, textvariable=variable_2_L_comp, command=deplace_ligne0_2_L_comp) +entree3_L_comp=tkinter.Spinbox(frame1_L_comp, from_=198, to=1013, increment=0.5,textvariable=variable_3_L_comp, command=deplace_ligne0_3_L_comp) +entree4_L_comp=tkinter.Spinbox(frame1_L_comp, from_=198, to=1013, increment=0.5,textvariable=variable_4_L_comp, command=deplace_ligne0_4_L_comp) +entree1_L_comp.grid(row=2, column=2) +entree2_L_comp.grid(row=2, column=4) +entree3_L_comp.grid(row=3, column=2) +entree4_L_comp.grid(row=3, column=4) + +flag_denominateur_L_comp=tkinter.IntVar(value=1) +coche_denominateur_L_comp=tkinter.Checkbutton(frame1_L_comp, text="Dénominateur ?", variable=flag_denominateur_L_comp, command=change_flag_denominateur_L_comp) +coche_denominateur_L_comp.grid(row=3, column=5) + +bouton_reset_L_comp=tkinter.Button(frame1_L_comp, text="Reset", command=reset_tableau_L_comp, width=9) +bouton_reset_L_comp.grid(row=2, column=6, rowspan=2) + +frame1_1_L_comp=tkinter.Frame(frame1_L_comp) +frame1_1_L_comp.grid(row=1, column=6) + +text_zoom_L_comp=tkinter.Label(frame1_1_L_comp, text="Zoom : ", width=9) +text_zoom_L_comp.grid(row=1, column=1) +variable_zoom_inf_L_comp=tkinter.DoubleVar(value=198) +variable_zoom_sup_L_comp=tkinter.DoubleVar(value=1013) +entree_zoom_inf_L_comp=tkinter.Spinbox(frame1_1_L_comp, from_=198, to=1013, increment=1, textvariable=variable_zoom_inf_L_comp, command=change_zoom_inf_L_comp, width=9) +entree_zoom_sup_L_comp=tkinter.Spinbox(frame1_1_L_comp, from_=198, to=1013, increment=1, textvariable=variable_zoom_sup_L_comp, command=change_zoom_sup_L_comp, width=9) +entree_zoom_inf_L_comp.grid(row=2, column=1) +entree_zoom_sup_L_comp.grid(row=3, column=1) + +bouton_rep_L_comp=tkinter.Button(frame1_1_L_comp, text="Repertoire\nde travail" ,command=choix_rep_L_comp, width=9) +bouton_execute_L_comp=tkinter.Button(frame1_1_L_comp, text="Exécute", command=execute_scripts_L_comp, state="disable", width=9) +bouton_rep_L_comp.grid(row=4, column=1) +bouton_execute_L_comp.grid(row=5, column=1) + +flag_2D_L_comp=tkinter.IntVar(value=1) +coche_2D_L_comp=tkinter.Checkbutton(frame1_1_L_comp, text="Sortie 2D", variable=flag_2D_L_comp, command=change_flag_2D_L_comp) +coche_2D_L_comp.grid(row=6, column=1) + +flag_3D_L_comp=tkinter.IntVar(value=0) +coche_3D_L_comp=tkinter.Checkbutton(frame1_1_L_comp, text="Sortie 3D", variable=flag_3D_L_comp, command=change_flag_3D_L_comp) +coche_3D_L_comp.grid(row=7, column=1) + +############################################################################### +# 10- Interface graphique frame2_L_comp : affichage des spectres classés +############################################################################### +canevas1_L_comp=tkinter.Canvas(frame2_L_comp, width=1000, height=200, bg="white") +canevas1_L_comp.grid(row=1, column=1, columnspan=2) + +variable_5_L_comp=tkinter.DoubleVar(value=0) +variable_6_L_comp=tkinter.IntVar(value=0) +entree5_L_comp=tkinter.Spinbox(frame2_L_comp, from_=198, to=1013, textvariable=variable_5_L_comp, command=vars_5_6_to_coord1_L_comp, increment=0.5) +entree6_L_comp=tkinter.Spinbox(frame2_L_comp, from_=1, to=100, textvariable=variable_6_L_comp, command=vars_5_6_to_coord1_L_comp) +entree5_L_comp.grid(row=2, column=1) +entree6_L_comp.grid(row=2, column=2) + +text5_L_comp = tkinter.Label(frame2_L_comp, text="Position x (nm)") +text6_L_comp = tkinter.Label(frame2_L_comp, text="Position y (n° de spectre)") +text5_L_comp.grid(row=3, column=1) +text6_L_comp.grid(row=3, column=2) + +ligne1_vert_L_comp=canevas1_L_comp.create_line(x1_L_comp,0,x1_L_comp,200, fill="white") +ligne1_hori_L_comp=canevas1_L_comp.create_line(0,y1_L_comp,500,y1_L_comp, fill="white") + +affiche_lignes_spectre_L_comp() + +############################################################################### +# 11- Interface graphique frame3_L_comp : affichage des résultats sous forme de TreeView +############################################################################### +tree_resultats_L_comp=tkinter.ttk.Treeview(frame3_L_comp, columns=(1,2,3), height = 10 ,show = "headings") +tree_resultats_L_comp.column(1, width=10) +tree_resultats_L_comp.column(2, width=600) +tree_resultats_L_comp.column(1, width=200) +tree_resultats_L_comp.heading(1, text="n°") +tree_resultats_L_comp.heading(2, text="Nom du spectre") +tree_resultats_L_comp.heading(3, text="Rapport zone1/zone2") +tree_resultats_L_comp.grid(row=1, column=1, sticky=tkinter.N+tkinter.S+tkinter.E+tkinter.W) +scroll_tree_resultat_L_comp=tkinter.ttk.Scrollbar(frame3_L_comp, orient=tkinter.VERTICAL, command=tree_resultats_L_comp.yview) +scroll_tree_resultat_L_comp.grid(row=1, column=2, sticky=tkinter.N+tkinter.S) +tree_resultats_L_comp.configure(yscrollcommand=scroll_tree_resultat_L_comp.set) + +############################################################################### +# 12- Interface graphique : gestion de évènements +############################################################################### +canevas0_L_comp.bind("", affiche_lambda_L_comp) +canevas0_L_comp.bind("", affiche_position_souris_L_comp) +canevas0_L_comp.bind("", affiche_position_souris_motion_L_comp) +canevas0_L_comp.bind("", zoom_clic_L_comp) +canevas0_L_comp.bind("", zoom_drag_and_drop_L_comp) +canevas0_L_comp.bind("", zoom_clic_release_L_comp) + +entree_zoom_inf_L_comp.bind("", change_zoom_inf_return_L_comp) +entree_zoom_sup_L_comp.bind("", change_zoom_sup_return_L_comp) +entree_zoom_inf_L_comp.bind("", change_zoom_inf_return_L_comp) +entree_zoom_sup_L_comp.bind("", change_zoom_sup_return_L_comp) +entree_zoom_inf_L_comp.bind("", change_zoom_inf_return_L_comp) +entree_zoom_sup_L_comp.bind("", change_zoom_sup_return_L_comp) +entree_zoom_inf_L_comp.bind("", change_zoom_inf_return_L_comp) +entree_zoom_sup_L_comp.bind("", change_zoom_sup_return_L_comp) + +canevas1_L_comp.bind("", coordonnees1_L_comp) + +entree1_L_comp.bind("", deplace_ligne0_1_return_L_comp) +entree2_L_comp.bind("", deplace_ligne0_2_return_L_comp) +entree3_L_comp.bind("", deplace_ligne0_3_return_L_comp) +entree4_L_comp.bind("", deplace_ligne0_4_return_L_comp) +entree1_L_comp.bind("", deplace_ligne0_1_return_L_comp) +entree2_L_comp.bind("", deplace_ligne0_2_return_L_comp) +entree3_L_comp.bind("", deplace_ligne0_3_return_L_comp) +entree4_L_comp.bind("", deplace_ligne0_4_return_L_comp) +entree1_L_comp.bind("", deplace_ligne0_1_return_L_comp) +entree2_L_comp.bind("", deplace_ligne0_2_return_L_comp) +entree3_L_comp.bind("", deplace_ligne0_3_return_L_comp) +entree4_L_comp.bind("", deplace_ligne0_4_return_L_comp) +entree1_L_comp.bind("", deplace_ligne0_1_return_L_comp) +entree2_L_comp.bind("", deplace_ligne0_2_return_L_comp) +entree3_L_comp.bind("", deplace_ligne0_3_return_L_comp) +entree4_L_comp.bind("", deplace_ligne0_4_return_L_comp) + +entree5_L_comp.bind("", vars_5_6_to_coord1_return_L_comp) +entree6_L_comp.bind("", vars_5_6_to_coord1_return_L_comp) +entree5_L_comp.bind("", vars_5_6_to_coord1_return_L_comp) +entree6_L_comp.bind("", vars_5_6_to_coord1_return_L_comp) +entree5_L_comp.bind("", vars_5_6_to_coord1_return_L_comp) +entree6_L_comp.bind("", vars_5_6_to_coord1_return_L_comp) + +tree_resultats_L_comp.bind("", selectionne_spectre_L_comp) + +############################################################################### +# 13- Interface graphique : gestion du redimentionnement de la fenêtre principale +############################################################################### +canevas_scroll.create_window(0, 0, anchor='nw', window=frame_scroll) +frame_scroll.update_idletasks() +canevas_scroll.config(scrollregion=canevas_scroll.bbox("all")) + +fenetre.mainloop() diff --git a/LIBStick_GUI_extraction.py b/LIBStick_GUI_extraction.py new file mode 100755 index 0000000..046117e --- /dev/null +++ b/LIBStick_GUI_extraction.py @@ -0,0 +1,692 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Tue Feb 18 15:05:40 2020 + +@author: yannick +""" + +import tkinter, numpy, tkinter.filedialog +import os, math +import PIL.Image, PIL.ImageTk +import LIBStick_echange_vars +import LIBStick_extraction_spectres +import LIBStick_creation_spectre_moyen + +############################################################################### +# 0- initialisations +############################################################################### +limites_spectre_L_ext=numpy.array([198.0,1013.0]) +limites_affichage_spectre_L_ext=numpy.array([198.0,1013.0]) +coord_zoom_L_ext=numpy.array([198,0,1013,0]) +delta_limites_L_ext=limites_affichage_spectre_L_ext[1]-limites_affichage_spectre_L_ext[0] +flag_premier_lamda_L_ext=True +l_L_ext=0.0 +spectre_entier_L_ext=numpy.zeros((0,2)) +tableau_bornes_init_L_ext=numpy.array([[528, 543],[592, 608]]) +tableau_bornes_L_ext=numpy.array([[528, 543],[592, 608]]) +rep_travail_L_ext="./" +#rep_travail="~/Bureau/LIBS/Scripts_divers_pour_LIBS/repertoire_Zone_1" +x1_L_ext=250.0 +y1_L_ext=100.0 +x2_L_ext=250.0 +y2_L_ext=100.0 + +############################################################################### +# 1- fonctions traitement des données +############################################################################### +def creation_tab_bornes_L_ext() : + global tableau_bornes_L_ext + tableau_bornes_L_ext[0,0]=variable_L_ext_1.get() + tableau_bornes_L_ext[0,1]=variable_L_ext_2.get() + entree5_L_ext.configure(from_=tableau_bornes_L_ext[0,0], to=tableau_bornes_L_ext[0,1]) + if flag_zone2_L_ext.get() : + tableau_bornes_L_ext[1,0]=variable_L_ext_3.get() + tableau_bornes_L_ext[1,1]=variable_L_ext_4.get() + entree7_L_ext.configure(from_=tableau_bornes_L_ext[1,0], to=tableau_bornes_L_ext[1,1]) + return tableau_bornes_L_ext + +def reset_tableau_L_ext() : + global tableau_bornes_L_ext + tableau_bornes_L_ext=tableau_bornes_init_L_ext.copy() + variable_L_ext_1.set(tableau_bornes_L_ext[0,0]) + variable_L_ext_2.set(tableau_bornes_L_ext[0,1]) + variable_L_ext_3.set(tableau_bornes_L_ext[1,0]) + variable_L_ext_4.set(tableau_bornes_L_ext[1,1]) + deplace_lignes_L_ext() + +def choix_rep_L_ext(): + global rep_travail + global nbr_fichier + #rep_travail = tkinter.filedialog.askdirectory(initialdir="~/Bureau/LIBS/Scripts_divers_pour_LIBS/repertoire_Zone_1",title='Choisissez un repertoire') + rep_travail = tkinter.filedialog.askdirectory(initialdir="./",title='Choisissez un repertoire') + LIBStick_echange_vars.L_ext_liste_fichiers=LIBStick_extraction_spectres.creation_liste_fichiers(rep_travail) + LIBStick_echange_vars.L_ext_nombre_fichiers=len(LIBStick_echange_vars.L_ext_liste_fichiers) + nbr_fichier=LIBStick_echange_vars.L_ext_nombre_fichiers + lit_affiche_spectre_L_ext() + bouton_execute_L_ext.configure(state="normal") + entree6_L_ext.configure(to=LIBStick_echange_vars.L_ext_nombre_fichiers) + entree8_L_ext.configure(to=LIBStick_echange_vars.L_ext_nombre_fichiers) + entree9_L_ext.configure(to=LIBStick_echange_vars.L_ext_nombre_fichiers) + entree10_L_ext.configure(to=LIBStick_echange_vars.L_ext_nombre_fichiers) + +def execute_scripts_L_ext(): + tableau_bornes_L_ext=creation_tab_bornes_L_ext() + if flag_zone2_L_ext.get() == 0 : + canevas2_L_ext.delete("all") + LIBStick_extraction_spectres.main(rep_travail, tableau_bornes_L_ext) + global photo1, photo2 + fichier1=rep_travail+"/"+str(tableau_bornes_L_ext[0,0])+"_"+str(tableau_bornes_L_ext[0,1])+"/figure.png" + image1_zoom=PIL.Image.open(fichier1) + image1_zoom=image1_zoom.resize((500, 200)) + photo1=PIL.ImageTk.PhotoImage(image1_zoom) + canevas1_L_ext.create_image(250 ,100 ,image=photo1) + if flag_zone2_L_ext.get() : + fichier2=rep_travail+"/"+str(tableau_bornes_L_ext[1,0])+"_"+str(tableau_bornes_L_ext[1,1])+"/figure.png" + image2_zoom=PIL.Image.open(fichier2) + image2_zoom=image2_zoom.resize((500,200)) + photo2=PIL.ImageTk.PhotoImage(image2_zoom) + canevas2_L_ext.create_image(250,100 ,image=photo2) + #print("nombre de spectres : " + str(nbr_fichier)) + bouton_extraction_L_ext.configure(state="normal") + #plt.show(block=False) + +def creation_spectre_moyen_L_ext(): + LIBStick_echange_vars.L_ext_bornes_moyenne_spectres.insert(0,variable_L_ext_9.get()) + LIBStick_echange_vars.L_ext_bornes_moyenne_spectres.insert(1,variable_L_ext_10.get()) + tableau_bornes_copy_L_ext=tableau_bornes_L_ext.copy() + i=3 + if flag_zone2_L_ext.get() == 0: + tableau_bornes_copy_L_ext=numpy.delete(tableau_bornes_copy_L_ext, (1), axis=0) + #print ("copy tableau bornes pour extraction : ") + #print (tableau_bornes_copy_L_ext) + canevas4_L_ext.delete("all") + for bornes in tableau_bornes_copy_L_ext : + repertoire=rep_travail+"/"+str(bornes[0])+"_"+ str(bornes[1])+"/" + spectre=LIBStick_creation_spectre_moyen.main(repertoire,LIBStick_echange_vars.L_ext_nom_echantillon,bornes) + if i==3 : + canevas3_L_ext.delete("all") + minimum=spectre[:].min() + maximum=spectre[:].max() + spectre[:] = (200-(spectre[:] - minimum)*200/(maximum - minimum)) + for j in range(len(spectre) - 1) : + dx=500/len(spectre) + x=j*dx + canevas3_L_ext.create_line(x,spectre[j],x+dx,spectre[j+1], width=1, fill="red", smooth=1) + if i==4 : + canevas4_L_ext.delete("all") + minimum=spectre[:].min() + maximum=spectre[:].max() + spectre[:] = (200-(spectre[:] - minimum)*200/(maximum - minimum)) + for j in range(len(spectre) - 1) : + dx=500/len(spectre) + x=j*dx + canevas4_L_ext.create_line(x,spectre[j],x+dx,spectre[j+1], width=1, fill="blue", smooth=1) + i=i+1 + +############################################################################### +# 2- fonctions graphiques du caneva du spectre (frame1_L_ext) +############################################################################### +def change_flag_2D_L_ext(): + LIBStick_echange_vars.L_ext_flag_2D=flag_2D_L_ext.get() + +def change_flag_3D_L_ext(): + LIBStick_echange_vars.L_ext_flag_3D=flag_3D_L_ext.get() + +def change_flag_zone2_L_ext(): + LIBStick_echange_vars.L_ext_flag_zone2=flag_zone2_L_ext.get() + if flag_zone2_L_ext.get() == 0 : + efface_lignes_3_4_L_ext() + entree3_L_ext.configure(state="disable") + entree4_L_ext.configure(state="disable") + entree7_L_ext.configure(state="disable") + entree8_L_ext.configure(state="disable") + canevas2_L_ext.configure(state="disable") + canevas4_L_ext.configure(state="disable") + if flag_zone2_L_ext.get() == 1 : + affiche_lignes_3_4_L_ext() + entree3_L_ext.configure(state="normal") + entree4_L_ext.configure(state="normal") + entree7_L_ext.configure(state="normal") + entree8_L_ext.configure(state="normal") + canevas2_L_ext.configure(state="normal") + canevas4_L_ext.configure(state="normal") + +def change_zoom_inf_L_ext() : +# global limites_affichage_spectre_L_ext + if variable_L_ext__zoom_inf.get() >= variable_L_ext__zoom_sup.get() : + variable_L_ext__zoom_sup.set(variable_L_ext__zoom_inf.get()) +# limites_affichage_spectre_L_ext[0]=variable_L_ext__zoom_inf.get() +# limites_affichage_spectre_L_ext[1]=variable_L_ext__zoom_sup.get() + affiche_spectre_L_ext() + +def change_zoom_sup_L_ext(): +# global limites_affichage_spectre_L_ext + if variable_L_ext__zoom_sup.get() <= variable_L_ext__zoom_inf.get() : + variable_L_ext__zoom_inf.set(variable_L_ext__zoom_sup.get()) +# limites_affichage_spectre_L_ext[0]=variable_L_ext__zoom_inf.get() +# limites_affichage_spectre_L_ext[1]=variable_L_ext__zoom_sup.get() + affiche_spectre_L_ext() + +def change_zoom_inf_return_L_ext(event): + change_zoom_inf_L_ext() + +def change_zoom_sup_return_L_ext(event): + change_zoom_sup_L_ext() + +def zoom_clic_L_ext(event): + global coord_zoom_L_ext + coord_zoom_L_ext[0]=event.x + coord_zoom_L_ext[1]=event.y + +def zoom_drag_and_drop_L_ext(event): + global ligne_position_L_ext + global coord_zoom_L_ext + global limites_affichage_spectre_L_ext + global lambda_texte_spectre_L_ext + global flag_premier_lamda_L_ext + canevas0_L_ext.delete(ligne_position_L_ext) + ligne_position_L_ext=canevas0_L_ext.create_line(event.x,0,event.x,200, fill="green") + coord_zoom_L_ext[2]=event.x + coord_zoom_L_ext[3]=event.y + if coord_zoom_L_ext[2] > coord_zoom_L_ext[0] : + debut= coord_zoom_L_ext[0]*delta_limites_L_ext/1000+limites_affichage_spectre_L_ext[0] + fin = coord_zoom_L_ext[2]*delta_limites_L_ext/1000+limites_affichage_spectre_L_ext[0] + variable_L_ext__zoom_inf.set(format(debut, "4.1f")) + variable_L_ext__zoom_sup.set(format(fin, "4.1f")) + #affiche la longueur d'onde : + if flag_premier_lamda_L_ext == False : + canevas0_L_ext.delete(lambda_texte_spectre_L_ext) + l= event.x*delta_limites_L_ext/1000+limites_affichage_spectre_L_ext[0] + lambda_texte_spectre_L_ext = canevas0_L_ext.create_text(event.x, event.y, text=str(format(l, "4.1f")), fill="blue") + lambda_texte_L_ext.configure(text="Lambda = " + str(format(l, "4.1f") + " nm" )) + flag_premier_lamda_L_ext=False + if coord_zoom_L_ext[2] < coord_zoom_L_ext[0] : + variable_L_ext__zoom_inf.set(limites_spectre_L_ext[0]) + variable_L_ext__zoom_sup.set(limites_spectre_L_ext[1]) + limites_affichage_spectre_L_ext[0]=variable_L_ext__zoom_inf.get() + limites_affichage_spectre_L_ext[1]=variable_L_ext__zoom_sup.get() + +def zoom_clic_release_L_ext(event): + affiche_spectre_L_ext() + +def lit_affiche_spectre_L_ext(): + global spectre_entier + os.chdir(rep_travail) + #if LIBStick_echange_vars.L_ext_nombre_fichiers > 0 : + spectre_entier=LIBStick_extraction_spectres.lit_spectre(LIBStick_echange_vars.L_ext_liste_fichiers[0]) + affiche_spectre_L_ext() + +def affiche_lambda_L_ext(event): + global lambda_texte_spectre_L_ext + global flag_premier_lamda_L_ext + if flag_premier_lamda_L_ext == False : + canevas0_L_ext.delete(lambda_texte_spectre_L_ext) + l= event.x*delta_limites_L_ext/1000+limites_affichage_spectre_L_ext[0] + lambda_texte_spectre_L_ext = canevas0_L_ext.create_text(event.x, event.y, text=str(format(l, "4.1f")), fill="blue") + lambda_texte_L_ext.configure(text="Lambda = " + str(format(l, "4.1f") + " nm" )) + flag_premier_lamda_L_ext=False + +def affiche_position_souris_L_ext(event): + global ligne_position_L_ext + canevas0_L_ext.delete(ligne_position_L_ext) + ligne_position_L_ext=canevas0_L_ext.create_line(event.x,0,event.x,200, fill="green") + +def affiche_position_souris_motion_L_ext(event): + global ligne_position_L_ext + global lambda_texte_spectre_L_ext + global flag_premier_lamda_L_ext + canevas0_L_ext.delete(ligne_position_L_ext) + ligne_position_L_ext=canevas0_L_ext.create_line(event.x,0,event.x,200, fill="green") + if flag_premier_lamda_L_ext == False : + canevas0_L_ext.delete(lambda_texte_spectre_L_ext) + l= event.x*delta_limites_L_ext/1000+limites_affichage_spectre_L_ext[0] + lambda_texte_spectre_L_ext = canevas0_L_ext.create_text(event.x, event.y, text=str(format(l, "4.1f")), fill="blue") + lambda_texte_L_ext.configure(text="Lambda = " + str(format(l, "4.1f") + " nm" )) + flag_premier_lamda_L_ext=False + +def affiche_spectre_L_ext(): + global limites_affichage_spectre_L_ext + global delta_limites_L_ext + global spectre_entier + limites_affichage_spectre_L_ext[0]=variable_L_ext__zoom_inf.get() + limites_affichage_spectre_L_ext[1]=variable_L_ext__zoom_sup.get() + delta_limites_L_ext=limites_affichage_spectre_L_ext[1]-limites_affichage_spectre_L_ext[0] + canevas0_L_ext.delete("all") + spectre=numpy.zeros((0,2)) + for ligne in spectre_entier : + if (ligne[0] >= limites_affichage_spectre_L_ext[0] and ligne[0] <= limites_affichage_spectre_L_ext[1]) : + spectre=numpy.row_stack((spectre,ligne)) + minimum=spectre[:,1].min() + maximum=spectre[:,1].max() + spectre[:,1] = (200-(spectre[:,1] - minimum)*200/(maximum - minimum)) + #spectre[:,0] = (spectre[:,0] - spectre[0,0])*1000/(spectre[len(spectre),0]-spectre[0,0]) + spectre[:,0] = (spectre[:,0] - limites_affichage_spectre_L_ext[0])*1000/delta_limites_L_ext + for i in range(len(spectre) - 1) : + canevas0_L_ext.create_line(spectre[i,0],spectre[i,1],spectre[i+1,0],spectre[i+1,1]) + affiche_lignes_spectre_L_ext() + +def affiche_lignes_spectre_L_ext(): + global ligne0_1 + global ligne0_2 + global ligne0_3 + global ligne0_4 + x_ligne0_1=((variable_L_ext_1.get()-limites_affichage_spectre_L_ext[0])*1000/delta_limites_L_ext) + x_ligne0_2=((variable_L_ext_2.get()-limites_affichage_spectre_L_ext[0])*1000/delta_limites_L_ext) + ligne0_1=canevas0_L_ext.create_line(x_ligne0_1,0,x_ligne0_1,200, fill="red") + ligne0_2=canevas0_L_ext.create_line(x_ligne0_2,0,x_ligne0_2,200, fill="red") + if flag_zone2_L_ext.get() : + x_ligne0_3=((variable_L_ext_3.get()-limites_affichage_spectre_L_ext[0])*1000/delta_limites_L_ext) + x_ligne0_4=((variable_L_ext_4.get()-limites_affichage_spectre_L_ext[0])*1000/delta_limites_L_ext) + ligne0_3=canevas0_L_ext.create_line(x_ligne0_3,0,x_ligne0_3,200, fill="blue") + ligne0_4=canevas0_L_ext.create_line(x_ligne0_4,0,x_ligne0_4,200, fill="blue") + +def deplace_lignes_L_ext(): + deplace_ligne0_1_L_ext() + deplace_ligne0_2_L_ext() + if flag_zone2_L_ext.get() : + deplace_ligne0_3_L_ext() + deplace_ligne0_4_L_ext() + +def deplace_ligne0_1_L_ext(): + global ligne0_1 + canevas0_L_ext.delete(ligne0_1) + x_ligne0_1=((variable_L_ext_1.get()-limites_affichage_spectre_L_ext[0])*1000/delta_limites_L_ext) + ligne0_1=canevas0_L_ext.create_line(x_ligne0_1,0,x_ligne0_1,200, fill="red") + if variable_L_ext_1.get() >= variable_L_ext_2.get(): + variable_L_ext_2.set(variable_L_ext_1.get()) + deplace_ligne0_2_L_ext() + +def deplace_ligne0_2_L_ext(): + global ligne0_2 + canevas0_L_ext.delete(ligne0_2) + x_ligne0_2=((variable_L_ext_2.get()-limites_affichage_spectre_L_ext[0])*1000/delta_limites_L_ext) + ligne0_2=canevas0_L_ext.create_line(x_ligne0_2,0,x_ligne0_2,200, fill="red") + if variable_L_ext_2.get() <= variable_L_ext_1.get() : + variable_L_ext_1.set(variable_L_ext_2.get()) + deplace_ligne0_1_L_ext() + +def deplace_ligne0_3_L_ext(): + global ligne0_3 + canevas0_L_ext.delete(ligne0_3) + if flag_zone2_L_ext.get() : + x_ligne0_3=((variable_L_ext_3.get()-limites_affichage_spectre_L_ext[0])*1000/delta_limites_L_ext) + ligne0_3=canevas0_L_ext.create_line(x_ligne0_3,0,x_ligne0_3,200, fill="blue") + if variable_L_ext_3.get() >= variable_L_ext_4.get(): + variable_L_ext_4.set(variable_L_ext_3.get()) + deplace_ligne0_4_L_ext() + +def deplace_ligne0_4_L_ext(): + global ligne0_4 + canevas0_L_ext.delete(ligne0_4) + if flag_zone2_L_ext.get() : + x_ligne0_4=((variable_L_ext_4.get()-limites_affichage_spectre_L_ext[0])*1000/delta_limites_L_ext) + ligne0_4=canevas0_L_ext.create_line(x_ligne0_4,0,x_ligne0_4,200, fill="blue") + if variable_L_ext_4.get() <= variable_L_ext_3.get() : + variable_L_ext_3.set(variable_L_ext_4.get()) + deplace_ligne0_3_L_ext() + +def efface_lignes_3_4_L_ext(): + global ligne0_3 + global ligne0_4 + canevas0_L_ext.delete(ligne0_3) + canevas0_L_ext.delete(ligne0_4) + +def affiche_lignes_3_4_L_ext(): + global ligne0_3 + global ligne0_4 + canevas0_L_ext.delete(ligne0_3) + canevas0_L_ext.delete(ligne0_4) + x_ligne0_3=((variable_L_ext_3.get()-limites_affichage_spectre_L_ext[0])*1000/delta_limites_L_ext) + x_ligne0_4=((variable_L_ext_4.get()-limites_affichage_spectre_L_ext[0])*1000/delta_limites_L_ext) + ligne0_3=canevas0_L_ext.create_line(x_ligne0_3,0,x_ligne0_3,200, fill="blue") + ligne0_4=canevas0_L_ext.create_line(x_ligne0_4,0,x_ligne0_4,200, fill="blue") + +def deplace_ligne0_1_return_L_ext(event): + deplace_ligne0_1_L_ext() + +def deplace_ligne0_2_return_L_ext(event): + deplace_ligne0_2_L_ext() + +def deplace_ligne0_3_return_L_ext(event): + deplace_ligne0_3_L_ext() + +def deplace_ligne0_4_return_L_ext(event): + deplace_ligne0_4_L_ext() + +############################################################################### +# 3- fonctions graphiques du caneva de l'image 1 (frame2_L_ext) +############################################################################### +def coordonnees1_L_ext (event) : + global x1_L_ext,y1_L_ext + x1_L_ext=event.x + y1_L_ext=event.y + coord1_to_vars_5_6_L_ext(x1_L_ext,y1_L_ext) + deplace_cible1_L_ext() + +def deplace_cible1_L_ext(): + global x1_L_ext,y1_L_ext + global ligne1_vert_L_ext, ligne1_hori_L_ext + canevas1_L_ext.delete(ligne1_vert_L_ext) + canevas1_L_ext.delete(ligne1_hori_L_ext) + ligne1_vert_L_ext=canevas1_L_ext.create_line(x1_L_ext,0,x1_L_ext,200, fill="white") + ligne1_hori_L_ext=canevas1_L_ext.create_line(0,y1_L_ext,500,y1_L_ext, fill="white") +# canevas1_L_ext.coords(ligne1_vert_L_ext, x1_L_ext,0,x1_L_ext,200) +# canevas1_L_ext.coords(ligne1_hori_L_ext, 0,y1_L_ext,400,y1_L_ext) + +def coord1_to_vars_5_6_L_ext(x,y): + variable_L_ext_5.set(format((variable_L_ext_1.get() + (x * (variable_L_ext_2.get()-variable_L_ext_1.get()) / 500)), "4.1f")) + variable_L_ext_6.set(math.ceil(y * nbr_fichier / 200)) + +def vars_5_6_to_coord1_L_ext(): + global x1_L_ext,y1_L_ext + x1_L_ext=round( ((variable_L_ext_5.get()-variable_L_ext_1.get())*500) / (variable_L_ext_2.get()-variable_L_ext_1.get())) + y1_L_ext= round(200*(variable_L_ext_6.get()-0.5)/nbr_fichier) + deplace_cible1_L_ext() + +def vars_5_6_to_coord1_return_L_ext(event): + vars_5_6_to_coord1_L_ext() + +############################################################################### +# 4- fonctions graphiques du caneva de l'image 2 (frame2_L_ext) +############################################################################### +def coordonnees2_L_ext (event) : + global x2_L_ext,y2_L_ext + x2_L_ext=event.x + y2_L_ext=event.y + coord2_to_vars_7_8_L_ext(x2_L_ext,y2_L_ext) + deplace_cible2_L_ext() + +def deplace_cible2_L_ext(): + global x2_L_ext,y2_L_ext + global ligne2_vert_L_ext, ligne2_hori_L_ext + canevas2_L_ext.delete(ligne2_vert_L_ext) + canevas2_L_ext.delete(ligne2_hori_L_ext) + ligne2_vert_L_ext=canevas2_L_ext.create_line(x2_L_ext,0,x2_L_ext,200, fill="white") + ligne2_hori_L_ext=canevas2_L_ext.create_line(0,y2_L_ext,500,y2_L_ext, fill="white") + +def coord2_to_vars_7_8_L_ext(x,y): + variable_L_ext_7.set(format((variable_L_ext_3.get() + (x * (variable_L_ext_4.get()-variable_L_ext_3.get()) / 500)), "4.1f")) + variable_L_ext_8.set(math.ceil(y * nbr_fichier / 200)) + +def vars_7_8_to_coord2_L_ext(): + global x2_L_ext,y2_L_ext + x2_L_ext= round((variable_L_ext_7.get()-variable_L_ext_3.get())*500/(variable_L_ext_4.get()-variable_L_ext_3.get())) + y2_L_ext= round(200*(variable_L_ext_8.get()-0.5)/nbr_fichier) + deplace_cible2_L_ext() + +def vars_7_8_to_coord2_return_L_ext(event): + vars_7_8_to_coord2_L_ext() + +############################################################################### +# 5- fonctions graphiques du choix des spectres à moyenner (frame3_L_ext) +############################################################################### +def retro_action_entree10_L_ext(): + if variable_L_ext_9.get() > variable_L_ext_10.get(): + variable_L_ext_10.set(variable_L_ext_9.get()) + +def retro_action_entree9_L_ext(): + if variable_L_ext_10.get() < variable_L_ext_9.get(): + variable_L_ext_9.set(variable_L_ext_10.get()) + +def change_entree9_L_ext(event): + retro_action_entree10_L_ext() + +def change_entree10_L_ext(event): + retro_action_entree9_L_ext() + +############################################################################### +# 6- Interface graphique : nouvelles classes +############################################################################### +class AutoScrollbar(tkinter.Scrollbar): + # a scrollbar that hides itself if it's not needed. only + # works if you use the grid geometry manager. + # cf. : http://effbot.org/zone/tkinter-autoscrollbar.htm + def set(self, lo, hi): + if float(lo) <= 0.0 and float(hi) >= 1.0: + # grid_remove is currently missing from Tkinter! + self.tk.call("grid", "remove", self) + else: + self.grid() + tkinter.Scrollbar.set(self, lo, hi) + +############################################################################### +# 7- Interface graphique : création fenêtre principale avec scrolls +############################################################################### +fenetre= tkinter.Tk() +fenetre.title("LIBStick : Extraction de spectres moyens") +fenetre.geometry("1120x775+100+50") +fenetre.maxsize(width=1125, height=785) + +vscrollbar = AutoScrollbar(fenetre,orient=tkinter.VERTICAL) +vscrollbar.grid(row=0, column=1, sticky=tkinter.N+tkinter.S) +hscrollbar = AutoScrollbar(fenetre,orient=tkinter.HORIZONTAL) +hscrollbar.grid(row=1, column=0, sticky=tkinter.E+tkinter.W) + +canevas_scroll=tkinter.Canvas(fenetre,yscrollcommand=vscrollbar.set, xscrollcommand=hscrollbar.set) +canevas_scroll.grid(row=0, column=0, sticky=tkinter.N+tkinter.S+tkinter.E+tkinter.W) + +vscrollbar.config(command=canevas_scroll.yview) +hscrollbar.config(command=canevas_scroll.xview) +# make the canvas expandable +fenetre.grid_rowconfigure(0, weight=1) +fenetre.grid_columnconfigure(0, weight=1) + +frame_scroll=tkinter.Frame(canevas_scroll) +frame_scroll.rowconfigure(1, weight=1) +frame_scroll.columnconfigure(1, weight=1) + +############################################################################### +# 8- Interface graphique : création des différentes zones/étapes (frames 1-2-3) +############################################################################### +frame1_L_ext=tkinter.Frame(frame_scroll,borderwidth=2,relief=tkinter.RAISED) +frame2_L_ext=tkinter.Frame(frame_scroll,borderwidth=2,relief=tkinter.RAISED) +frame3_L_ext=tkinter.Frame(frame_scroll,borderwidth=2,relief=tkinter.RAISED) + +#frame1_L_ext=tkinter.Frame(onglet1,borderwidth=2,relief=tkinter.RAISED) +#frame2_L_ext=tkinter.Frame(onglet1,borderwidth=2,relief=tkinter.RAISED) +#frame3_L_ext=tkinter.Frame(onglet1,borderwidth=2,relief=tkinter.RAISED) + +frame1_L_ext.grid(row=10, column=10, padx=5, pady=5,sticky = tkinter.W) +frame2_L_ext.grid(row=20, column=10, padx=5, pady=5,sticky = tkinter.W) +frame3_L_ext.grid(row=30, column=10, padx=5, pady=5, sticky = tkinter.W) + +############################################################################### +# 9- Interface graphique frame1_L_ext : création selection répertoire, affiche spectre et bouton executer +############################################################################### +canevas0_L_ext=tkinter.Canvas(frame1_L_ext, width=1000, height=200, bg="white") +canevas0_L_ext.grid(row=1, column=1, columnspan=5) + +ligne_position_L_ext=canevas0_L_ext.create_line(0,0,0,200, fill="white") + +lambda_texte_L_ext = tkinter.Label(frame1_L_ext, text="Lambda = " + str(format(l_L_ext, "4.1f") + " nm")) +lambda_texte_L_ext.grid(row=2, column=5) + +text1_L_ext=tkinter.Label(frame1_L_ext, text="Première borne inf. en nm") +text2_L_ext=tkinter.Label(frame1_L_ext, text="Première borne sup. en nm") +text3_L_ext=tkinter.Label(frame1_L_ext, text="Seconde borne inf. en nm") +text4_L_ext=tkinter.Label(frame1_L_ext, text="Seconde borne sup. en nm") +text1_L_ext.grid(row=2, column=1) +text2_L_ext.grid(row=2, column=3) +text3_L_ext.grid(row=3, column=1) +text4_L_ext.grid(row=3, column=3) + +variable_L_ext_1=tkinter.DoubleVar(value=528) +variable_L_ext_2=tkinter.DoubleVar(value=543) +variable_L_ext_3=tkinter.DoubleVar( value=592) +variable_L_ext_4=tkinter.DoubleVar(value=608) +entree1_L_ext=tkinter.Spinbox(frame1_L_ext, from_=198, to=1013, textvariable=variable_L_ext_1, command=deplace_ligne0_1_L_ext) +entree2_L_ext=tkinter.Spinbox(frame1_L_ext, from_=198, to=1013, textvariable=variable_L_ext_2, command=deplace_ligne0_2_L_ext) +entree3_L_ext=tkinter.Spinbox(frame1_L_ext, from_=198, to=1013, textvariable=variable_L_ext_3, command=deplace_ligne0_3_L_ext) +entree4_L_ext=tkinter.Spinbox(frame1_L_ext, from_=198, to=1013, textvariable=variable_L_ext_4, command=deplace_ligne0_4_L_ext) +entree1_L_ext.grid(row=2, column=2) +entree2_L_ext.grid(row=2, column=4) +entree3_L_ext.grid(row=3, column=2) +entree4_L_ext.grid(row=3, column=4) + +flag_zone2_L_ext=tkinter.IntVar(value=1) +coche_zone2_L_ext=tkinter.Checkbutton(frame1_L_ext, text="Seconde extraction ?", variable=flag_zone2_L_ext, command=change_flag_zone2_L_ext) +coche_zone2_L_ext.grid(row=3, column=5) + +bouton_reset_L_ext=tkinter.Button(frame1_L_ext, text="Reset", command=reset_tableau_L_ext, width=9) +bouton_reset_L_ext.grid(row=2, column=6, rowspan=2) + +frame1_1_L_ext=tkinter.Frame(frame1_L_ext) +frame1_1_L_ext.grid(row=1, column=6) + +text_zoom_L_ext=tkinter.Label(frame1_1_L_ext, text="Zoom : ", width=9) +text_zoom_L_ext.grid(row=1, column=1) +variable_L_ext__zoom_inf=tkinter.DoubleVar(value=198) +variable_L_ext__zoom_sup=tkinter.DoubleVar(value=1013) +entree_zoom_inf_L_ext=tkinter.Spinbox(frame1_1_L_ext, from_=198, to=1013, increment=5, textvariable=variable_L_ext__zoom_inf, command=change_zoom_inf_L_ext, width=9) +entree_zoom_sup_L_ext=tkinter.Spinbox(frame1_1_L_ext, from_=198, to=1013, increment=5, textvariable=variable_L_ext__zoom_sup, command=change_zoom_sup_L_ext, width=9) +entree_zoom_inf_L_ext.grid(row=2, column=1) +entree_zoom_sup_L_ext.grid(row=3, column=1) + +bouton_rep_L_ext=tkinter.Button(frame1_1_L_ext, text="Repertoire\nde travail" ,command=choix_rep_L_ext, width=9) +bouton_execute_L_ext=tkinter.Button(frame1_1_L_ext, text="Exécute", command=execute_scripts_L_ext, state="disable", width=9) +bouton_rep_L_ext.grid(row=4, column=1) +bouton_execute_L_ext.grid(row=5, column=1) + +flag_2D_L_ext=tkinter.IntVar(value=1) +coche_2D_L_ext=tkinter.Checkbutton(frame1_1_L_ext, text="Sortie 2D", variable=flag_2D_L_ext, command=change_flag_2D_L_ext) +coche_2D_L_ext.grid(row=6, column=1) + +flag_3D_L_ext=tkinter.IntVar(value=0) +coche_3D_L_ext=tkinter.Checkbutton(frame1_1_L_ext, text="Sortie 3D", variable=flag_3D_L_ext, command=change_flag_3D_L_ext) +coche_3D_L_ext.grid(row=7, column=1) + + +############################################################################### +# 10- Interface graphique frame2_L_ext : création visues des résultats et aide à la sélection +############################################################################### +canevas1_L_ext=tkinter.Canvas(frame2_L_ext, width=500, height=200, bg="white") +canevas2_L_ext=tkinter.Canvas(frame2_L_ext, width=500, height=200, bg="white") +canevas1_L_ext.grid(row=1, column=1, columnspan=2) +canevas2_L_ext.grid(row=1, column=3, columnspan=2) + +variable_L_ext_5=tkinter.DoubleVar(value=0) +variable_L_ext_6=tkinter.IntVar(value=0) +variable_L_ext_7=tkinter.DoubleVar(value=0) +variable_L_ext_8=tkinter.IntVar(value=0) +entree5_L_ext=tkinter.Spinbox(frame2_L_ext, from_=198, to=1013, textvariable=variable_L_ext_5, command=vars_5_6_to_coord1_L_ext, increment=0.5) +entree6_L_ext=tkinter.Spinbox(frame2_L_ext, from_=1, to=200, textvariable=variable_L_ext_6, command=vars_5_6_to_coord1_L_ext) +entree7_L_ext=tkinter.Spinbox(frame2_L_ext, from_=198, to=1013, textvariable=variable_L_ext_7, command=vars_7_8_to_coord2_L_ext, increment=0.5) +entree8_L_ext=tkinter.Spinbox(frame2_L_ext, from_=1, to=200, textvariable=variable_L_ext_8, command=vars_7_8_to_coord2_L_ext) +entree5_L_ext.grid(row=2, column=1) +entree6_L_ext.grid(row=2, column=2) +entree7_L_ext.grid(row=2, column=3) +entree8_L_ext.grid(row=2, column=4) + +text5_L_ext = tkinter.Label(frame2_L_ext, text="Position x (nm)") +text6_L_ext = tkinter.Label(frame2_L_ext, text="Position y (n° de spectre)") +text7_L_ext = tkinter.Label(frame2_L_ext, text="Position x (nm)") +text8_L_ext = tkinter.Label(frame2_L_ext, text="Position y (n° de spectre)") +text5_L_ext.grid(row=3, column=1) +text6_L_ext.grid(row=3, column=2) +text7_L_ext.grid(row=3, column=3) +text8_L_ext.grid(row=3, column=4) + +ligne1_vert_L_ext=canevas1_L_ext.create_line(x1_L_ext,0,x1_L_ext,200, fill="white") +ligne1_hori_L_ext=canevas1_L_ext.create_line(0,y1_L_ext,500,y1_L_ext, fill="white") +ligne2_vert_L_ext=canevas1_L_ext.create_line(x1_L_ext,0,x1_L_ext,200, fill="white") +ligne2_hori_L_ext=canevas1_L_ext.create_line(0,y1_L_ext,500,y1_L_ext, fill="white") + +affiche_lignes_spectre_L_ext() + +############################################################################### +# 11- Interface graphique frame3_L_ext : création selection des spectres à moyenner +############################################################################### +text9_L_ext=tkinter.Label(frame3_L_ext, text="Du spectre n° :") +text10_L_ext=tkinter.Label(frame3_L_ext, text="Au spectre n° :") +text9_L_ext.grid(row=1, column=1) +text10_L_ext.grid(row=1, column=3) + +variable_L_ext_9=tkinter.IntVar(value=0) +variable_L_ext_10=tkinter.IntVar(value=0) +entree9_L_ext=tkinter.Spinbox(frame3_L_ext,from_=1, to=200, textvariable=variable_L_ext_9, command=retro_action_entree10_L_ext) +entree10_L_ext=tkinter.Spinbox(frame3_L_ext,from_=1, to=200, textvariable=variable_L_ext_10, command=retro_action_entree9_L_ext) +entree9_L_ext.grid(row=1, column=2) +entree10_L_ext.grid(row=1, column=4) + +fram3_1_L_ext=tkinter.Frame(frame3_L_ext) +fram3_1_L_ext.grid(row=1, column=5) +bouton_extraction_L_ext=tkinter.Button(fram3_1_L_ext, text="Extraction", state="disable", command=creation_spectre_moyen_L_ext, width=9) +bouton_extraction_L_ext.grid(row=1, column=1) + +canevas3_L_ext=tkinter.Canvas(frame3_L_ext, width=500, height=200, bg="white") +canevas4_L_ext=tkinter.Canvas(frame3_L_ext, width=500, height=200, bg="white") +canevas3_L_ext.grid(row=3, column=1, columnspan=2) +canevas4_L_ext.grid(row=3, column=3, columnspan=2) + +############################################################################### +# 12- Interface graphique : gestion de évènements +############################################################################### +canevas0_L_ext.bind("", affiche_lambda_L_ext) +canevas0_L_ext.bind("", affiche_position_souris_L_ext) +canevas0_L_ext.bind("", affiche_position_souris_motion_L_ext) +canevas0_L_ext.bind("", zoom_clic_L_ext) +canevas0_L_ext.bind("", zoom_drag_and_drop_L_ext) +canevas0_L_ext.bind("", zoom_clic_release_L_ext) + +entree_zoom_inf_L_ext.bind("", change_zoom_inf_return_L_ext) +entree_zoom_sup_L_ext.bind("", change_zoom_sup_return_L_ext) +entree_zoom_inf_L_ext.bind("", change_zoom_inf_return_L_ext) +entree_zoom_sup_L_ext.bind("", change_zoom_sup_return_L_ext) +entree_zoom_inf_L_ext.bind("", change_zoom_inf_return_L_ext) +entree_zoom_sup_L_ext.bind("", change_zoom_sup_return_L_ext) +entree_zoom_inf_L_ext.bind("", change_zoom_inf_return_L_ext) +entree_zoom_sup_L_ext.bind("", change_zoom_sup_return_L_ext) + +canevas1_L_ext.bind("", coordonnees1_L_ext) +canevas2_L_ext.bind("", coordonnees2_L_ext) + +entree1_L_ext.bind("", deplace_ligne0_1_return_L_ext) +entree2_L_ext.bind("", deplace_ligne0_2_return_L_ext) +entree3_L_ext.bind("", deplace_ligne0_3_return_L_ext) +entree4_L_ext.bind("", deplace_ligne0_4_return_L_ext) +entree1_L_ext.bind("", deplace_ligne0_1_return_L_ext) +entree2_L_ext.bind("", deplace_ligne0_2_return_L_ext) +entree3_L_ext.bind("", deplace_ligne0_3_return_L_ext) +entree4_L_ext.bind("", deplace_ligne0_4_return_L_ext) +entree1_L_ext.bind("", deplace_ligne0_1_return_L_ext) +entree2_L_ext.bind("", deplace_ligne0_2_return_L_ext) +entree3_L_ext.bind("", deplace_ligne0_3_return_L_ext) +entree4_L_ext.bind("", deplace_ligne0_4_return_L_ext) +entree1_L_ext.bind("", deplace_ligne0_1_return_L_ext) +entree2_L_ext.bind("", deplace_ligne0_2_return_L_ext) +entree3_L_ext.bind("", deplace_ligne0_3_return_L_ext) +entree4_L_ext.bind("", deplace_ligne0_4_return_L_ext) + + +entree5_L_ext.bind("", vars_5_6_to_coord1_return_L_ext) +entree6_L_ext.bind("", vars_5_6_to_coord1_return_L_ext) +entree7_L_ext.bind("", vars_7_8_to_coord2_return_L_ext) +entree8_L_ext.bind("", vars_7_8_to_coord2_return_L_ext) +entree5_L_ext.bind("", vars_5_6_to_coord1_return_L_ext) +entree6_L_ext.bind("", vars_5_6_to_coord1_return_L_ext) +entree7_L_ext.bind("", vars_7_8_to_coord2_return_L_ext) +entree8_L_ext.bind("", vars_7_8_to_coord2_return_L_ext) +entree5_L_ext.bind("", vars_5_6_to_coord1_return_L_ext) +entree6_L_ext.bind("", vars_5_6_to_coord1_return_L_ext) +entree7_L_ext.bind("", vars_7_8_to_coord2_return_L_ext) +entree8_L_ext.bind("", vars_7_8_to_coord2_return_L_ext) + +entree9_L_ext.bind("", change_entree9_L_ext) +entree10_L_ext.bind("", change_entree10_L_ext) +entree9_L_ext.bind("", change_entree9_L_ext) +entree10_L_ext.bind("", change_entree10_L_ext) +entree9_L_ext.bind("", change_entree9_L_ext) +entree10_L_ext.bind("", change_entree10_L_ext) +entree9_L_ext.bind("", change_entree9_L_ext) +entree10_L_ext.bind("", change_entree10_L_ext) + + +############################################################################### +# 13- Interface graphique : gestion du redimentionnement de la fenêtre principale +############################################################################### +canevas_scroll.create_window(0, 0, anchor='nw', window=frame_scroll) +frame_scroll.update_idletasks() +canevas_scroll.config(scrollregion=canevas_scroll.bbox("all")) + +fenetre.mainloop() diff --git a/LIBStick_comp_spectres.py b/LIBStick_comp_spectres.py new file mode 100644 index 0000000..b8efcd0 --- /dev/null +++ b/LIBStick_comp_spectres.py @@ -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) + diff --git a/LIBStick_creation_spectre_moyen.py b/LIBStick_creation_spectre_moyen.py new file mode 100644 index 0000000..967f5b0 --- /dev/null +++ b/LIBStick_creation_spectre_moyen.py @@ -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 diff --git a/LIBStick_creation_tableau_norm.py b/LIBStick_creation_tableau_norm.py old mode 100755 new mode 100644 index bc60c98..6e75ce8 --- a/LIBStick_creation_tableau_norm.py +++ b/LIBStick_creation_tableau_norm.py @@ -30,10 +30,10 @@ ############################################################################### # 1- fonction qui liste des fichiers *.tsv d'un répertoire ############################################################################### -def repertoire_de_travail_0(rep_script): - rep_travail=rep_script+"/test_python_Zone_1/528_543/" - #rep_travail=rep_travail+"/test_python_Zone_1/592_608/" - return rep_travail +#def repertoire_de_travail_0(rep_script): +# rep_travail=rep_script+"/test_python_Zone_1/528_543/" +# #rep_travail=rep_travail+"/test_python_Zone_1/592_608/" +# return rep_travail def repertoire_de_travail(rep_script,rep_travail_relatif): rep_travail=rep_script+"/"+rep_travail_relatif @@ -52,21 +52,6 @@ def creation_liste_fichiers(rep_travail): # 2- fonction qui ouvre chaque fichier de la liste, sépare les données en liste de listes, # extrait la seconde colonne et l'ajoute à un tableau numpy ############################################################################### -#def creer_tableau_0(liste): -# tableau=numpy.array(object) -# i=0 -# for fichier in liste : -# if i==0: -# fentree=open(fichier,"r") -# tableau=numpy.genfromtxt(fentree, delimiter="\t") -# else : -# fentree=open(fichier,"r") -# tableau2=numpy.genfromtxt(fentree, delimiter="\t") -# tableau=numpy.insert(tableau,tableau.shape[1],tableau2[:,1],axis=1) -# i=i+1 -# tableau=numpy.delete(tableau,0,axis=1) -# return tableau - def creer_tableau(liste): i=0 for fichier in liste : @@ -80,16 +65,16 @@ def creer_tableau(liste): i=i+1 return tableau +def creer_tableau_abscisses(liste): + fichier0=numpy.loadtxt(liste[0], delimiter="\t", usecols=[0]) + tableau_abscisses=numpy.zeros((fichier0.shape[0],0)) + tableau_abscisses=numpy.column_stack((tableau_abscisses,fichier0)) + print(tableau_abscisses) + return tableau_abscisses + ############################################################################### # 3- fonction normalise les colonnes du tableau ############################################################################### -#def normalise_tableau_maxi(tableau): -# for colonne in range(tableau.shape[1]): -# minimum=tableau[:,colonne].min() -# maximum=tableau[:,colonne].max() -# tableau[:,colonne] = (tableau[:,colonne] - minimum)/(maximum - minimum) -# return tableau - def normalise_tableau_aire(tableau): for colonne in range(tableau.shape[1]): minimum=tableau[:,colonne].min() @@ -102,15 +87,6 @@ def normalise_tableau_aire(tableau): ############################################################################### # 4- fonction qui sauvegarde le résultat dans un fichier tsv dans le sous répertoire ############################################################################### -#def enregistre_fichier_0(repertoire, tableau, nom_fichier): -# os.chdir(repertoire) -# nom_fichier=nom_fichier[0:-4] + "_" + repertoire[-7:] +".tsv" -# fsortie=open(nom_fichier,"w") -# fsortie.write(tableau) -# fsortie.close() -# #ecrit_tsv=csv.writer(fsortie, delimiter = '\t') -# #ecrit_tsv.writerow(document) - def enregistre_fichier(tableau,nom_fichier): numpy.savetxt(nom_fichier,tableau,delimiter="\t", newline="\n") @@ -119,6 +95,9 @@ def enregistre_fichier_virgule(tableau,nom_fichier): tableau=numpy.char.replace(tableau, ".", ",") numpy.savetxt(nom_fichier,tableau,delimiter="\t", newline="\n", fmt="%s") +def enregistre_tableau_abscisses(tableau_abscisses): + numpy.savetxt("tableau_abscisses.txt", tableau_abscisses, newline="\n") + ############################################################################### # 5- fonctions qui affiche et sauvegarde des graphes ############################################################################### @@ -176,32 +155,20 @@ def graphique_sauvegarde(tableau8bits) : ############################################################################### # programme principal ############################################################################### -def main_commun(rep_travail,nom_echantillon,bornes) : +def main (rep_travail,nom_echantillon,bornes) : + global tableau_norm liste_fichiers=creation_liste_fichiers(rep_travail) + tableau_abscisses=creer_tableau_abscisses(liste_fichiers) + enregistre_tableau_abscisses(tableau_abscisses) tableau=creer_tableau(liste_fichiers) - #tableau_norm=normalise_tableau_maxi(tableau) tableau_norm=normalise_tableau_aire(tableau) - #enregistre_fichier_0(rep_travail, tableau_norm,"tableau_normalisé.txt") enregistre_fichier(tableau_norm,"tableau_normalisé.txt") enregistre_fichier_virgule(tableau_norm,"tableau_normalisé_virgules.txt") tableau8bits=tableau_transpose_256gris(tableau_norm) - graphique_creation(tableau8bits,nom_echantillon,bornes) graphique_sauvegarde(tableau8bits) - if LIBStick_echange_vars.flag_3D == 1 : - graphique_3D_creation(tableau8bits,nom_echantillon,bornes) - + if LIBStick_echange_vars.L_ext_flag_2D : + graphique_creation(tableau8bits,nom_echantillon,bornes) + if LIBStick_echange_vars.L_ext_flag_3D == 1 : + graphique_3D_creation(tableau8bits,nom_echantillon,bornes) + -def main (rep_travail,nom_echantillon,bornes) : - main_commun(rep_travail,nom_echantillon,bornes) - -if __name__=='__main__': - #rep_travail=repertoire_de_travail_0(rep_script) - nom_echantillon="Spectres LIBS" - bornes=[0,100] - if (len(sys.argv)) <= 1 : - rep_travail_relatif="/" - else : - rep_travail_relatif=sys.argv[1] - rep_script=os.getcwd() - rep_travail=repertoire_de_travail(rep_script,rep_travail_relatif) - main_commun(rep_travail,nom_echantillon,bornes) diff --git a/LIBStick_echange_vars.py b/LIBStick_echange_vars.py old mode 100755 new mode 100644 index 12f1bcd..e61faea --- a/LIBStick_echange_vars.py +++ b/LIBStick_echange_vars.py @@ -5,9 +5,42 @@ @author: yannick """ +import numpy, pandas -nombre_fichiers=50 -liste_fichiers=[] -flag_3D=0 -bornes_moyenne_spectres=[] +#nombre_fichiers=50 +#liste_fichiers=[] +#flag_2D=1 +#flag_3D=0 +#flag_zone2=1 +#bornes_moyenne_spectres=[] +#nom_echantillon=str() +# +#flag_denominateur=1 +#limites_spectre=[] +#DataFrame_resultats=pandas.DataFrame() + +############################################################################### +# 1- variables pour LIBStick_extraction (L_ext_) +############################################################################### +L_ext_nombre_fichiers=50 +L_ext_liste_fichiers=[] +L_ext_flag_2D=1 +L_ext_flag_3D=0 +L_ext_flag_zone2=1 +L_ext_bornes_moyenne_spectres=[] +L_ext_nom_echantillon=str() + + +############################################################################### +# 2- variables pour LIBStick_compare (L_comp_) +############################################################################### +L_comp_nombre_fichiers=50 +L_comp_liste_fichiers=[] +L_comp_flag_2D=1 +L_comp_flag_3D=0 +L_comp_bornes_moyenne_spectres=[] +L_comp_nom_echantillon=str() +L_comp_flag_denominateur=1 +L_comp_limites_spectre=[] +L_comp_DataFrame_resultats=pandas.DataFrame() diff --git a/LIBStick_extraction_spectres.py b/LIBStick_extraction_spectres.py old mode 100755 new mode 100644 index 280b48a..7a8d5cb --- a/LIBStick_extraction_spectres.py +++ b/LIBStick_extraction_spectres.py @@ -16,8 +16,8 @@ ############################################################################### import sys,os,numpy -import LIBStick_creation_tableau_norm import LIBStick_echange_vars +import LIBStick_creation_tableau_norm sys.path.insert(0,os.path.join(os.path.expanduser("~"),"Desktop")) sys.path.insert(0,"./dossier_mes_modules/") @@ -34,27 +34,12 @@ def creation_liste_fichiers(rep_travail): return liste def creation_nom_echantillon(liste_fichiers): - nom_echantillon=LIBStick_echange_vars.liste_fichiers[0][0:-6] + nom_echantillon=LIBStick_echange_vars.L_ext_liste_fichiers[0][0:-6] return nom_echantillon ############################################################################### # 2- fonction qui ouvre un fichier et extrait les lignes de 528 à 543 nm ou de 592 à 608 nm ############################################################################### -#def lit_fichier_0(fichier, bas, haut): -# fentree=open(fichier,"r",encoding="Latin-1") -# document_tronc="" -# i=0 -# for ligne in fentree : -# i=i+1 -# if i>64 : -# liste_mots=ligne.split() -# if float(liste_mots[0]) >= bas and float(liste_mots[0]) <= haut : -# #document2=document2 + "\n" + ligne -# document_tronc=document_tronc + ligne -# fentree.close() -# document_tronc.replace(" ", "\t") -# return document_tronc - def lit_fichier(fichier, bas, haut): document=numpy.loadtxt(fichier,delimiter="\t",skiprows=64, usecols=[0,1],dtype=float,encoding="Latin-1") document_tronc=numpy.zeros((0,2)) @@ -68,39 +53,30 @@ def lit_spectre(fichier): 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]<=608) : + if (ligne[0]<=1013) : spectre=numpy.row_stack((spectre,ligne)) return spectre ############################################################################### # 3- fonction qui crée un sous répertoire d'un certain nom passé en argument ############################################################################### -#def repertoire_de_travail_0(rep_script): -# rep_travail=rep_script+"/test_python_Zone_1/" -# return rep_travail - def repertoire_de_travail(rep_script,rep_travail_relatif): rep_travail=rep_script+"/"+rep_travail_relatif return rep_travail def creation_sous_repertoire(rep_travail,tableau_bornes): - if not os.path.isdir(rep_travail + "/"+str(tableau_bornes[0,0])+"_"+str(tableau_bornes[0,1])): - os.mkdir(rep_travail + "/"+str(tableau_bornes[0,0])+"_"+str(tableau_bornes[0,1])) - if not os.path.isdir(rep_travail + "/"+str(tableau_bornes[1,0])+"_"+str(tableau_bornes[1,1])): - os.mkdir(rep_travail + "/"+str(tableau_bornes[1,0])+"_"+str(tableau_bornes[1,1])) + if LIBStick_echange_vars.L_ext_flag_zone2 : + if not os.path.isdir(rep_travail + "/"+str(tableau_bornes[0,0])+"_"+str(tableau_bornes[0,1])): + os.mkdir(rep_travail + "/"+str(tableau_bornes[0,0])+"_"+str(tableau_bornes[0,1])) + if not os.path.isdir(rep_travail + "/"+str(tableau_bornes[1,0])+"_"+str(tableau_bornes[1,1])): + os.mkdir(rep_travail + "/"+str(tableau_bornes[1,0])+"_"+str(tableau_bornes[1,1])) + if LIBStick_echange_vars.L_ext_flag_zone2 == 0 : + if not os.path.isdir(rep_travail + "/"+str(tableau_bornes[0,0])+"_"+str(tableau_bornes[0,1])): + os.mkdir(rep_travail + "/"+str(tableau_bornes[0,0])+"_"+str(tableau_bornes[0,1])) ############################################################################### # 4- fonction qui sauvegarde le résultat dans un fichier tsv dans le sous répertoire ############################################################################### -#def enregistre_fichier_0(document,repertoire,nom_fichier): -# os.chdir(repertoire) -# nom_fichier=nom_fichier[0:-4] + "_" + repertoire[-7:] +".tsv" -# fsortie=open(nom_fichier,"w") -# fsortie.write(document) -# fsortie.close() -# #ecrit_tsv=csv.writer(fsortie, delimiter = '\t') -# #ecrit_tsv.writerow(document) - def enregistre_fichier(document,repertoire,nom_fichier): os.chdir(repertoire) nom_fichier=nom_fichier[0:-4] + "_" + repertoire[-7:] +".tsv" @@ -109,54 +85,22 @@ def enregistre_fichier(document,repertoire,nom_fichier): ############################################################################### # programme principal ############################################################################### -def main_commun(rep_script, rep_travail, tableau_bornes) : +def main(rep_travail, tableau_bornes) : + rep_script=os.getcwd() + print ("Flag 2 spectre : ") + print (LIBStick_echange_vars.L_ext_flag_zone2) + if LIBStick_echange_vars.L_ext_flag_zone2 == 0 : + tableau_bornes=numpy.delete(tableau_bornes, (1), axis=0) creation_sous_repertoire(rep_travail,tableau_bornes) - #LIBStick_echange_vars.liste_fichiers=creation_liste_fichiers(rep_travail) - LIBStick_echange_vars.nombre_fichiers=len(LIBStick_echange_vars.liste_fichiers) - nom_echantillon=creation_nom_echantillon(LIBStick_echange_vars.liste_fichiers) - -# for i in range(len(liste_fichiers)) : -# os.chdir(rep_travail) -# document_528_543=lit_fichier_0(liste_fichiers[i], 528, 543) -# document_592_608=lit_fichier_0(liste_fichiers[i], 592, 608) -# enregistre_fichier_0(document_528_543,rep_travail+"/528_543",liste_fichiers[i]) -# enregistre_fichier_0(document_592_608,rep_travail+"/592_608",liste_fichiers[i]) - -# for i in range(len(liste_fichiers)) : -# os.chdir(rep_travail) -# document_528_543=lit_fichier(liste_fichiers[i], 528, 543) -# document_592_608=lit_fichier(liste_fichiers[i], 592, 608) -# enregistre_fichier(document_528_543,rep_travail+"/528_543",liste_fichiers[i]) -# enregistre_fichier(document_592_608,rep_travail+"/592_608",liste_fichiers[i]) - - for i in range(len(LIBStick_echange_vars.liste_fichiers)) : + #LIBStick_echange_vars.L_ext_liste_fichiers=creation_liste_fichiers(rep_travail) +# LIBStick_echange_vars.L_ext_nombre_fichiers=len(LIBStick_echange_vars.L_ext_liste_fichiers) + LIBStick_echange_vars.L_ext_nom_echantillon=creation_nom_echantillon(LIBStick_echange_vars.L_ext_liste_fichiers) + for i in range(len(LIBStick_echange_vars.L_ext_liste_fichiers)) : for bornes in tableau_bornes : os.chdir(rep_travail) - document=lit_fichier(LIBStick_echange_vars.liste_fichiers[i], bornes[0], bornes[1]) - enregistre_fichier(document,rep_travail+"/"+str(bornes[0])+"_"+ str(bornes[1]) ,LIBStick_echange_vars.liste_fichiers[i]) - -# os.chdir(rep_script) -# LIBStick_normalisation_creation_tableau.main(rep_travail_relatif+"528_543/") -# os.chdir(rep_script) -# LIBStick_normalisation_creation_tableau.main(rep_travail_relatif+"592_608/") - + document=lit_fichier(LIBStick_echange_vars.L_ext_liste_fichiers[i], bornes[0], bornes[1]) + enregistre_fichier(document,rep_travail+"/"+str(bornes[0])+"_"+ str(bornes[1]) ,LIBStick_echange_vars.L_ext_liste_fichiers[i]) for bornes in tableau_bornes : os.chdir(rep_script) - LIBStick_creation_tableau_norm.main(rep_travail+"/"+str(bornes[0])+"_"+ str(bornes[1])+"/", nom_echantillon,bornes) - - -def main(rep_travail, tableau_bornes) : - rep_script=os.getcwd() - main_commun(rep_script, rep_travail, tableau_bornes) - -if __name__=='__main__': - tableau_bornes=numpy.array([[528, 543],[592, 608]]) - rep_script=os.getcwd() - #rep_travail=repertoire_de_travail_0(rep_script) - if (len(sys.argv)) <= 1 : - rep_travail_relatif="/" - else : - rep_travail_relatif=sys.argv[1] - rep_travail=repertoire_de_travail(rep_script,rep_travail_relatif) - main_commun(rep_script, rep_travail, tableau_bornes) + LIBStick_creation_tableau_norm.main(rep_travail+"/"+str(bornes[0])+"_"+ str(bornes[1])+"/", LIBStick_echange_vars.L_ext_nom_echantillon,bornes)