OpenFlatus.py 11.3 KB
Newer Older
1 2 3
# -*- coding: iso-8859-15 -*-

import Tkinter as tk
4
from Ewindow import *
5 6
from calc import *
from spec import *
7

8
##############################################################################
9 10
# Arbitrary parameters to define dictionaries
param = dict(dedx=250. ,Theta_out=70., dW2dx=26500., E0= 100000, Theta_in=0., FWHM0=250.)
11
ionb = dict(Z=1, mass=1.0079)
12
OFlabentries = list()
13 14 15 16 17 18
Plot = dict()
Plotbuttons = list()
j = 0
Pcontrol = 0
doseold = 6.6e36 
FT = True
19

20
##############################################################################
21
##############################################################################
22 23 24
# Main window

root = tk.Tk()
25
root.minsize(800,720)
26
root.title('Open Flatus')
27
root.geometry('800x720+200+400')
28

29
##############################################################################
30 31 32
# Frames
MasterFrame1 = tk.Frame(root)
MasterFrame1.pack(side='left')
33 34
MasterFrame2 = tk.Frame(root)
MasterFrame2.pack(side='top')
35

36 37
Label0 = tk.LabelFrame(MasterFrame1, text = 'Experiment', relief='raised', bd=2)
Label0.pack(side='top')
38 39 40
Label2 = tk.LabelFrame(MasterFrame1, text = 'Parameters', relief='raised', bd=2)
Label2.pack(side='top')
Label3 = tk.LabelFrame(MasterFrame1, text = 'Ion parameters', relief='raised', bd=2)
41 42 43
Label3.pack(side='top')
Label4 = tk.LabelFrame(MasterFrame1, text = 'Energy loss model', relief='raised', bd=2)
Label4.pack(side='top')
44 45 46 47
Label5 = tk.LabelFrame(MasterFrame1, text = 'Graphical parameters', relief='raised', bd=2)
Label5.pack(side='top')
Label6 = tk.LabelFrame(MasterFrame1, text = 'Curve Selection', relief='raised', bd=2)
Label6.pack(side='top')
48 49 50 51

# Elements frame
Label1 = tk.Frame(MasterFrame2)
Label1.pack(side='top')
52 53 54 55 56 57

Pframel = tk.Frame(Label2)
Pframel.pack(side='left')
Pframee = tk.Frame(Label2)
Pframee.pack(side='right')

58 59 60 61 62
Gframel = tk.Frame(Label5)
Gframel.pack(side='left')
Gframee = tk.Frame(Label5)
Gframee.pack(side='right')

63
Iframel = tk.Frame(Label3)
64
Iframel.pack(side='left')
65
Iframee = tk.Frame(Label3)
66
Iframee.pack(side='right')
67

68
Dframe = tk.Frame(MasterFrame2, bd=2)
69
Dframe.pack(side='bottom',fill='both', expand=1)
70 71 72 73 74 75 76 77 78 79 80

##############################################################################
##############################################################################
# Controle de Plots - Inicio                                                 #
##############################################################################
# Embedded distribution

f = plt.figure()
a = f.add_subplot(111)

embedded_frame = tk.Frame(Dframe)
81
embedded_frame.pack(side='top',fill='both', expand=1)
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
    
dataPlot = FigureCanvasTkAgg(f, master=embedded_frame)
dataPlot.get_tk_widget().pack(side='top', fill='both', expand=1)

xx = arange(0, 100)       		  
temp, = a.plot(xx, xx*0, 'blue', lw=0.9)
xlabel('Depth (nm)')
ylabel('Concentration factor')
ylim([0,1])

##############################################################################
# Figura do plot de perda de energia

f2 = plt.figure()
xlabel('Energy (eV)')
ylabel('Yield')

##############################################################################
pltbutfrm = tk.Frame(Label6)
pltbutfrm.pack(side='bottom')
pltbutfrm2 = tk.Frame(Label6)
pltbutfrm2.pack(side='bottom')
pltbutfrm3 = tk.Frame(Label6)
pltbutfrm3.pack(side='bottom')

def plot_select(j, button):
    global Pcontrol, Plot
    button[Pcontrol]['relief']='raised'
    Pcontrol = j
    button[j]['relief']='sunken'

def add_plot():
    global j, Plot, Plotbuttons
    Plot[j], = plot(xx, xx*0, lw=0.9, label = '%s' %j)
    Plotbuttons.insert(j, tk.Button(pltbutfrm, text=j, width=1, height=1, command = lambda j=j : plot_select(j,Plotbuttons) ) )
    Plotbuttons[j].grid(column = ((len(Plotbuttons)-1)%5), row = int(math.floor((len(Plotbuttons)-1)/5)))
    j = j + 1

