OpenFlatus.py 7.58 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 13
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) 
doseold = 12e34 
14

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

21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
##############################################################################
# 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():
    temp.set_xdata(arange(OFlabentries[14].get(),OFlabentries[15].get(),OFlabentries[16].get()))           
    temp.set_ydata(temp.ydata/doseold*float(OFlabentries[24].get()))
    doseold = float(OFlabentries[24].get())
    show()

42
##############################################################################
43
# Calculation callback
44
# Get parameters
45 46

def init_calc():
47
    global modelvar
48 49 50 51 52 53 54 55
    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())      
56

57 58 59 60
    if str(modevar.get()) == 'IONS':
        if str(distvar.get()) == 'drawing':
            for i in range(len(Edict)):
                Edict[i]['dist'] = np.loadtxt(Edict[i]['symbol']+".prof")
61
            spectro(param, str(modelvar.get()), ionb, OFlabentries, int(LSvar.get()), int(CGvar.get()), temp)
62
        elif str(distvar.get()) == 'layer':
63
            spectrolayer(param, str(modelvar.get()), ionb, OFlabentries, int(LSvar.get()), int(CGvar.get()), temp)
64

65
    elif str(modevar.get()) == 'RRNA':
66
        spectroRNA(param, str(modelvar.get()), ionb, OFlabentries, int(LSvar.get()), int(CGvar.get()), temp)
67

68
##############################################################################
69 70 71
# Main window

root = tk.Tk()
72
root.minsize(670,610)
73
root.title('Open Flatus')
74
root.geometry('670x500+200+400')
75

76
##############################################################################
77 78 79
# Frames
MasterFrame1 = tk.Frame(root)
MasterFrame1.pack(side='left')
80 81
MasterFrame2 = tk.Frame(root)
MasterFrame2.pack(side='top')
82

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

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

103 104 105 106 107
Gframel = tk.Frame(Label5)
Gframel.pack(side='left')
Gframee = tk.Frame(Label5)
Gframee.pack(side='right')

108
Iframel = tk.Frame(Label3, width=9)
109
Iframel.pack(side='left')
110
Iframee = tk.Frame(Label3, width=11)
111
Iframee.pack(side='right')
112

113
##############################################################################
114
# Parameters
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
# 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))
131 132
OFlabentries.insert(5, tk.Label(Gframel, width=9, text='Emin', pady=2))
OFlabentries.insert(6, tk.Label(Gframel, width=9, text='Emax', pady=2))
133 134
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))
135 136 137
OFlabentries.insert(24, tk.Entry(Gframee, width=11))
OFlabentries.insert(25, tk.Label(Gframel, width=9, text='Dose', pady=2))

138 139

# Entries
140
for n in arange(9,18):
141 142 143 144
    if n == 14 or n == 15:
        OFlabentries.insert(n, tk.Entry(Gframee, width=11))
    else:
        OFlabentries.insert(n, tk.Entry(Pframee, width=11))
145 146

#Ion
147 148 149 150 151 152 153 154 155 156
# 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))
157 158

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

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

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'])
176 177 178 179 180 181 182 183 184 185
OFlabentries[24].insert(0, 12e34)
doseold = float(OFlabentries[24].get())

##############################################################################
# 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()
186

187
##############################################################################
188 189
# Energy loss models

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

200
##############################################################################
201
# Line shape/Convolve gaussian checkbox
202 203

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

##############################################################################
215
# Calculate and Exit buttons
216

217
CalcButton = tk.Button(Label4, text = 'Calculate', command = init_calc, bd=4, width=17, height=2)
218 219
CalcButton.pack()

220
##############################################################################
221 222
# Elements callback

223 224
distvar = tk.StringVar()
distvar.set('drawing')
225
ewin_build(Label1, OFlabentries, root, CalcButton, distvar, modevar, Label0)
226

227
##############################################################################
228 229 230

root.mainloop()

231
##############################################################################