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

import Tkinter as tk
4
from Ewindow import *
5
from numerical import *
6 7 8 9 10 11 12
import tkFileDialog

fig = plt.figure()
ax = fig.add_subplot(111)
fig.canvas.set_window_title("Signal") 
xx = arange(0,1, 0.1)         		 
temp, = plot(xx,xx*0) 
13 14
xlabel("Enegy (eV)")
ylabel("Yield")
15
doseold = 12e34 
16

17
##############################################################################
18
# Arbitrary parameters to declare dictionaries
19
param = dict(dedx=192. ,Theta_out=70., dW2dx=20740., E0= 100000., Theta_in=0., FWHM0=180.)
20
ionb = dict(Z=1, mass=1.0079)
21
OFlabentries = list()
22

23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
##############################################################################
# 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():
39 40 41
    fraction = float(OFlabentries[24].get())/doseold
    newdata = temp.ydata*fraction
    temp.set_ydata(newdata)
42 43 44
    doseold = float(OFlabentries[24].get())
    show()

45
##############################################################################
46
# Calculation callback
47
# Get parameters
48 49

def init_calc():
50
    global modelvar
51 52 53 54 55 56 57 58
    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())      
Matheus Müller's avatar
Matheus Müller committed
59
 
60 61
    if int(modevar.get()) == 0:
        if int(distvar.get()) == 1:
62 63
            for i in range(len(Edict)):
                Edict[i]['dist'] = np.loadtxt(Edict[i]['symbol']+".prof")
64
            spectro(param, str(modelvar.get()), ionb, OFlabentries, int(LSvar.get()), int(CGvar.get()), temp)
65
        elif int(distvar.get()) == 0:
66
            spectrolayer(param, str(modelvar.get()), ionb, OFlabentries, int(LSvar.get()), int(CGvar.get()), temp)
67

68
    elif int(modevar.get()) == 1:
69
        spectroRNA(param, str(modelvar.get()), ionb, OFlabentries, int(LSvar.get()), int(CGvar.get()), temp)
70

71
##############################################################################
72 73 74
# Main window

root = tk.Tk()
75
root.minsize(670,610)
76
root.title('Open Flatus')
77
root.geometry('670x500+200+400')
78

79
##############################################################################
80 81 82
# Frames
MasterFrame1 = tk.Frame(root)
MasterFrame1.pack(side='left')
83 84
MasterFrame2 = tk.Frame(root)
MasterFrame2.pack(side='top')
85

86 87
Label0 = tk.LabelFrame(MasterFrame1, text = 'Experiment', relief='raised', bd=2)
Label0.pack(side='top')
88 89 90
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)
91
Label3.pack(side='top')
92 93
Label5 = tk.LabelFrame(MasterFrame1, text = 'Graphical parameters', relief='raised', bd=2)
Label5.pack(side='top')
94 95 96 97 98 99
Label4 = tk.LabelFrame(MasterFrame1, text = 'Energy loss model', relief='raised', bd=2)
Label4.pack(side='top')

# Elements frame
Label1 = tk.Frame(MasterFrame2)
Label1.pack(side='top')
100 101 102 103 104 105

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

106 107 108 109 110
Gframel = tk.Frame(Label5)
Gframel.pack(side='left')
Gframee = tk.Frame(Label5)
Gframee.pack(side='right')

111
Iframel = tk.Frame(Label3, width=9)
112
Iframel.pack(side='left')
113
Iframee = tk.Frame(Label3, width=11)
114
Iframee.pack(side='right')
115

116
##############################################################################
117
# Parameters
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
# 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