def rmv_plot():
    global j, Plot, Plotbuttons, Pcontrol
    if j > 1:
        j = j-1
        for a in range(Pcontrol+1,j+1):
            Plot[a-1] = Plot[a]
            Plotbuttons[a-1].configure(text = Plotbuttons[a]['text'])

        del Plot[j]
        Plotbuttons[j].destroy()
        del Plotbuttons[j]

        if Pcontrol == j:
            Pcontrol = Pcontrol -1
            Plotbuttons[Pcontrol]['relief']='sunken'
    plot_select(0, Plotbuttons)

baddplt = tk.Button(pltbutfrm2, command=add_plot, text='Add Plot', bd=1, height=1,width=7, pady='4')
baddplt.pack(side='left')
brmvplt = tk.Button(pltbutfrm2, command=rmv_plot, text='Remove Plot', bd=1, height=1,width=9, pady='4')
brmvplt.pack(side='left')

##############################################################################
# Controle de Plots - Fim                                                    #
##############################################################################
145
##############################################################################
146
# Parameters
147 148 149 150 151 152 153 154 155 156 157
# Labels // Entries numbers:
# 0 // 9 = dedx
# 1 // 10 = dW2dx
# 2 // 11 = theta out
# 3 // 12 = theta in
# 4 // 13 = FWHM0
# 5 // 14 = Energy min
# 6 // 15 = Energy max
# 7 // 16 = Energy step
# 8 // 17 = Depht step

158 159 160 161 162 163 164 165 166 167 168
OFlabentries.insert(0, tk.Label(Pframel, width=13, text='dƐ/dx (eV/nm)', pady=2))
OFlabentries.insert(1, tk.Label(Pframel, width=13, text='dω²/dx (eV²/nm)', pady=2))
OFlabentries.insert(2, tk.Label(Pframel, width=13, text='θ out (°)', pady=2))
OFlabentries.insert(3, tk.Label(Pframel, width=13, text='θ in (°)', pady=2))
OFlabentries.insert(4, tk.Label(Pframel, width=13, text='FWHM0 (eV)', pady=2))
OFlabentries.insert(5, tk.Label(Pframel, width=13, text='Emin (eV)', pady=2))
OFlabentries.insert(6, tk.Label(Pframel, width=13, text='Emax (eV)', pady=2))
OFlabentries.insert(7, tk.Label(Pframel, width=13, text='Estep (eV)', pady=2))
OFlabentries.insert(8, tk.Label(Pframel, width=13, text='Depth step (nm)', pady=2))
OFlabentries.insert(24, tk.Entry(Gframee, width=10))
OFlabentries.insert(25, tk.Label(Gframel, width=12, text='Dose', pady=2))
169

170
# Entries
171
for n in arange(9,18):
172
    OFlabentries.insert(n, tk.Entry(Pframee, width=10))
173 174

#Ion
175 176 177 178
# Labels // Entries numbers:
# 18 // 21 = Initial Energy
# 19 // 22 = mass
# 20 // 23 = Z (atomic number)
179 180 181
OFlabentries.insert(18, tk.Label(Iframel, width=13, text='Energy (KeV)'))
OFlabentries.insert(19, tk.Label(Iframel, width=13, text='Mass'))
OFlabentries.insert(20, tk.Label(Iframel, width=13, text='Z'))
182 183

for n in arange(21,24):
184
    OFlabentries.insert(n, tk.Entry(Iframee, width=10))
185 186

for n in range(26):
187
    OFlabentries[n].pack()
188

189 190 191
OFlabentries.insert(26, tk.Label(Dframe, pady=1, text='Left-Click:Draw   Middle-Click:Scale   Right-Click:Shift   Hotkeys: Normalize:Alt+N   Clear:Alt+C' ))
OFlabentries[26].pack(side='bottom',fill='x', expand=1)

192
##############################################################################
193
# Initial values
194 195 196 197 198 199 200 201 202

OFlabentries[9].insert(0,param['dedx'])
OFlabentries[10].insert(0,param['dW2dx'])
OFlabentries[11].insert(0,param['Theta_out'])
OFlabentries[12].insert(0,param['Theta_in'])
OFlabentries[13].insert(0,param['FWHM0'])
OFlabentries[14].insert(0,70000)
OFlabentries[15].insert(0,100000) 
OFlabentries[16].insert(0,20) 
203
OFlabentries[17].insert(0,0.05) 
204 205 206
OFlabentries[21].insert(0,param['E0'])
OFlabentries[22].insert(0, ionb['mass'])
OFlabentries[23].insert(0, ionb['Z'])
207
OFlabentries[24].insert(0, "6.6e36")
208

209
##############################################################################
210 211 212
# Energy loss models

modelvar = tk.StringVar()
213
modelvar.set('bessel')
214 215 216 217
R1 = tk.Radiobutton(Label4, text="Gaussian", variable=modelvar, value='gaussiana')
R1.pack()
R2 = tk.Radiobutton(Label4, text="Bessel", variable=modelvar, value='bessel')
R2.pack()
218
R2.select()
219

