[f32d144] | 1 | """ |
---|
| 2 | Dialog to set ftol for Scipy |
---|
[2296316] | 3 | |
---|
[f32d144] | 4 | ftol(float): Relative error desired in the sum of squares. |
---|
| 5 | """ |
---|
[2296316] | 6 | ################################################################################ |
---|
| 7 | #This software was developed by the University of Tennessee as part of the |
---|
| 8 | #Distributed Data Analysis of Neutron Scattering Experiments (DANSE) |
---|
[f32d144] | 9 | #project funded by the US National Science Foundation. |
---|
[2296316] | 10 | # |
---|
| 11 | #See the license text in license.txt |
---|
| 12 | # |
---|
| 13 | #copyright 2009, University of Tennessee |
---|
| 14 | ################################################################################ |
---|
| 15 | import wx |
---|
| 16 | import sys |
---|
| 17 | # default ftol |
---|
[f32d144] | 18 | F_TOL = 1.49012e-08 |
---|
[b9a5f0e] | 19 | SAS_F_TOL = 5e-05 |
---|
[2296316] | 20 | |
---|
[ee576a9] | 21 | PANEL_WIDTH = 270 |
---|
[7e44299] | 22 | FONT_VARIANT = 0 |
---|
[2296316] | 23 | if sys.platform.count("win32") > 0: |
---|
[ee576a9] | 24 | PANEL_HEIGHT = 265 |
---|
[2296316] | 25 | else: |
---|
[18c8c3d] | 26 | PANEL_HEIGHT = 245 |
---|
[f32d144] | 27 | |
---|
[2296316] | 28 | class ChangeFtol(wx.Dialog): |
---|
| 29 | """ |
---|
| 30 | Dialog to select ftol |
---|
| 31 | """ |
---|
[2c6b224] | 32 | def __init__(self, parent, base, id=-1, title="FTolerance"): |
---|
[ee576a9] | 33 | wx.Dialog.__init__(self, parent, id, title, |
---|
| 34 | size=(PANEL_WIDTH, PANEL_HEIGHT)) |
---|
[f32d144] | 35 | # font size |
---|
[2296316] | 36 | self.SetWindowVariant(variant=FONT_VARIANT) |
---|
| 37 | # build layout |
---|
| 38 | vbox = wx.BoxSizer(wx.VERTICAL) |
---|
[164d64f] | 39 | title_text = wx.StaticText(self, id=wx.NewId(), label='FTol selection (Leastsq)') |
---|
[b9a5f0e] | 40 | self.default_bt = wx.RadioButton(self, -1, 'SasView Default (5e-05)', (15, 30), style=wx.RB_GROUP) |
---|
[767514a] | 41 | self.default_bt.SetValue(True) |
---|
| 42 | self.default_bt.Bind(wx.EVT_RADIOBUTTON, self.OnFtolSelection) |
---|
[164d64f] | 43 | self.sci_default_bt = wx.RadioButton(self, -1, 'Scipy Default (1.49012e-08)', (15, 55)) |
---|
[767514a] | 44 | self.sci_default_bt.SetValue(False) |
---|
| 45 | self.sci_default_bt.Bind(wx.EVT_RADIOBUTTON, self.OnFtolSelection) |
---|
[164d64f] | 46 | self.high_bt = wx.RadioButton(self, -1, '1e-06', (15, 80)) |
---|
[767514a] | 47 | self.high_bt.SetValue(False) |
---|
| 48 | self.high_bt.Bind(wx.EVT_RADIOBUTTON, self.OnFtolSelection) |
---|
[164d64f] | 49 | self.mid_bt = wx.RadioButton(self, -1, '1e-05', (15, 105)) |
---|
[767514a] | 50 | self.mid_bt.SetValue(False) |
---|
| 51 | self.mid_bt.Bind(wx.EVT_RADIOBUTTON, self.OnFtolSelection) |
---|
[164d64f] | 52 | self.low_bt = wx.RadioButton(self, -1, '1e-04', (15, 130)) |
---|
[767514a] | 53 | self.low_bt.SetValue(False) |
---|
| 54 | self.low_bt.Bind(wx.EVT_RADIOBUTTON, self.OnFtolSelection) |
---|
[164d64f] | 55 | self.custom_bt = wx.RadioButton(self, -1, 'Custom', (15, 155)) |
---|
[2296316] | 56 | self.custom_bt.SetValue(False) |
---|
| 57 | self.custom_bt.Bind(wx.EVT_RADIOBUTTON, self.OnFtolSelection) |
---|
[164d64f] | 58 | self.custombox = wx.TextCtrl(self, -1, '', (95, 155)) |
---|
[2296316] | 59 | self.custombox.Disable() |
---|
[767514a] | 60 | |
---|
[2296316] | 61 | hbox = wx.BoxSizer(wx.HORIZONTAL) |
---|
[767514a] | 62 | okButton = wx.Button(self, wx.ID_OK, 'Set', size=(70, 30)) |
---|
| 63 | closeButton = wx.Button(self,wx.ID_CANCEL, 'Cancel', size=(70, 30)) |
---|
[2296316] | 64 | hbox.Add(okButton, 1, wx.RIGHT, 5) |
---|
[767514a] | 65 | hbox.Add(closeButton, 1, wx.RIGHT, 5) |
---|
[164d64f] | 66 | |
---|
| 67 | vbox.Add(title_text, 0, wx.ALIGN_CENTER | wx.TOP | wx.BOTTOM, 10) |
---|
| 68 | vbox.Add(self.default_bt, 0, wx.LEFT, 20) |
---|
| 69 | vbox.Add(self.sci_default_bt, 0, wx.LEFT, 20) |
---|
| 70 | vbox.Add(self.high_bt, 0, wx.LEFT, 20) |
---|
| 71 | vbox.Add(self.mid_bt, 0, wx.LEFT, 20) |
---|
| 72 | vbox.Add(self.low_bt, 0, wx.LEFT, 20) |
---|
| 73 | vbox.Add(self.custom_bt, 0, wx.LEFT, 20) |
---|
| 74 | vbox.Add(self.custombox, 0, wx.LEFT, 60) |
---|
| 75 | vbox.Add(hbox, 0, wx.ALIGN_CENTER | wx.TOP | wx.BOTTOM, 10) |
---|
[767514a] | 76 | |
---|
[2296316] | 77 | self.SetSizer(vbox) |
---|
[2c6b224] | 78 | |
---|
[2296316] | 79 | def OnFtolSelection(self, event=None): |
---|
| 80 | """ |
---|
[767514a] | 81 | Changes the ftol on selection of the radio button |
---|
[2296316] | 82 | """ |
---|
[767514a] | 83 | self.custombox.Enable(self.custom_bt.GetValue()) |
---|
[2296316] | 84 | |
---|
[767514a] | 85 | def get_ftol(self): |
---|
[2296316] | 86 | """ |
---|
[767514a] | 87 | Get the ftol value |
---|
[2296316] | 88 | """ |
---|
[767514a] | 89 | if self.default_bt.GetValue(): |
---|
[b9a5f0e] | 90 | return SAS_F_TOL |
---|
[767514a] | 91 | elif self.sci_default_bt.GetValue(): |
---|
| 92 | return F_TOL |
---|
| 93 | elif self.low_bt.GetValue(): |
---|
| 94 | return 1.0e-4 |
---|
| 95 | elif self.mid_bt.GetValue(): |
---|
| 96 | return 1.0e-5 |
---|
| 97 | elif self.high_bt.GetValue(): |
---|
| 98 | return 1.0e-6 |
---|
[2296316] | 99 | if self.custom_bt.GetValue(): |
---|
| 100 | try: |
---|
[767514a] | 101 | return float(self.custombox.GetValue()) |
---|
[2296316] | 102 | except: |
---|
[767514a] | 103 | return None |
---|
[b9a5f0e] | 104 | return SAS_F_TOL |
---|