OFlabentries.insert(0, tk.Label(Pframel, width=9, text='dƐ/dx', pady=2))
OFlabentries.insert(1, tk.Label(Pframel, width=9, text='dω²/dx', pady=2))
OFlabentries.insert(2, tk.Label(Pframel, width=9, text='θ out', pady=2))
OFlabentries.insert(3, tk.Label(Pframel, width=9, text='θ in', pady=2))
OFlabentries.insert(4, tk.Label(Pframel, width=9, text='FWHM0', pady=2))
134 135
OFlabentries.insert(5, tk.Label(Pframel, width=9, text='Emin', pady=2))
OFlabentries.insert(6, tk.Label(Pframel, width=9, text='Emax', pady=2))
136 137
OFlabentries.insert(7, tk.Label(Pframel, width=9, text='Estep', pady=2))
OFlabentries.insert(8, tk.Label(Pframel, width=9, text='Depth step', pady=2))
138 139 140
OFlabentries.insert(24, tk.Entry(Gframee, width=11))
OFlabentries.insert(25, tk.Label(Gframel, width=9, text='Dose', pady=2))

141
# Entries
142
for n in arange(9,18):
143
    OFlabentries.insert(n, tk.Entry(Pframee, width=11))
144 145

#Ion
146 147 148 149 150 151 152 153 154 155
# Labels // Entries numbers:
# 18 // 21 = Initial Energy
# 19 // 22 = mass
# 20 // 23 = Z (atomic number)
OFlabentries.insert(18, tk.Label(Iframel, width=9, text='Energy'))
OFlabentries.insert(19, tk.Label(Iframel, width=9, text='Mass'))
OFlabentries.insert(20, tk.Label(Iframel, width=9, text='Z'))

for n in arange(21,24):
    OFlabentries.insert(n, tk.Entry(Iframee, width=11))
156 157

for n in range(26):
158
    OFlabentries[n].pack()
159

160
##############################################################################
161
# Initial values
162 163 164 165 166 167 168 169 170 171 172 173 174

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) 
OFlabentries[17].insert(0,0.01) 
OFlabentries[21].insert(0,param['E0'])
OFlabentries[22].insert(0, ionb['mass'])
OFlabentries[23].insert(0, ionb['Z'])
175
OFlabentries[24].insert(0, "12e34")
176 177 178 179 180 181 182 183

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

Adjbut = tk.Button(Gframee, text = 'Adjust', command = init_calc, width=8)
Databut = tk.Button(Gframel, text = 'Exp Data', command = loadexp, width=6)
Adjbut.pack()
Databut.pack()
184

185
##############################################################################
186 187 188
# Energy loss models

modelvar = tk.StringVar()
189
modelvar.set('bessel')
190 191 192 193
R1 = tk.Radiobutton(Label4, text="Gaussian", variable=modelvar, value='gaussiana')
R1.pack()
R2 = tk.Radiobutton(Label4, text="Bessel", variable=modelvar, value='bessel')
R2.pack()
194
R2.select()
195

196
##############################################################################
197
# Line shape/Convolve gaussian checkbox
198 199

LSvar = tk.IntVar()
200
LSvar.set(1)
201
CGvar = tk.IntVar()
202
CGvar.set(1)
203 204
C1 = tk.Checkbutton(Label4, text="Use Line Shape", variable=LSvar)
C1.pack()
205
C1.select()
206 207 208
C2 = tk.Checkbutton(Label4, text="Resolution Convolve", variable=CGvar)
C2.pack()
C2.select()
209 210

##############################################################################
211
# Calculate and Exit buttons
212

213
CalcButton = tk.Button(Label4, text = 'Calculate', command = init_calc, bd=4, width=17, height=2)
214 215
CalcButton.pack()

216
##############################################################################
217 218
# Elements callback

219
modevar = tk.IntVar()
Matheus Müller's avatar
Matheus Müller committed
220
modevar.set(0)
221
distvar = tk.IntVar()
Matheus Müller's avatar
Matheus Müller committed
222
distvar.set(1)
223
ewin_build(Label1, OFlabentries, root, CalcButton, distvar, modevar, Label0)
224

225
##############################################################################
226 227 228

root.mainloop()

229
##############################################################################