source: sasview/sansview/perspectives/fitting/ftol_dialog.py @ 0145a25

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 0145a25 was 2c6b224, checked in by Jae Cho <jhjcho@…>, 13 years ago

added a menu item : Ftol setup

  • Property mode set to 100644
File size: 4.6 KB
RevLine 
[2296316]1
2################################################################################
3#This software was developed by the University of Tennessee as part of the
4#Distributed Data Analysis of Neutron Scattering Experiments (DANSE)
5#project funded by the US National Science Foundation.
6#
7#See the license text in license.txt
8#
9#copyright 2009, University of Tennessee
10################################################################################
11import wx
12import sys
[1b1bbf9]13from sans.guiframe.events import StatusEvent 
[2296316]14# default ftol
15F_TOL = 1.49012e-08 
[2c6b224]16SANS_F_TOL = 5e-05
[2296316]17
18if sys.platform.count("win32") > 0:
19    PANEL_WIDTH = 270 
[2c6b224]20    PANEL_HEIGHT = 265
[2296316]21    FONT_VARIANT = 0
22else:
23    PANEL_WIDTH = 285
[2c6b224]24    PANEL_HEIGHT = 265
[2296316]25    FONT_VARIANT = 1
26   
27"""
28Dialog to set ftol for Scipy
29
30    ftol(float): Relative error desired in the sum of squares.
31"""
32class ChangeFtol(wx.Dialog):
33    """
34    Dialog to select ftol
35    """
[2c6b224]36    def __init__(self, parent, base, id=-1, title="FTolerance"):
[2296316]37        wx.Dialog.__init__(self, parent, id, title, 
38                           size=(PANEL_WIDTH, PANEL_HEIGHT))
39        # parent
[2c6b224]40        self.parent = base
[2296316]41        # default ftol
[2c6b224]42        self.ftol = SANS_F_TOL
[2296316]43                # font size
44        self.SetWindowVariant(variant=FONT_VARIANT)
45        # build layout
46        panel = wx.Panel(self, -1)
47        vbox = wx.BoxSizer(wx.VERTICAL)
[2c6b224]48        wx.StaticBox(panel, -1, 'FTol selection (Leastsq)', (5, 6),
49                      (PANEL_WIDTH*0.9, PANEL_HEIGHT*0.7))
50        default_bt = wx.RadioButton(panel, -1, 'SansView Default (5e-05)', 
51                                    (15, 30), 
[2296316]52                                    style=wx.RB_GROUP)
53        default_bt.SetValue(True)
[2c6b224]54        default_bt.Bind(wx.EVT_RADIOBUTTON, self.OnFtolSelection)
55        sci_default_bt = wx.RadioButton(panel, -1, 
56                                    'Scipy Default (1.49012e-08)', (15, 55))
57        sci_default_bt.SetValue(False)
58        sci_default_bt.Bind(wx.EVT_RADIOBUTTON, self.OnFtolSelection)
59        high_bt = wx.RadioButton(panel, -1, '1e-06', (15, 80))
[2296316]60        high_bt.SetValue(False)
61        high_bt.Bind(wx.EVT_RADIOBUTTON, self.OnFtolSelection)
[2c6b224]62        mid_bt = wx.RadioButton(panel, -1, '1e-05', (15, 105))
[2296316]63        mid_bt.SetValue(False)
64        mid_bt.Bind(wx.EVT_RADIOBUTTON, self.OnFtolSelection)
[2c6b224]65        low_bt = wx.RadioButton(panel, -1, '1e-04', (15, 130))
[2296316]66        low_bt.SetValue(False)
67        low_bt.Bind(wx.EVT_RADIOBUTTON, self.OnFtolSelection)
[2c6b224]68        self.custom_bt = wx.RadioButton(panel, -1, 'Custom', (15, 155))
[2296316]69        self.custom_bt.SetValue(False)
70        self.custom_bt.Bind(wx.EVT_RADIOBUTTON, self.OnFtolSelection)
[2c6b224]71        self.custombox = wx.TextCtrl(panel, -1, '', (95, 155))
[2296316]72        self.custombox.Disable()
73        hbox = wx.BoxSizer(wx.HORIZONTAL)
74        okButton = wx.Button(self, -1, 'Set', size=(70, 30))
75        hbox.Add(okButton, 1, wx.RIGHT, 5)
76        okButton.Bind(wx.EVT_BUTTON, self.OnClose)
77        vbox.Add(panel)
78        vbox.Add(hbox, 1, wx.ALIGN_CENTER | wx.TOP | wx.BOTTOM, 10)
79        # set sizer
80        self.SetSizer(vbox)
[2c6b224]81
[2296316]82    def OnFtolSelection(self, event=None):
83        """
84        Changes the ftol on selection of the radio button
85        """
86        event.Skip()
87        # event object and selection
88        button = event.GetEventObject()
89        selection = button.GetLabel()
90        # get float value
[2c6b224]91        if selection.count('SansView') > 0:
92            ftol = SANS_F_TOL   
93            self.custombox.Disable() 
94        elif selection.count('Scipy') > 0:
[2296316]95            ftol = F_TOL   
96            self.custombox.Disable()     
97        elif selection == 'Custom':
98            ftol = F_TOL
99            self.custombox.Enable(True)
100        else:
101            ftol =  float(selection)
102            self.custombox.Disable()
103        self.ftol = ftol   
104       
105
106    def OnClose(self, event):
107        """
108        Close event
109        """
110        # clear event
111        event.Skip()
112        flag = True
113        # I case of the custom ftol
114        if self.custom_bt.GetValue():
115            try:
116                ftol = float(self.custombox.GetValue())
117                self.ftol = ftol
118            except:
119                flag = False
120        if flag:
121            # set ftol in fitting
[2c6b224]122            self.parent.set_ftol(self.ftol) 
123            msg = "The ftol (LeastSq) is set to %s." % self.ftol
[2296316]124        else:
125           msg = "Error in the selection... No changes in ftol."
126        # post event for info
[2c6b224]127        wx.PostEvent( self.parent.parent, 
[2296316]128                      StatusEvent(status= msg, info='warning')) 
129   
130        self.Destroy()
131
Note: See TracBrowser for help on using the repository browser.