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