Das hatte ich eigentlich auch vor, aber das wird recht lang. Ich hoffe, dieser Teil reicht ...
Code: Alles auswählen
#!/usr/bin/env python
# Author: Sebastian Rhode
# Created: 2009-11-03
# Version: 1.6 - 2010-03-19
#
# Feel free to improve it! There still some bugs inside ...
import wx
import os, sys
import numpy as np
import wx.grid
# Matplotlib Figure object
from matplotlib.figure import Figure
# import the WxAgg FigureCanvas object, that binds Figure to
# WxAgg backend --> a wxPanel
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
# import the NavigationToolbar WxAgg widget
from matplotlib.backends.backend_wx import NavigationToolbar2Wx
# ------------------------------------------------------------------------------------
# global variables and additional functions
# range of graph
xmin_limit = 200
xmax_limit = 1500
# size of figure & resolution (dpi)
sizex = 12
sizey = 9
res = 100
# array with used laser wavelengths
wl = np.array([405, 445, 473, 488, 491, 515, 532, 561, 594, 640]) # wavelengths of Lasers
# corresponding colors in HEX-RGB code
colors = ['#8700ff','#5600ff','#00baff','#00f6ff','#00fffc','#00ffa0','#00ff64','#c1ff00','#ff8900','#ff001f']
# line width for displaying the laser lines
linew = 2
# ------------------------------------------------------------------------------------
# calculation for Raman lines
raman = np.zeros( (wl.shape[0], 4))
raman[:,0] = wl
for i in range (0,wl.shape[0],1):
raman1 = 1.0 /(1.0/wl[i]-1595/1E7)
raman2 = 1.0 /(1.0/wl[i]-3652/1E7)
raman3 = 1.0 /(1.0/wl[i]-3756/1E7)
raman[i,1] = raman1
raman[i,2] = raman2
raman[i,3] = raman3
# normalizes dye spectra to 1
def normspec(datain):
out = datain
out[:,1] = datain[:,1]/datain[:,1].max(0)
return out
# converts filters spectra to 0-1 range
#def normspec_filter(datain):
# out = datain
# if datain[:,1].max(0)>10:
# out[:,1] = datain[:,1]/100
# print "max. value: ", datain[:,1].max(0)
# print 'Filter normalized !!!'
# return out
def normspec_filter(datain): # converts filters spectra to 0-1 range
out = datain
maxvalue = datain[:,1].max(0)
#print 'maxvalue: ', maxvalue
if (maxvalue > 1):
decdigits = np.floor(np.log(maxvalue)/np.log(10)) + 1
out[:,1] = datain[:,1]/10**(decdigits)
print 'maxvalue: ', maxvalue
print 'Filter Normalized by division: ', 10**(decdigits)
return out
def AdjustDisplay(self):
self.page_graph.axes.axis([self.xmin, self.xmax, self.ymin, self.ymax])
self.page_graph.axes.legend(loc=4)
leg = self.page_graph.axes.legend(loc='lower right')
# matplotlib.text.Text instances
try:
for t in leg.get_texts():
t.set_fontsize('small') # the legend text fontsize
except:
test=1
self.page_graph.figure.canvas.draw()
class Page_Abs(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent)
class Page_Flu(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent)
class Page_Ex(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent)
class Page_Di(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent)
class Page_Em(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent)
class Page_Ls(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent)
class Page_Misc(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent)
class MplPanel(wx.Panel):
def __init__(self, *args, **kwds):
wx.Panel.__init__(self, *args, **kwds)
self.__set_properties()
self.__do_layout()
xmin = 320
xmax = 700
ymin = 0
ymax = 1.05
self.figure = Figure(figsize=(sizex, sizey), dpi=res)
self.axes = self.figure.add_subplot(111)
self.axes.set_xticks(np.arange(xmin_limit, xmax_limit, 20))
self.axes.set_yticks(np.arange(ymin, ymax, 0.1));
self.axes.axis([xmin,xmax,ymin,ymax])
self.axes.grid(True)
self.axes.set_xlabel('Wavelength [nm]',fontsize=14)
self.axes.set_ylabel('Transmission [%] or Intensity [a.u.]',fontsize=14)
self.figure.subplots_adjust(left=0.07, bottom=0.09, right=0.97, top=0.94,wspace=0.20, hspace=0.20)
# we bind the figure to the FigureCanvas, so that it will be drawn using the specific backend
self.canvas = FigureCanvas(self, wx.ID_ANY, self.figure)
# create an BoxSizer, to define the layout of our window
self.sizer = wx.BoxSizer(wx.VERTICAL)
# add the figure canvas
self.sizer.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.EXPAND)
# instantiate the Navigation Toolbar
self.toolbar = NavigationToolbar2Wx(self.canvas)
# needed to support Windows systems
self.toolbar.Realize()
# add it to the sizer
self.sizer.Add(self.toolbar, 0, wx.LEFT | wx.EXPAND)
# explicitly show the toolbar
self.toolbar.Show()
# sets the window to have the given layout sizer
self.SetSizer(self.sizer)
# adapt sub-widget sizes to fit the window size following sizer specification
self.Fit()
def __set_properties(self):
# begin wxGlade: MplPanel.__set_properties
pass
# end wxGlade
def __do_layout(self):
# begin wxGlade: MplPanel.__do_layout
pass
# end wxGlade
class MplFrame(wx.Frame):
def __init__(self, *args, **kwds):
kwds['style'] = wx.CAPTION|wx.CLOSE_BOX|wx.MINIMIZE_BOX|wx.MAXIMIZE|wx.MAXIMIZE_BOX|wx.SYSTEM_MENU|wx.RESIZE_BORDER|wx.FULL_REPAINT_ON_RESIZE|wx.CLIP_CHILDREN
wx.Frame.__init__(self, *args, **kwds)
# Here we create a panel and a notebook on the panel
p = wx.Panel(self)
self.nb = wx.Notebook(p)
# create the page windows as children of the notebook
self.page_graph = MplPanel(self.nb)
self.page_abs = Page_Abs(self.nb)
self.page_flu = Page_Flu(self.nb)
self.page_ex = Page_Ex(self.nb)
self.page_di = Page_Di(self.nb)
self.page_em = Page_Em(self.nb)
self.page_ls = Page_Ls(self.nb)
self.page_misc = Page_Misc (self.nb)
# add the pages to the notebook with the label to show on the tab
self.nb.AddPage(self.page_graph, 'Graph')
self.nb.AddPage(self.page_abs, 'Abs')
self.nb.AddPage(self.page_flu, 'Flu')
self.nb.AddPage(self.page_ex, 'Ex')
self.nb.AddPage(self.page_di, 'Di')
self.nb.AddPage(self.page_em, 'Em')
self.nb.AddPage(self.page_ls, 'Ls')
self.nb.AddPage(self.page_misc, 'Misc')
self.createMenuBar()
self.MplFrame_statusbar = self.CreateStatusBar(1, 0)
self.__set_properties()
self.__do_layout()
# default x/y scaling values
self.xmin = 320
self.xmax = 700
self.ymin = 0
self.ymax = 1.05
def menuData(self):
return (('File',
('Save Graph As...', '', self.OnSaveAs, wx.ITEM_NORMAL, True),
('', '', '', '', ''), # separator
('Set Working Directory', '', self.OnSetDir, wx.ITEM_NORMAL, True),
('', '', '', '', ''), # separator
('Quit', '', self.OnQuit, wx.ITEM_NORMAL, True)),
('Dyes',
('Load Dye Absorption', '', self.OnLoadAbs, wx.ITEM_NORMAL, True),
('Load Dye Emission', '', self.OnLoadFlu, wx.ITEM_NORMAL, True),
('', '', '', '', ''),
('Delete last Absorption', '', self.OnDelAbs, wx.ITEM_NORMAL, False),
('Delete last Emission', '', self.OnDelFlu, wx.ITEM_NORMAL, False)),
('Filter',
('Load Excitation Filter', '', self.OnLoadEx, wx.ITEM_NORMAL, True),
('Load Dichroic Mirror', '', self.OnLoadDi, wx.ITEM_NORMAL, True),
('Load Emission Filter', '', self.OnLoadEm, wx.ITEM_NORMAL, True),
('', '', '', '', ''),
('Delete last Excitation Filter', '', self.OnDelEx, wx.ITEM_NORMAL, False),
('Delete last Dichroic Mirror', '', self.OnDelDi, wx.ITEM_NORMAL, False),
('Delete Last Emission Filter', '', self.OnDelEm, wx.ITEM_NORMAL, False)),
('Light Source',
('Load Light Source', '', self.OnLoadLs, wx.ITEM_NORMAL, True),
('', '', '', '', ''),
('Delete last Light Source', '', self.OnDelLs, wx.ITEM_NORMAL, False)),
('Misc. Spectra',
('Load misc. Spec', '', self.OnLoadMisc, wx.ITEM_NORMAL, True),
('', '', '', '', ''),
('Delete misc. Spec', '', self.OnDelMisc, wx.ITEM_NORMAL, False)),
('Fura Excitation',
('Fura 340nm', '', self.OnShowFura340, wx.ITEM_CHECK, True),
('Fura 380nm', '', self.OnShowFura380, wx.ITEM_CHECK, True)),
('Laser Lines',
('405nm', '', self.OnShow405, wx.ITEM_CHECK, True),
('445nm', '', self.OnShow445, wx.ITEM_CHECK, True),
('473nm', '', self.OnShow473, wx.ITEM_CHECK, True),
('488nm', '', self.OnShow488, wx.ITEM_CHECK, True),
('491nm', '', self.OnShow491, wx.ITEM_CHECK, True),
('515nm', '', self.OnShow515, wx.ITEM_CHECK, True),
('532nm', '', self.OnShow532, wx.ITEM_CHECK, True),
('561nm', '', self.OnShow561, wx.ITEM_CHECK, True),
('594nm', '', self.OnShow594, wx.ITEM_CHECK, True),
('640nm', '', self.OnShow640, wx.ITEM_CHECK, True),
('', '', '', '', ''),
('Custom Laser', '', self.OnShowCustomLaser, wx.ITEM_CHECK, True)),
('H2O Raman Lines',
('H2O Raman 405nm', '', self.OnShowRaman405, wx.ITEM_CHECK, True),
('H2O Raman 445nm', '', self.OnShowRaman445, wx.ITEM_CHECK, True),
('H2O Raman 473nm', '', self.OnShowRaman473, wx.ITEM_CHECK, True),
('H2O Raman 488nm', '', self.OnShowRaman488, wx.ITEM_CHECK, True),
('H2O Raman 491nm', '', self.OnShowRaman491, wx.ITEM_CHECK, True),
('H2O Raman 515nm', '', self.OnShowRaman515, wx.ITEM_CHECK, True),
('H2O Raman 532nm', '', self.OnShowRaman532, wx.ITEM_CHECK, True),
('H2O Raman 561nm', '', self.OnShowRaman561, wx.ITEM_CHECK, True),
('H2O Raman 594nm', '', self.OnShowRaman594, wx.ITEM_CHECK, True),
('H2O Raman 640nm', '', self.OnShowRaman640, wx.ITEM_CHECK, True),
('', '', '', '', ''),
('Custom Raman Laser', '', self.OnShowCustomRaman, wx.ITEM_CHECK, True)),
('Scaling Options',
('Set X-Min Value', '', self.OnSetXMin, wx.ITEM_NORMAL, True),
('Set X-Max Value', '', self.OnSetXMax, wx.ITEM_NORMAL, True)))
def createMenuBar(self):
menuBar = wx.MenuBar()
for eachMenuData in self.menuData():
menuLabel = eachMenuData[0]
menuItems = eachMenuData[1:]
menuBar.Append(self.createMenu(menuItems), menuLabel)
self.SetMenuBar(menuBar)
def createMenu(self, menuData):
menu = wx.Menu()
for eachLabel, eachStatus, eachHandler, eachKind, eachEnable in menuData:
if not eachLabel:
menu.AppendSeparator()
continue
menuItem = menu.Append(-1, eachLabel, eachStatus, eachKind)
menuItem.Enable(eachEnable)
self.Bind(wx.EVT_MENU, eachHandler, menuItem)
return menu
def __set_properties(self):
self.SetTitle('Spectra 1.6 - by Sebastian Rhode')
self.SetSize((sizex*res, sizey*res))
self.MplFrame_statusbar.SetStatusWidths([-1])
# statusbar fields
MplFrame_statusbar_fields = ['MplFrame_statusbar']
for i in range(len(MplFrame_statusbar_fields)):
self.MplFrame_statusbar.SetStatusText(MplFrame_statusbar_fields[i], i)
def __do_layout(self):
mplsizer1 = wx.BoxSizer(wx.VERTICAL)
mplsizer1.Add(self.nb, 1, wx.ALL|wx.EXPAND, 0)
self.SetSizer(mplsizer1)
self.Layout()
...