[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 |
---|
[2c6b224] | 19 | SANS_F_TOL = 5e-05 |
---|
[2296316] | 20 | |
---|
[7e44299] | 21 | PANEL_HEIGHT = 265 |
---|
| 22 | FONT_VARIANT = 0 |
---|
[2296316] | 23 | if sys.platform.count("win32") > 0: |
---|
[f32d144] | 24 | PANEL_WIDTH = 270 |
---|
[2296316] | 25 | else: |
---|
| 26 | PANEL_WIDTH = 285 |
---|
[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"): |
---|
[e94f14f] | 33 | wx.Dialog.__init__(self, parent, id, title) |
---|
[f32d144] | 34 | # font size |
---|
[2296316] | 35 | self.SetWindowVariant(variant=FONT_VARIANT) |
---|
| 36 | # build layout |
---|
| 37 | vbox = wx.BoxSizer(wx.VERTICAL) |
---|
[164d64f] | 38 | title_text = wx.StaticText(self, id=wx.NewId(), label='FTol selection (Leastsq)') |
---|
| 39 | self.default_bt = wx.RadioButton(self, -1, 'SansView Default (5e-05)', (15, 30), style=wx.RB_GROUP) |
---|
[767514a] | 40 | self.default_bt.SetValue(True) |
---|
| 41 | self.default_bt.Bind(wx.EVT_RADIOBUTTON, self.OnFtolSelection) |
---|
[164d64f] | 42 | self.sci_default_bt = wx.RadioButton(self, -1, 'Scipy Default (1.49012e-08)', (15, 55)) |
---|
[767514a] | 43 | self.sci_default_bt.SetValue(False) |
---|
| 44 | self.sci_default_bt.Bind(wx.EVT_RADIOBUTTON, self.OnFtolSelection) |
---|
[164d64f] | 45 | self.high_bt = wx.RadioButton(self, -1, '1e-06', (15, 80)) |
---|
[767514a] | 46 | self.high_bt.SetValue(False) |
---|
| 47 | self.high_bt.Bind(wx.EVT_RADIOBUTTON, self.OnFtolSelection) |
---|
[164d64f] | 48 | self.mid_bt = wx.RadioButton(self, -1, '1e-05', (15, 105)) |
---|
[767514a] | 49 | self.mid_bt.SetValue(False) |
---|
| 50 | self.mid_bt.Bind(wx.EVT_RADIOBUTTON, self.OnFtolSelection) |
---|
[164d64f] | 51 | self.low_bt = wx.RadioButton(self, -1, '1e-04', (15, 130)) |
---|
[767514a] | 52 | self.low_bt.SetValue(False) |
---|
| 53 | self.low_bt.Bind(wx.EVT_RADIOBUTTON, self.OnFtolSelection) |
---|
[164d64f] | 54 | self.custom_bt = wx.RadioButton(self, -1, 'Custom', (15, 155)) |
---|
[2296316] | 55 | self.custom_bt.SetValue(False) |
---|
| 56 | self.custom_bt.Bind(wx.EVT_RADIOBUTTON, self.OnFtolSelection) |
---|
[164d64f] | 57 | self.custombox = wx.TextCtrl(self, -1, '', (95, 155)) |
---|
[2296316] | 58 | self.custombox.Disable() |
---|
[767514a] | 59 | |
---|
[2296316] | 60 | hbox = wx.BoxSizer(wx.HORIZONTAL) |
---|
[767514a] | 61 | okButton = wx.Button(self, wx.ID_OK, 'Set', size=(70, 30)) |
---|
| 62 | closeButton = wx.Button(self,wx.ID_CANCEL, 'Cancel', size=(70, 30)) |
---|
[2296316] | 63 | hbox.Add(okButton, 1, wx.RIGHT, 5) |
---|
[767514a] | 64 | hbox.Add(closeButton, 1, wx.RIGHT, 5) |
---|
[164d64f] | 65 | |
---|
| 66 | vbox.Add(title_text, 0, wx.ALIGN_CENTER | wx.TOP | wx.BOTTOM, 10) |
---|
| 67 | vbox.Add(self.default_bt, 0, wx.LEFT, 20) |
---|
| 68 | vbox.Add(self.sci_default_bt, 0, wx.LEFT, 20) |
---|
| 69 | vbox.Add(self.high_bt, 0, wx.LEFT, 20) |
---|
| 70 | vbox.Add(self.mid_bt, 0, wx.LEFT, 20) |
---|
| 71 | vbox.Add(self.low_bt, 0, wx.LEFT, 20) |
---|
| 72 | vbox.Add(self.custom_bt, 0, wx.LEFT, 20) |
---|
| 73 | vbox.Add(self.custombox, 0, wx.LEFT, 60) |
---|
| 74 | vbox.Add(hbox, 0, wx.ALIGN_CENTER | wx.TOP | wx.BOTTOM, 10) |
---|
[767514a] | 75 | |
---|
[2296316] | 76 | self.SetSizer(vbox) |
---|
[2c6b224] | 77 | |
---|
[2296316] | 78 | def OnFtolSelection(self, event=None): |
---|
| 79 | """ |
---|
[767514a] | 80 | Changes the ftol on selection of the radio button |
---|
[2296316] | 81 | """ |
---|
[767514a] | 82 | self.custombox.Enable(self.custom_bt.GetValue()) |
---|
[2296316] | 83 | |
---|
[767514a] | 84 | def get_ftol(self): |
---|
[2296316] | 85 | """ |
---|
[767514a] | 86 | Get the ftol value |
---|
[2296316] | 87 | """ |
---|
[767514a] | 88 | if self.default_bt.GetValue(): |
---|
| 89 | return SANS_F_TOL |
---|
| 90 | elif self.sci_default_bt.GetValue(): |
---|
| 91 | return F_TOL |
---|
| 92 | elif self.low_bt.GetValue(): |
---|
| 93 | return 1.0e-4 |
---|
| 94 | elif self.mid_bt.GetValue(): |
---|
| 95 | return 1.0e-5 |
---|
| 96 | elif self.high_bt.GetValue(): |
---|
| 97 | return 1.0e-6 |
---|
[2296316] | 98 | if self.custom_bt.GetValue(): |
---|
| 99 | try: |
---|
[767514a] | 100 | return float(self.custombox.GetValue()) |
---|
[2296316] | 101 | except: |
---|
[767514a] | 102 | return None |
---|
| 103 | return SANS_F_TOL |
---|