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