220
##############################################################################
221
# Line shape/Convolve gaussian checkbox
222 223

LSvar = tk.IntVar()
224
LSvar.set(1)
225
CGvar = tk.IntVar()
226
CGvar.set(1)
227 228
C1 = tk.Checkbutton(Label4, text="Use Line Shape", variable=LSvar)
C1.pack()
229
C1.select()
230
C2 = tk.Checkbutton(Label4, text="Resolution Convolve", variable=CGvar, width=21)
231 232
C2.pack()
C2.select()
233

234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249
##############################################################################
# Load experiment data

def loadexp():
    arquivo = tkFileDialog.askopenfilename()
    amostra = np.loadtxt(arquivo)
    xxx= amostra[:,0]*1000
    ccc=amostra[:,1]

    plot (xxx, ccc, 'r.')
    show()

##############################################################################
# Adjust graphic

def adjust():
250
    global doseold, Pcontrol, Plot, f
251
    fraction = float(OFlabentries[24].get())/doseold
252 253 254 255
    newdata = list()
    for x in range(len(Plot[Pcontrol].get_ydata())):
        newdata.insert(x, Plot[Pcontrol].get_ydata()[x]*fraction)
    Plot[Pcontrol].set_ydata(newdata)
256
    doseold = float(OFlabentries[24].get())
257 258
    ylim([0,max(Plot[Pcontrol].get_ydata())*1.1])       
    f2.canvas.draw()
259 260 261 262 263 264

##############################################################################
# Calculation callback
# Get parameters

def init_calc():
265
    global modelvar, FT, doseold
266 267 268 269 270 271 272 273 274
    param['dedx'] = float(OFlabentries[9].get())
    param['dW2dx'] = float(OFlabentries[10].get())
    param['Theta_out'] = float(OFlabentries[11].get())
    param['Theta_in'] = float(OFlabentries[12].get())
    param['E0'] = float(OFlabentries[21].get())
    param['FWHM0'] = float(OFlabentries[13].get())
    ionb['mass'] = float(OFlabentries[22].get())
    ionb['Z'] = float(OFlabentries[23].get())      
    espectro = spectro(int(float(OFlabentries[21].get())/float(OFlabentries[16].get())), int(OFlabentries[16].get()))         		 
275
    aux = spectro(int(float(OFlabentries[21].get())/float(OFlabentries[16].get())), int(OFlabentries[16].get()))         		 
276
    aux2 = spectro(int(float(OFlabentries[21].get())/float(OFlabentries[16].get())), int(OFlabentries[16].get()))         		 
277 278
    doseold = float(OFlabentries[24].get())

279 280 281 282 283
    LSi = int(LSvar.get())
    CGi = int(CGvar.get())

    if int(modevar.get()) == 0:
        if int(distvar.get()) == 1:
284
            calc(param, str(modelvar.get()), ionb, OFlabentries, LSi, CGi, 'draw', espectro, OFlabentries[14].get(), Plot, f2, FT, Plotbuttons, Pcontrol)
285
        elif int(distvar.get()) == 0:
286
            calc(param, str(modelvar.get()), ionb, OFlabentries, LSi, CGi, 'layer', espectro, OFlabentries[14].get(), Plot, f2, FT, Plotbuttons, Pcontrol)
287 288

    elif int(modevar.get()) == 1:
289
        spectrolayer(param, str(modelvar.get()), ionb, OFlabentries, LSi, CGi, 'layer', espectro, OFlabentries[14].get(), Plot, f2, FT, Plotbuttons, Pcontrol,aux,aux2)
290 291 292

    FT = False

293
##############################################################################
294
# Calculate and Exit buttons
295

296 297 298 299 300 301
CalcButton = tk.Button(pltbutfrm3, text = 'Calculate Energy Loss', command = init_calc, bd=4, width=19, height=2)
CalcButton.pack(side='bottom')

##############################################################################
# Grahical parameters buttons

302
Adjbut = tk.Button(Gframee, text = 'Adjust', command = adjust, width=8)
303 304 305
Databut = tk.Button(Gframel, text = 'Exp Data', command = loadexp, width=6)
Adjbut.pack()
Databut.pack()
306

307
##############################################################################
308
##############################################################################
309 310
# Elements callback

311
modevar = tk.IntVar()
Matheus Müller's avatar
Matheus Müller committed
312
modevar.set(0)
313
distvar = tk.IntVar()
Matheus Müller's avatar
Matheus Müller committed
314
distvar.set(1)
315
ewin_build(Label1, OFlabentries, root, CalcButton, distvar, modevar, Label0, temp, f, a)
316

317
##############################################################################
318

319 320
add_plot()
plot_select(0,Plotbuttons)
321 322
root.mainloop()

323
##############################################################################
324
##############################################################################