#!/usr/bin/python # fitDialog.py import wx from PlotPanel import PlotPanel from plottables import Theory1D import math,pylab,fittings class LinearFit(wx.Dialog): #def __init__(self, parent, id, title): def __init__(self, parent, plottable, push_data, id, title): wx.Dialog.__init__(self, parent, id, title, size=(550, 300)) """ for the fit window """ self.parent = parent #dialog panel self call function to plot the fitting function self.push_data = push_data #dialog self plottable self.plottable = plottable #Dialog interface panel = wx.Panel(self, -1, style=wx.SIMPLE_BORDER) vbox = wx.BoxSizer(wx.VERTICAL) sizer = wx.GridBagSizer(5,0) vbox.Add(panel, 1, wx.EXPAND | wx.ALL) self.tcA = wx.TextCtrl(panel, -1,size=(120,20),style=wx.SIMPLE_BORDER) self.tcErrA = wx.TextCtrl(panel, -1,size=(120,20),style=wx.SIMPLE_BORDER) self.tcB = wx.TextCtrl(panel, -1,size=(120,20),style=wx.SIMPLE_BORDER) self.tcErrB = wx.TextCtrl(panel, -1,size=(120,20),style=wx.SIMPLE_BORDER) self.tcChi = wx.TextCtrl(panel, -1,size=(120,20),style=wx.SIMPLE_BORDER) self.tcXmin = wx.TextCtrl(panel,-1,size=(120,20),style=wx.SIMPLE_BORDER) self.tcXmax = wx.TextCtrl(panel,-1,size=(120,20),style=wx.SIMPLE_BORDER) self.btFit =wx.Button(panel,-1,'Fit' ) btClose =wx.Button(panel, wx.ID_CANCEL,'Close' ) ix = 1 iy = 1 sizer.Add(wx.StaticText(panel, -1, 'y = Ax +B'),(iy, ix)) ix = 1 iy += 2 sizer.Add(wx.StaticText(panel, -1, 'Param A'),(iy, ix)) ix += 1 sizer.Add(self.tcA, (iy, ix)) ix += 1 sizer.Add(wx.StaticText(panel, -1, '+/-'),(iy, ix)) ix += 1 sizer.Add(self.tcErrA, (iy, ix)) iy += 1 ix = 1 sizer.Add(wx.StaticText(panel, -1, 'Param B'),(iy, ix)) ix += 1 sizer.Add(self.tcB, (iy, ix)) ix += 1 sizer.Add(wx.StaticText(panel, -1, '+/-'),(iy, ix)) ix += 1 sizer.Add(self.tcErrB, (iy, ix)) iy += 1 ix = 1 sizer.Add(wx.StaticText(panel, -1, 'Chi ^{2}'),(iy, ix)) ix += 1 sizer.Add(self.tcChi, (iy, ix)) iy += 1 ix = 1 sizer.Add(wx.StaticText(panel, -1, 'Xmin'),(iy, ix)) ix += 2 sizer.Add(wx.StaticText(panel, -1, 'Xmax'),(iy, ix)) iy += 1 ix = 1 sizer.Add(self.tcXmin, (iy, ix)) ix += 2 sizer.Add(self.tcXmax, (iy, ix)) iy += 1 ix = 1 sizer.Add(self.btFit, (iy, ix)) self.btFit.Bind(wx.EVT_BUTTON, self._onFit) ix += 2 sizer.Add(btClose, (iy, ix)) panel.SetSizer(sizer) self.SetSizer(vbox) self.Centre() # Receives the type of model for the fitting from LineModel import LineModel self.model = LineModel() # new data for the fit self.file_data1 = Theory1D(x=[], y=[], dy=None) self.file_data1.name = "Fit" def _onFit(self ,event): print "we are on fit" temp =[] xmin = self._checkVal(self.tcXmin.GetValue()) xmax = self._checkVal(self.tcXmax.GetValue()) #store the values of View in x,y, dx,dy x,y,dx,dy=self.plottable.returnValuesOfView() if x != []: if xmin !=None and xmax != None: for j in range(len(x)): if x[j]>xmin and x[j]