[d1e0473] | 1 | |
---|
| 2 | |
---|
[c77d859] | 3 | import sys |
---|
| 4 | import wx |
---|
| 5 | import wx.lib.newevent |
---|
| 6 | import numpy |
---|
| 7 | import copy |
---|
| 8 | import math |
---|
[7975f2b] | 9 | import time |
---|
[c77d859] | 10 | from sans.models.dispersion_models import ArrayDispersion, GaussianDispersion |
---|
[c21e87b] | 11 | from sans.dataloader.data_info import Data1D |
---|
[cc31608] | 12 | from sans.guiframe.events import StatusEvent |
---|
| 13 | from sans.guiframe.events import NewPlotEvent |
---|
[85b3971] | 14 | from sans.guiframe.utils import format_number,check_float |
---|
[7609f1a] | 15 | |
---|
[f72333f] | 16 | (Chi2UpdateEvent, EVT_CHI2_UPDATE) = wx.lib.newevent.NewEvent() |
---|
[eda428b] | 17 | _BOX_WIDTH = 76 |
---|
[a5701e6] | 18 | _DATA_BOX_WIDTH = 300 |
---|
[ba1f0b2] | 19 | SMEAR_SIZE_L = 0.00 |
---|
| 20 | SMEAR_SIZE_H = 0.00 |
---|
[7609f1a] | 21 | |
---|
[c77d859] | 22 | import basepage |
---|
| 23 | from basepage import BasicPage |
---|
[b787e68c] | 24 | from basepage import PageInfoEvent |
---|
[e4957fb] | 25 | from sans.models.qsmearing import smear_selection |
---|
[c77d859] | 26 | |
---|
[e030625] | 27 | |
---|
[c77d859] | 28 | class FitPage(BasicPage): |
---|
| 29 | """ |
---|
[5062bbf] | 30 | FitPanel class contains fields allowing to display results when |
---|
| 31 | fitting a model and one data |
---|
| 32 | |
---|
| 33 | :note: For Fit to be performed the user should check at least one parameter |
---|
[c77d859] | 34 | on fit Panel window. |
---|
| 35 | """ |
---|
[7975f2b] | 36 | |
---|
[6bbeacd4] | 37 | def __init__(self,parent, color='rand'): |
---|
[c77d859] | 38 | """ |
---|
[5062bbf] | 39 | Initialization of the Panel |
---|
[c77d859] | 40 | """ |
---|
[6bbeacd4] | 41 | BasicPage.__init__(self, parent, color=color) |
---|
[88f286d] | 42 | |
---|
[b787e68c] | 43 | ## draw sizer |
---|
[cc31608] | 44 | self._fill_data_sizer() |
---|
[2296316] | 45 | self.is_2D = None |
---|
[f22e626] | 46 | self.fit_started = False |
---|
[7609f1a] | 47 | # get smear info from data |
---|
| 48 | self._get_smear_info() |
---|
[c77d859] | 49 | self._fill_model_sizer( self.sizer1) |
---|
[7609f1a] | 50 | self._get_defult_custom_smear() |
---|
[cfc0913] | 51 | self._fill_range_sizer() |
---|
[6bbeacd4] | 52 | self._set_smear(self.data) |
---|
[f72333f] | 53 | self.Bind(EVT_CHI2_UPDATE, self.on_complete_chisqr) |
---|
[2296316] | 54 | # bind key event |
---|
| 55 | self.Bind(wx.EVT_RIGHT_DOWN, self.on_right_down) |
---|
[982e953] | 56 | self._set_bookmark_flag(False) |
---|
| 57 | self._set_save_flag(False) |
---|
[aad74b3] | 58 | self._set_preview_flag(False) |
---|
[07c8630] | 59 | self._set_copy_flag(False) |
---|
| 60 | self._set_paste_flag(False) |
---|
[716da5e] | 61 | self.btFit.SetFocus() |
---|
[cc31608] | 62 | self.fill_data_combobox(data_list=self.data_list) |
---|
| 63 | |
---|
| 64 | |
---|
| 65 | def _fill_data_sizer(self): |
---|
| 66 | """ |
---|
| 67 | fill sizer 0 with data info |
---|
| 68 | """ |
---|
| 69 | box_description= wx.StaticBox(self, -1, 'I(q) Data Source') |
---|
| 70 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
| 71 | #---------------------------------------------------------- |
---|
| 72 | sizer_data = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 73 | self.dataSource = wx.ComboBox(self, -1, style=wx.CB_READONLY) |
---|
| 74 | wx.EVT_COMBOBOX(self.dataSource, -1, self.on_select_data) |
---|
| 75 | self.dataSource.SetMinSize((_DATA_BOX_WIDTH, -1)) |
---|
| 76 | sizer_data.Add(wx.StaticText(self, -1, 'Name : ')) |
---|
| 77 | sizer_data.Add(self.dataSource) |
---|
| 78 | sizer_data.Add( (0,5) ) |
---|
| 79 | boxsizer1.Add(sizer_data,0, wx.ALL, 10) |
---|
| 80 | self.sizer0.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10) |
---|
| 81 | self.sizer0.Layout() |
---|
| 82 | |
---|
| 83 | def enable_datasource(self): |
---|
| 84 | """ |
---|
| 85 | Enable or disable data source control depending on existing data |
---|
| 86 | """ |
---|
| 87 | if not self.data_list: |
---|
| 88 | self.dataSource.Disable() |
---|
| 89 | else: |
---|
| 90 | self.dataSource.Enable() |
---|
| 91 | |
---|
| 92 | def fill_data_combobox(self, data_list): |
---|
| 93 | """ |
---|
| 94 | Get a list of data and fill the corresponding combobox |
---|
| 95 | """ |
---|
| 96 | self.dataSource.Clear() |
---|
| 97 | self.data_list = data_list |
---|
| 98 | self.enable_datasource() |
---|
[4225aed] | 99 | if data_list: |
---|
[67ae937] | 100 | qmin, qmax, npts = self.compute_data_range(data_list[0]) |
---|
[4225aed] | 101 | self.qmin_data_set, self.qmax_data_set = qmin, qmax |
---|
[67ae937] | 102 | self.npts_data_set = npts |
---|
[cc31608] | 103 | for data in self.data_list: |
---|
| 104 | if data is not None: |
---|
[4225aed] | 105 | self.compute_data_set_range(data) |
---|
[cc31608] | 106 | self.dataSource.Append(str(data.name), clientData=data) |
---|
[4225aed] | 107 | |
---|
| 108 | print "fill_data_combox", self.qmin_data_set, self.qmax_data_set |
---|
[cc31608] | 109 | self.dataSource.SetSelection(0) |
---|
| 110 | self.on_select_data(event=None) |
---|
| 111 | |
---|
| 112 | def on_select_data(self, event=None): |
---|
| 113 | """ |
---|
| 114 | """ |
---|
| 115 | if event is None and self.dataSource.GetCount() > 0: |
---|
| 116 | data = self.dataSource.GetClientData(0) |
---|
| 117 | self.set_data(data) |
---|
| 118 | elif self.dataSource.GetCount() > 0: |
---|
| 119 | pos = self.dataSource.GetSelection() |
---|
| 120 | data = self.dataSource.GetClientData(pos) |
---|
| 121 | self.set_data(data) |
---|
| 122 | |
---|
| 123 | |
---|
[9466f2d6] | 124 | |
---|
[66ff250] | 125 | def _on_fit_complete(self): |
---|
[34a0c17] | 126 | """ |
---|
[5062bbf] | 127 | When fit is complete ,reset the fit button label. |
---|
[34a0c17] | 128 | """ |
---|
[66ff250] | 129 | self.btFit.SetLabel("Fit") |
---|
| 130 | self.bind_fit_button() |
---|
[34a0c17] | 131 | |
---|
[f72333f] | 132 | def _is_2D(self): |
---|
| 133 | """ |
---|
[5062bbf] | 134 | Check if data_name is Data2D |
---|
| 135 | |
---|
| 136 | :return: True or False |
---|
| 137 | |
---|
[f72333f] | 138 | """ |
---|
[ba1f0b2] | 139 | if self.data.__class__.__name__ == "Data2D" or \ |
---|
| 140 | self.enable2D: |
---|
[f72333f] | 141 | return True |
---|
| 142 | return False |
---|
| 143 | |
---|
[66ff250] | 144 | def _on_engine_change(self, name): |
---|
[77e23a2] | 145 | """ |
---|
[66ff250] | 146 | get the current name of the fit engine type |
---|
| 147 | and update the panel accordingly |
---|
[77e23a2] | 148 | """ |
---|
[66ff250] | 149 | |
---|
| 150 | self.engine_type = str(name) |
---|
[0b12abb5] | 151 | self.state.engine_type = self.engine_type |
---|
[9e87b76] | 152 | if not self.is_mac: |
---|
| 153 | if len(self.parameters) == 0: |
---|
| 154 | self.Layout() |
---|
| 155 | return |
---|
[edd166b] | 156 | self.Layout() |
---|
[9e87b76] | 157 | self.Refresh() |
---|
[66ff250] | 158 | |
---|
[6bbeacd4] | 159 | |
---|
| 160 | |
---|
[c77d859] | 161 | def _fill_range_sizer(self): |
---|
| 162 | """ |
---|
[5062bbf] | 163 | Fill the sizer containing the plotting range |
---|
| 164 | add access to npts |
---|
[c77d859] | 165 | """ |
---|
[51a71a3] | 166 | is_2Ddata = False |
---|
| 167 | |
---|
| 168 | # Check if data is 2D |
---|
[ba1f0b2] | 169 | if self.data.__class__.__name__ == "Data2D" or \ |
---|
| 170 | self.enable2D: |
---|
[51a71a3] | 171 | is_2Ddata = True |
---|
| 172 | |
---|
[ff8f99b] | 173 | title = "Fitting" |
---|
[7609f1a] | 174 | #smear messages & titles |
---|
| 175 | smear_message_none = "No smearing is selected..." |
---|
| 176 | smear_message_dqdata = "The dQ data is being used for smearing..." |
---|
[f72333f] | 177 | smear_message_2d = "Higher accuracy is very time-expensive. Use it with care..." |
---|
[7609f1a] | 178 | smear_message_new_ssmear = "Please enter only the value of interest to customize smearing..." |
---|
| 179 | smear_message_new_psmear = "Please enter both; the dQ will be generated by interpolation..." |
---|
[2296316] | 180 | smear_message_2d_x_title = "<dQp>[1/A]:" |
---|
| 181 | smear_message_2d_y_title = "<dQs>[1/A]:" |
---|
[f72333f] | 182 | smear_message_pinhole_min_title = "dQ_low[1/A]:" |
---|
| 183 | smear_message_pinhole_max_title = "dQ_high[1/A]:" |
---|
[7609f1a] | 184 | smear_message_slit_height_title = "Slit height[1/A]:" |
---|
| 185 | smear_message_slit_width_title = "Slit width[1/A]:" |
---|
| 186 | |
---|
| 187 | self._get_smear_info() |
---|
[c77d859] | 188 | |
---|
[51a71a3] | 189 | #Sizers |
---|
| 190 | box_description_range = wx.StaticBox(self, -1,str(title)) |
---|
| 191 | boxsizer_range = wx.StaticBoxSizer(box_description_range, wx.VERTICAL) |
---|
[7609f1a] | 192 | self.sizer_set_smearer = wx.BoxSizer(wx.VERTICAL) |
---|
[c77d859] | 193 | sizer_smearer = wx.BoxSizer(wx.HORIZONTAL) |
---|
[7609f1a] | 194 | self.sizer_new_smear= wx.BoxSizer(wx.HORIZONTAL) |
---|
| 195 | self.sizer_set_masking = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 196 | sizer_chi2 = wx.BoxSizer(wx.VERTICAL) |
---|
| 197 | smear_set_box= wx.StaticBox(self, -1,'Set Instrumental Smearing') |
---|
| 198 | sizer_smearer_box = wx.StaticBoxSizer(smear_set_box, wx.HORIZONTAL) |
---|
| 199 | sizer_smearer_box.SetMinSize((_DATA_BOX_WIDTH,85)) |
---|
[0cf97c5] | 200 | sizer_fit = wx.GridSizer(2, 4, 2, 6) |
---|
[2012eae] | 201 | |
---|
[f72333f] | 202 | # combobox for smear2d accuracy selection |
---|
| 203 | self.smear_accuracy = wx.ComboBox(self, -1,size=(50,-1),style=wx.CB_READONLY) |
---|
| 204 | self._set_accuracy_list() |
---|
| 205 | self.smear_accuracy.SetValue(self.smear2d_accuracy) |
---|
| 206 | self.smear_accuracy.SetSelection(0) |
---|
| 207 | self.smear_accuracy.SetToolTipString("'Higher' uses more Gaussian points for smearing computation.") |
---|
| 208 | |
---|
| 209 | wx.EVT_COMBOBOX(self.smear_accuracy,-1, self._on_select_accuracy) |
---|
| 210 | |
---|
[2012eae] | 211 | #Fit button |
---|
| 212 | self.btFit = wx.Button(self,wx.NewId(),'Fit', size=(88,25)) |
---|
[e030625] | 213 | self.default_bt_colour = self.btFit.GetDefaultAttributes() |
---|
[29bf83b] | 214 | self.btFit.Bind(wx.EVT_BUTTON, self._onFit,id= self.btFit.GetId()) |
---|
[2012eae] | 215 | self.btFit.SetToolTipString("Start fitting.") |
---|
[7609f1a] | 216 | |
---|
[f72333f] | 217 | #textcntrl for custom resolution |
---|
| 218 | self.smear_pinhole_max = self.ModelTextCtrl(self, -1,size=(_BOX_WIDTH-25,20),style=wx.TE_PROCESS_ENTER, |
---|
[7609f1a] | 219 | text_enter_callback = self.onPinholeSmear) |
---|
[f72333f] | 220 | self.smear_pinhole_min = self.ModelTextCtrl(self, -1,size=(_BOX_WIDTH-25,20),style=wx.TE_PROCESS_ENTER, |
---|
[7609f1a] | 221 | text_enter_callback = self.onPinholeSmear) |
---|
[f72333f] | 222 | self.smear_slit_height= self.ModelTextCtrl(self, -1,size=(_BOX_WIDTH-25,20),style=wx.TE_PROCESS_ENTER, |
---|
[7609f1a] | 223 | text_enter_callback = self.onSlitSmear) |
---|
[f72333f] | 224 | self.smear_slit_width = self.ModelTextCtrl(self, -1,size=(_BOX_WIDTH-25,20),style=wx.TE_PROCESS_ENTER, |
---|
[7609f1a] | 225 | text_enter_callback = self.onSlitSmear) |
---|
[f72333f] | 226 | |
---|
| 227 | ## smear |
---|
| 228 | self.smear_data_left= BGTextCtrl(self, -1, size=(_BOX_WIDTH-25,20), style=0) |
---|
[7609f1a] | 229 | self.smear_data_left.SetValue(str(self.dq_l)) |
---|
[f72333f] | 230 | self.smear_data_right = BGTextCtrl(self, -1, size=(_BOX_WIDTH-25,20), style=0) |
---|
[7609f1a] | 231 | self.smear_data_right.SetValue(str(self.dq_r)) |
---|
| 232 | |
---|
[f72333f] | 233 | #set default values for smear |
---|
[7609f1a] | 234 | self.smear_pinhole_max.SetValue(str(self.dx_max)) |
---|
| 235 | self.smear_pinhole_min.SetValue(str(self.dx_min)) |
---|
| 236 | self.smear_slit_height.SetValue(str(self.dxl)) |
---|
| 237 | self.smear_slit_width.SetValue(str(self.dxw)) |
---|
| 238 | |
---|
[c77d859] | 239 | #Filling the sizer containing instruments smearing info. |
---|
[7609f1a] | 240 | self.disable_smearer = wx.RadioButton(self, -1, 'None', style=wx.RB_GROUP) |
---|
| 241 | self.enable_smearer = wx.RadioButton(self, -1, 'Use dQ Data') |
---|
| 242 | #self.enable_smearer.SetToolTipString("Click to use the loaded dQ data for smearing.") |
---|
| 243 | self.pinhole_smearer = wx.RadioButton(self, -1, 'Custom Pinhole Smear') |
---|
| 244 | #self.pinhole_smearer.SetToolTipString("Click to input custom resolution for pinhole smearing.") |
---|
| 245 | self.slit_smearer = wx.RadioButton(self, -1, 'Custom Slit Smear') |
---|
| 246 | #self.slit_smearer.SetToolTipString("Click to input custom resolution for slit smearing.") |
---|
[c77d859] | 247 | self.Bind(wx.EVT_RADIOBUTTON, self.onSmear, id=self.disable_smearer.GetId()) |
---|
| 248 | self.Bind(wx.EVT_RADIOBUTTON, self.onSmear, id=self.enable_smearer.GetId()) |
---|
[7609f1a] | 249 | self.Bind(wx.EVT_RADIOBUTTON, self.onPinholeSmear, id=self.pinhole_smearer.GetId()) |
---|
| 250 | self.Bind(wx.EVT_RADIOBUTTON, self.onSlitSmear, id=self.slit_smearer.GetId()) |
---|
[ff8f99b] | 251 | self.disable_smearer.SetValue(True) |
---|
[c77d859] | 252 | |
---|
[7609f1a] | 253 | # add 4 types of smearing to the sizer |
---|
| 254 | sizer_smearer.Add( self.disable_smearer,0, wx.LEFT, 10) |
---|
[c77d859] | 255 | sizer_smearer.Add((10,10)) |
---|
[7609f1a] | 256 | sizer_smearer.Add( self.enable_smearer) |
---|
| 257 | sizer_smearer.Add((10,10)) |
---|
| 258 | sizer_smearer.Add( self.pinhole_smearer ) |
---|
| 259 | sizer_smearer.Add((10,10)) |
---|
| 260 | sizer_smearer.Add( self.slit_smearer ) |
---|
| 261 | sizer_smearer.Add((10,10)) |
---|
| 262 | |
---|
[51a71a3] | 263 | # StaticText for chi2, N(for fitting), Npts |
---|
| 264 | self.tcChi = BGTextCtrl(self, -1, "-", size=(75,20), style=0) |
---|
[e9875db] | 265 | self.tcChi.SetToolTipString("Chi2/Npts(Fit)") |
---|
[51a71a3] | 266 | self.Npts_fit = BGTextCtrl(self, -1, "-", size=(75,20), style=0) |
---|
[0cf97c5] | 267 | self.Npts_fit.SetToolTipString(\ |
---|
| 268 | " Npts : number of points selected for fitting") |
---|
| 269 | self.Npts_total = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH, 20), |
---|
| 270 | style=wx.TE_PROCESS_ENTER, |
---|
| 271 | text_enter_callback=self._onQrangeEnter) |
---|
| 272 | self.Npts_total.SetValue(format_number(self.npts_x)) |
---|
| 273 | self.Npts_total.SetToolTipString(\ |
---|
| 274 | " Total Npts : total number of data points") |
---|
| 275 | |
---|
[2296316] | 276 | # Update and Draw button |
---|
| 277 | self.draw_button = wx.Button(self,wx.NewId(),'Compute', size=(88,24)) |
---|
[0cf97c5] | 278 | self.draw_button.Bind(wx.EVT_BUTTON, \ |
---|
| 279 | self._onDraw,id= self.draw_button.GetId()) |
---|
[2296316] | 280 | self.draw_button.SetToolTipString("Compute and Draw.") |
---|
| 281 | |
---|
[51a71a3] | 282 | box_description_1= wx.StaticText(self, -1,' Chi2/Npts') |
---|
[0cf97c5] | 283 | box_description_2= wx.StaticText(self, -1,'Npts(Fit)') |
---|
| 284 | box_description_3= wx.StaticText(self, -1,'Total Npts') |
---|
| 285 | box_description_3.SetToolTipString( \ |
---|
| 286 | " Total Npts : total number of data points") |
---|
[2296316] | 287 | #box_description_4= wx.StaticText(self, -1,' ') |
---|
[7609f1a] | 288 | |
---|
[2012eae] | 289 | |
---|
[51a71a3] | 290 | sizer_fit.Add(box_description_1,0,0) |
---|
| 291 | sizer_fit.Add(box_description_2,0,0) |
---|
| 292 | sizer_fit.Add(box_description_3,0,0) |
---|
[2296316] | 293 | sizer_fit.Add(self.draw_button,0,0) |
---|
[51a71a3] | 294 | sizer_fit.Add(self.tcChi,0,0) |
---|
| 295 | sizer_fit.Add(self.Npts_fit ,0,0) |
---|
| 296 | sizer_fit.Add(self.Npts_total,0,0) |
---|
| 297 | sizer_fit.Add(self.btFit,0,0) |
---|
| 298 | |
---|
| 299 | # StaticText for smear |
---|
| 300 | #self.tcChi = wx.StaticText(self, -1, "-", style=wx.ALIGN_LEFT) |
---|
[4225aed] | 301 | self.smear_description_none = wx.StaticText(self, -1, |
---|
| 302 | smear_message_none , style=wx.ALIGN_LEFT) |
---|
| 303 | self.smear_description_dqdata = wx.StaticText(self, |
---|
| 304 | -1, smear_message_dqdata , style=wx.ALIGN_LEFT) |
---|
| 305 | self.smear_description_type = wx.StaticText(self, |
---|
| 306 | -1, "Type:" , style=wx.ALIGN_LEFT) |
---|
| 307 | self.smear_description_accuracy_type = wx.StaticText(self, -1, |
---|
| 308 | "Accuracy:" , style=wx.ALIGN_LEFT) |
---|
| 309 | self.smear_description_smear_type = BGTextCtrl(self, -1, |
---|
| 310 | size=(57,20), style=0) |
---|
[7609f1a] | 311 | self.smear_description_smear_type.SetValue(str(self.dq_l)) |
---|
| 312 | self.SetBackgroundColour(self.GetParent().GetBackgroundColour()) |
---|
[4225aed] | 313 | self.smear_description_2d = wx.StaticText(self, -1, |
---|
| 314 | smear_message_2d , style=wx.ALIGN_LEFT) |
---|
| 315 | self.smear_message_new_s = wx.StaticText(self, -1, |
---|
| 316 | smear_message_new_ssmear, style=wx.ALIGN_LEFT) |
---|
| 317 | self.smear_message_new_p = wx.StaticText(self, -1, |
---|
| 318 | smear_message_new_psmear , style=wx.ALIGN_LEFT) |
---|
[f72333f] | 319 | self.smear_description_2d_x = wx.StaticText(self, -1, smear_message_2d_x_title , style=wx.ALIGN_LEFT) |
---|
[2296316] | 320 | self.smear_description_2d_x.SetToolTipString(" dQp(parallel) in q_r direction.") |
---|
[f72333f] | 321 | self.smear_description_2d_y = wx.StaticText(self, -1, smear_message_2d_y_title , style=wx.ALIGN_LEFT) |
---|
[2296316] | 322 | self.smear_description_2d_y.SetToolTipString(" dQs(perpendicular) in q_phi direction.") |
---|
[7609f1a] | 323 | self.smear_description_pin_min = wx.StaticText(self, -1, smear_message_pinhole_min_title , style=wx.ALIGN_LEFT) |
---|
| 324 | self.smear_description_pin_max = wx.StaticText(self, -1, smear_message_pinhole_max_title , style=wx.ALIGN_LEFT) |
---|
| 325 | self.smear_description_slit_height = wx.StaticText(self, -1, smear_message_slit_height_title , style=wx.ALIGN_LEFT) |
---|
| 326 | self.smear_description_slit_width = wx.StaticText(self, -1, smear_message_slit_width_title , style=wx.ALIGN_LEFT) |
---|
| 327 | |
---|
| 328 | #arrange sizers |
---|
[51a71a3] | 329 | #boxsizer1.Add( self.tcChi ) |
---|
[7609f1a] | 330 | self.sizer_set_smearer.Add(sizer_smearer ) |
---|
| 331 | self.sizer_set_smearer.Add((10,10)) |
---|
| 332 | self.sizer_set_smearer.Add( self.smear_description_none,0, wx.CENTER, 10 ) |
---|
| 333 | self.sizer_set_smearer.Add( self.smear_description_dqdata,0, wx.CENTER, 10 ) |
---|
| 334 | self.sizer_set_smearer.Add( self.smear_description_2d,0, wx.CENTER, 10 ) |
---|
| 335 | self.sizer_new_smear.Add( self.smear_description_type,0, wx.CENTER, 10 ) |
---|
[f72333f] | 336 | self.sizer_new_smear.Add( self.smear_description_accuracy_type,0, wx.CENTER, 10 ) |
---|
| 337 | self.sizer_new_smear.Add( self.smear_accuracy ) |
---|
[7609f1a] | 338 | self.sizer_new_smear.Add( self.smear_description_smear_type,0, wx.CENTER, 10 ) |
---|
| 339 | self.sizer_new_smear.Add((15,-1)) |
---|
[f72333f] | 340 | self.sizer_new_smear.Add( self.smear_description_2d_x,0, wx.CENTER, 10 ) |
---|
[7609f1a] | 341 | self.sizer_new_smear.Add( self.smear_description_pin_min,0, wx.CENTER, 10 ) |
---|
| 342 | self.sizer_new_smear.Add( self.smear_description_slit_height,0, wx.CENTER, 10 ) |
---|
[f72333f] | 343 | |
---|
[7609f1a] | 344 | self.sizer_new_smear.Add( self.smear_pinhole_min,0, wx.CENTER, 10 ) |
---|
| 345 | self.sizer_new_smear.Add( self.smear_slit_height,0, wx.CENTER, 10 ) |
---|
| 346 | self.sizer_new_smear.Add( self.smear_data_left,0, wx.CENTER, 10 ) |
---|
| 347 | self.sizer_new_smear.Add((20,-1)) |
---|
[f72333f] | 348 | self.sizer_new_smear.Add( self.smear_description_2d_y,0, wx.CENTER, 10 ) |
---|
[7609f1a] | 349 | self.sizer_new_smear.Add( self.smear_description_pin_max,0, wx.CENTER, 10 ) |
---|
| 350 | self.sizer_new_smear.Add( self.smear_description_slit_width,0, wx.CENTER, 10 ) |
---|
[f72333f] | 351 | |
---|
[7609f1a] | 352 | self.sizer_new_smear.Add( self.smear_pinhole_max,0, wx.CENTER, 10 ) |
---|
| 353 | self.sizer_new_smear.Add( self.smear_slit_width,0, wx.CENTER, 10 ) |
---|
| 354 | self.sizer_new_smear.Add( self.smear_data_right,0, wx.CENTER, 10 ) |
---|
| 355 | |
---|
| 356 | self.sizer_set_smearer.Add( self.smear_message_new_s,0, wx.CENTER, 10) |
---|
| 357 | self.sizer_set_smearer.Add( self.smear_message_new_p,0, wx.CENTER, 10) |
---|
| 358 | self.sizer_set_smearer.Add((5,2)) |
---|
| 359 | self.sizer_set_smearer.Add( self.sizer_new_smear,0, wx.CENTER, 10 ) |
---|
| 360 | |
---|
[51a71a3] | 361 | # add all to chi2 sizer |
---|
| 362 | sizer_smearer_box.Add(self.sizer_set_smearer) |
---|
[7609f1a] | 363 | sizer_chi2.Add(sizer_smearer_box) |
---|
| 364 | sizer_chi2.Add((-1,5)) |
---|
[cc31608] | 365 | |
---|
[7609f1a] | 366 | # hide all smear messages and textctrl |
---|
| 367 | self._hide_all_smear_info() |
---|
| 368 | |
---|
| 369 | # get smear_selection |
---|
[f867cd9] | 370 | self.current_smearer= smear_selection( self.data, self.model ) |
---|
[83ad478] | 371 | |
---|
[7609f1a] | 372 | # Show only the relevant smear messages, etc |
---|
| 373 | if self.current_smearer == None: |
---|
[51a71a3] | 374 | if not is_2Ddata: |
---|
[7609f1a] | 375 | self.smear_description_none.Show(True) |
---|
| 376 | self.enable_smearer.Disable() |
---|
| 377 | else: |
---|
[f72333f] | 378 | self.smear_description_none.Show(True) |
---|
| 379 | #self.smear_description_2d.Show(True) |
---|
| 380 | #self.pinhole_smearer.Disable() |
---|
[7609f1a] | 381 | self.slit_smearer.Disable() |
---|
[f72333f] | 382 | #self.enable_smearer.Disable() |
---|
[0f8f831] | 383 | if self.data == None: |
---|
| 384 | self.slit_smearer.Disable() |
---|
| 385 | self.pinhole_smearer.Disable() |
---|
| 386 | self.enable_smearer.Disable() |
---|
[7609f1a] | 387 | else: self._show_smear_sizer() |
---|
[51a71a3] | 388 | boxsizer_range.Add(self.sizer_set_masking) |
---|
[6bbeacd4] | 389 | #2D data? default |
---|
| 390 | is_2Ddata = False |
---|
[7609f1a] | 391 | |
---|
[6bbeacd4] | 392 | #check if it is 2D data |
---|
[ba1f0b2] | 393 | if self.data.__class__.__name__ == "Data2D" or \ |
---|
| 394 | self.enable2D: |
---|
[6bbeacd4] | 395 | is_2Ddata = True |
---|
| 396 | |
---|
| 397 | self.sizer5.Clear(True) |
---|
| 398 | |
---|
[f95301b] | 399 | self.qmin = self.ModelTextCtrl(self, -1,size=(_BOX_WIDTH,20), |
---|
[6bbeacd4] | 400 | style=wx.TE_PROCESS_ENTER, |
---|
| 401 | text_enter_callback = self._onQrangeEnter) |
---|
[f95301b] | 402 | self.qmin.SetValue(str(self.qmin_x)) |
---|
| 403 | self.qmin.SetToolTipString("Minimun value of Q in linear scale.") |
---|
[6bbeacd4] | 404 | |
---|
| 405 | self.qmax = self.ModelTextCtrl(self, -1,size=(_BOX_WIDTH,20), |
---|
| 406 | style=wx.TE_PROCESS_ENTER, |
---|
| 407 | text_enter_callback=self._onQrangeEnter) |
---|
| 408 | self.qmax.SetValue(str(self.qmax_x)) |
---|
| 409 | self.qmax.SetToolTipString("Maximum value of Q in linear scale.") |
---|
[0cf97c5] | 410 | """ |
---|
[6bbeacd4] | 411 | self.theory_npts_tcrtl = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH, 20), |
---|
| 412 | style=wx.TE_PROCESS_ENTER, |
---|
| 413 | text_enter_callback=self._onQrangeEnter) |
---|
| 414 | self.theory_npts_tcrtl.SetValue(format_number(self.npts_x)) |
---|
| 415 | self.theory_npts_tcrtl.SetToolTipString("Number of point to plot.") |
---|
[0cf97c5] | 416 | """ |
---|
[6bbeacd4] | 417 | id = wx.NewId() |
---|
| 418 | self.reset_qrange =wx.Button(self,id,'Reset',size=(77,20)) |
---|
| 419 | |
---|
| 420 | self.reset_qrange.Bind(wx.EVT_BUTTON, self.on_reset_clicked,id=id) |
---|
| 421 | self.reset_qrange.SetToolTipString("Reset Q range to the default values") |
---|
| 422 | |
---|
| 423 | sizer_horizontal=wx.BoxSizer(wx.HORIZONTAL) |
---|
[0cf97c5] | 424 | sizer= wx.GridSizer(2, 4, 2, 6) |
---|
[6bbeacd4] | 425 | |
---|
| 426 | self.btEditMask = wx.Button(self,wx.NewId(),'Editor', size=(88,23)) |
---|
| 427 | self.btEditMask.Bind(wx.EVT_BUTTON, self._onMask,id= self.btEditMask.GetId()) |
---|
| 428 | self.btEditMask.SetToolTipString("Edit Mask.") |
---|
| 429 | self.EditMask_title = wx.StaticText(self, -1, ' Masking(2D)') |
---|
| 430 | |
---|
| 431 | sizer.Add(wx.StaticText(self, -1, 'Q range')) |
---|
| 432 | sizer.Add(wx.StaticText(self, -1, ' Min[1/A]')) |
---|
| 433 | sizer.Add(wx.StaticText(self, -1, ' Max[1/A]')) |
---|
| 434 | sizer.Add(self.EditMask_title) |
---|
[0cf97c5] | 435 | #sizer.Add(wx.StaticText(self, -1, '')) |
---|
[6bbeacd4] | 436 | sizer.Add(self.reset_qrange) |
---|
[f95301b] | 437 | sizer.Add(self.qmin) |
---|
[6bbeacd4] | 438 | sizer.Add(self.qmax) |
---|
[0cf97c5] | 439 | #sizer.Add(self.theory_npts_tcrtl) |
---|
[6bbeacd4] | 440 | sizer.Add(self.btEditMask) |
---|
| 441 | boxsizer_range.Add(sizer_chi2) |
---|
| 442 | boxsizer_range.Add((10,10)) |
---|
| 443 | boxsizer_range.Add(sizer) |
---|
| 444 | |
---|
| 445 | boxsizer_range.Add((10,15)) |
---|
| 446 | boxsizer_range.Add(sizer_fit) |
---|
| 447 | if is_2Ddata: |
---|
| 448 | self.btEditMask.Enable() |
---|
| 449 | self.EditMask_title.Enable() |
---|
| 450 | else: |
---|
| 451 | self.btEditMask.Disable() |
---|
| 452 | self.EditMask_title.Disable() |
---|
| 453 | ## save state |
---|
| 454 | self.save_current_state() |
---|
| 455 | self.sizer5.Add(boxsizer_range,0, wx.EXPAND | wx.ALL, 10) |
---|
| 456 | self.sizer5.Layout() |
---|
| 457 | |
---|
[813334e] | 458 | |
---|
[c77d859] | 459 | def _fill_model_sizer(self, sizer): |
---|
| 460 | """ |
---|
[5062bbf] | 461 | fill sizer containing model info |
---|
[c77d859] | 462 | """ |
---|
[7ad6ff5] | 463 | ##Add model function Details button in fitpanel. |
---|
[ff8f99b] | 464 | ##The following 3 lines are for Mac. Let JHC know before modifying... |
---|
| 465 | title = "Model" |
---|
[e4c9030] | 466 | self.formfactorbox = None |
---|
| 467 | self.multifactorbox = None |
---|
[88f286d] | 468 | self.mbox_description= wx.StaticBox(self, -1,str(title)) |
---|
| 469 | boxsizer1 = wx.StaticBoxSizer(self.mbox_description, wx.VERTICAL) |
---|
| 470 | |
---|
[7ad6ff5] | 471 | id = wx.NewId() |
---|
[e3a76c8] | 472 | self.model_help =wx.Button(self,id,'Details', size=(80,23)) |
---|
[7ad6ff5] | 473 | self.model_help.Bind(wx.EVT_BUTTON, self.on_model_help_clicked,id=id) |
---|
| 474 | self.model_help.SetToolTipString("Model Function Help") |
---|
[a5701e6] | 475 | id = wx.NewId() |
---|
[6371c9c] | 476 | self.model_view = wx.Button(self, id,"1D Mode", size=(80, 23)) |
---|
[a5701e6] | 477 | self.model_view.Bind(wx.EVT_BUTTON, self._onModel2D, id=id) |
---|
[8e33400] | 478 | hint = "toggle view of model from 1D to 2D or 2D to 1D" |
---|
[a5701e6] | 479 | self.model_view.SetToolTipString(hint) |
---|
| 480 | |
---|
[4225aed] | 481 | self.shape_rbutton = wx.RadioButton(self, -1, 'Shapes', |
---|
| 482 | style=wx.RB_GROUP) |
---|
[a5701e6] | 483 | self.shape_indep_rbutton = wx.RadioButton(self, -1, "Shape-Independent") |
---|
| 484 | self.struct_rbutton = wx.RadioButton(self, -1, "Structure Factor ") |
---|
| 485 | self.plugin_rbutton = wx.RadioButton(self, -1, "Customized Models") |
---|
| 486 | |
---|
| 487 | self.Bind(wx.EVT_RADIOBUTTON, self._show_combox, |
---|
| 488 | id= self.shape_rbutton.GetId()) |
---|
| 489 | self.Bind(wx.EVT_RADIOBUTTON, self._show_combox, |
---|
| 490 | id= self.shape_indep_rbutton.GetId()) |
---|
| 491 | self.Bind(wx.EVT_RADIOBUTTON, self._show_combox, |
---|
| 492 | id= self.struct_rbutton.GetId()) |
---|
| 493 | self.Bind(wx.EVT_RADIOBUTTON, self._show_combox, |
---|
| 494 | id= self.plugin_rbutton.GetId()) |
---|
| 495 | #MAC needs SetValue |
---|
| 496 | self.shape_rbutton.SetValue(True) |
---|
| 497 | |
---|
| 498 | sizer_radiobutton = wx.GridSizer(2, 3, 5, 5) |
---|
| 499 | sizer_radiobutton.Add(self.shape_rbutton) |
---|
| 500 | sizer_radiobutton.Add(self.shape_indep_rbutton) |
---|
| 501 | #sizer_radiobutton.Add((5, 5)) |
---|
| 502 | sizer_radiobutton.Add(self.model_view,1, wx.LEFT, 20) |
---|
| 503 | sizer_radiobutton.Add(self.plugin_rbutton) |
---|
| 504 | sizer_radiobutton.Add(self.struct_rbutton) |
---|
| 505 | #sizer_radiobutton.Add((5, 5)) |
---|
| 506 | sizer_radiobutton.Add(self.model_help,1, wx.LEFT, 20) |
---|
| 507 | |
---|
| 508 | sizer_selection = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 509 | mutifactor_selection = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 510 | |
---|
| 511 | self.text1 = wx.StaticText(self,-1,"" ) |
---|
| 512 | self.text2 = wx.StaticText(self,-1,"P(Q)*S(Q)" ) |
---|
| 513 | self.mutifactor_text = wx.StaticText( self,-1,"No. of Shells: ") |
---|
| 514 | self.mutifactor_text1 = wx.StaticText( self,-1,"" ) |
---|
| 515 | self.show_sld_button = wx.Button( self,-1,"Show SLD Profile" ) |
---|
| 516 | self.show_sld_button.Bind(wx.EVT_BUTTON,self._on_show_sld) |
---|
| 517 | |
---|
| 518 | self.formfactorbox = wx.ComboBox(self, -1,style=wx.CB_READONLY) |
---|
| 519 | if self.model!= None: |
---|
| 520 | self.formfactorbox.SetValue(self.model.name) |
---|
| 521 | self.structurebox = wx.ComboBox(self, -1, style=wx.CB_READONLY) |
---|
| 522 | self.multifactorbox = wx.ComboBox(self, -1, style=wx.CB_READONLY) |
---|
| 523 | self.initialize_combox() |
---|
| 524 | wx.EVT_COMBOBOX(self.formfactorbox, -1, self._on_select_model) |
---|
[9466f2d6] | 525 | |
---|
[a5701e6] | 526 | wx.EVT_COMBOBOX(self.structurebox, -1, self._on_select_model) |
---|
| 527 | wx.EVT_COMBOBOX(self.multifactorbox, -1, self._on_select_model) |
---|
| 528 | ## check model type to show sizer |
---|
| 529 | if self.model !=None: |
---|
| 530 | self._set_model_sizer_selection(self.model) |
---|
| 531 | |
---|
| 532 | sizer_selection.Add(self.text1) |
---|
| 533 | sizer_selection.Add((5, 5)) |
---|
| 534 | sizer_selection.Add(self.formfactorbox) |
---|
| 535 | sizer_selection.Add((5, 5)) |
---|
| 536 | sizer_selection.Add(self.text2) |
---|
| 537 | sizer_selection.Add((5, 5)) |
---|
| 538 | sizer_selection.Add(self.structurebox) |
---|
| 539 | |
---|
| 540 | mutifactor_selection.Add((10,5)) |
---|
| 541 | mutifactor_selection.Add(self.mutifactor_text) |
---|
| 542 | mutifactor_selection.Add(self.multifactorbox) |
---|
| 543 | mutifactor_selection.Add((5, 5)) |
---|
| 544 | mutifactor_selection.Add(self.mutifactor_text1) |
---|
| 545 | mutifactor_selection.Add((10, 5)) |
---|
| 546 | mutifactor_selection.Add(self.show_sld_button) |
---|
| 547 | |
---|
| 548 | |
---|
| 549 | boxsizer1.Add(sizer_radiobutton) |
---|
| 550 | boxsizer1.Add((10, 10)) |
---|
| 551 | boxsizer1.Add(sizer_selection) |
---|
| 552 | boxsizer1.Add((10, 10)) |
---|
| 553 | boxsizer1.Add(mutifactor_selection) |
---|
| 554 | |
---|
| 555 | self._set_multfactor_combobox() |
---|
| 556 | self.multifactorbox.SetSelection(1) |
---|
| 557 | self.show_sld_button.Hide() |
---|
| 558 | sizer.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10) |
---|
| 559 | sizer.Layout() |
---|
[5062bbf] | 560 | |
---|
[2296316] | 561 | def _set_sizer_dispersion(self): |
---|
[c77d859] | 562 | """ |
---|
[5062bbf] | 563 | draw sizer with gaussian dispersity parameters |
---|
[c77d859] | 564 | """ |
---|
| 565 | self.fittable_param=[] |
---|
| 566 | self.fixed_param=[] |
---|
[60132ef] | 567 | self.orientation_params_disp=[] |
---|
[920a6e5] | 568 | |
---|
[c77d859] | 569 | self.sizer4_4.Clear(True) |
---|
| 570 | if self.model==None: |
---|
| 571 | ##no model is selected |
---|
| 572 | return |
---|
| 573 | if not self.enable_disp.GetValue(): |
---|
| 574 | ## the user didn't select dispersity display |
---|
| 575 | return |
---|
[b421b1a] | 576 | |
---|
[376916c] | 577 | self._reset_dispersity() |
---|
[b421b1a] | 578 | |
---|
[2296316] | 579 | ## fill a sizer with the combobox to select dispersion type |
---|
| 580 | #sizer_select_dispers = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 581 | model_disp = wx.StaticText(self, -1, 'Function') |
---|
| 582 | |
---|
| 583 | import sans.models.dispersion_models |
---|
| 584 | self.polydisp= sans.models.dispersion_models.models |
---|
[b421b1a] | 585 | |
---|
[2296316] | 586 | ix = 0 |
---|
| 587 | iy = 0 |
---|
[52efcc5] | 588 | disp = wx.StaticText(self, -1, ' ') |
---|
[c77d859] | 589 | self.sizer4_4.Add(disp,( iy, ix),(1,1), |
---|
| 590 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 591 | ix += 1 |
---|
[2296316] | 592 | values = wx.StaticText(self, -1, 'PD[ratio]') |
---|
[01b6bd0] | 593 | polytext = "Polydispersity (= STD/mean); " |
---|
| 594 | polytext += "the standard deviation over the mean value." |
---|
| 595 | values.SetToolTipString(polytext) |
---|
[d7b7156] | 596 | |
---|
| 597 | self.sizer4_4.Add(values,( iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, |
---|
| 598 | 0) |
---|
[c77d859] | 599 | ix +=2 |
---|
[e5a1c31] | 600 | if self.is_mac: |
---|
| 601 | err_text = 'Error' |
---|
| 602 | else: |
---|
| 603 | err_text = '' |
---|
| 604 | self.text_disp_1 = wx.StaticText(self, -1, err_text) |
---|
[c77d859] | 605 | self.sizer4_4.Add( self.text_disp_1,(iy, ix),(1,1),\ |
---|
| 606 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[920a6e5] | 607 | |
---|
| 608 | |
---|
| 609 | ix +=1 |
---|
| 610 | self.text_disp_min = wx.StaticText(self, -1, 'Min') |
---|
| 611 | self.sizer4_4.Add(self.text_disp_min,(iy, ix),(1,1),\ |
---|
| 612 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[2296316] | 613 | |
---|
[920a6e5] | 614 | ix +=1 |
---|
| 615 | self.text_disp_max = wx.StaticText(self, -1, 'Max') |
---|
| 616 | self.sizer4_4.Add(self.text_disp_max,(iy, ix),(1,1),\ |
---|
| 617 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[339b563] | 618 | |
---|
[c77d859] | 619 | ix += 1 |
---|
| 620 | npts = wx.StaticText(self, -1, 'Npts') |
---|
[d7b7156] | 621 | npts.SetToolTipString("Number of sampling points for the numerical\n\ |
---|
| 622 | integration over the distribution function.") |
---|
[c77d859] | 623 | self.sizer4_4.Add(npts,( iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 624 | ix += 1 |
---|
[2296316] | 625 | nsigmas = wx.StaticText(self, -1, 'Nsigs') |
---|
[d7b7156] | 626 | nsigmas.SetToolTipString(" Number of sigmas between which the range\n\ |
---|
| 627 | of the distribution function will be used for weighting. \n\ |
---|
| 628 | The value '3' covers 99.5% for Gaussian distribution \n\ |
---|
[01b6bd0] | 629 | function. Note: Not recommended to change this value.") |
---|
[d7b7156] | 630 | self.sizer4_4.Add(nsigmas,( iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, |
---|
| 631 | 0) |
---|
[2296316] | 632 | ix +=1 |
---|
| 633 | self.sizer4_4.Add(model_disp,(iy, ix),(1,1),\ |
---|
| 634 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[920a6e5] | 635 | |
---|
| 636 | if self.engine_type=="park": |
---|
| 637 | self.text_disp_max.Show(True) |
---|
| 638 | self.text_disp_min.Show(True) |
---|
[6dc9ad8] | 639 | |
---|
[c77d859] | 640 | for item in self.model.dispersion.keys(): |
---|
[780d095] | 641 | if not item in self.model.orientation_params: |
---|
[edd166b] | 642 | if not self.disp_cb_dict.has_key(item): |
---|
| 643 | self.disp_cb_dict[item]= None |
---|
[d7b7156] | 644 | name0="Distribution of " + item |
---|
[780d095] | 645 | name1=item+".width" |
---|
| 646 | name2=item+".npts" |
---|
| 647 | name3=item+".nsigmas" |
---|
[c99a6c5] | 648 | if not self.model.details.has_key(name1): |
---|
[b421b1a] | 649 | self.model.details [name1] = ["",None,None] |
---|
[c99a6c5] | 650 | |
---|
[780d095] | 651 | iy += 1 |
---|
| 652 | for p in self.model.dispersion[item].keys(): |
---|
| 653 | |
---|
| 654 | if p=="width": |
---|
| 655 | ix = 0 |
---|
[d7b7156] | 656 | cb = wx.CheckBox(self, -1, name0, (10, 10)) |
---|
[2296316] | 657 | cb.SetToolTipString("Check mark to fit") |
---|
[780d095] | 658 | wx.EVT_CHECKBOX(self, cb.GetId(), self.select_param) |
---|
| 659 | self.sizer4_4.Add( cb,( iy, ix),(1,1), |
---|
[d7b7156] | 660 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, |
---|
[2296316] | 661 | 5) |
---|
[780d095] | 662 | ix = 1 |
---|
| 663 | value= self.model.getParam(name1) |
---|
[2296316] | 664 | ctl1 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/1.3,20) |
---|
[d7b7156] | 665 | ,style=wx.TE_PROCESS_ENTER) |
---|
[01b6bd0] | 666 | ctl1.SetLabel('PD[ratio]') |
---|
| 667 | poly_text = "Polydispersity (STD/mean) of %s\n" % item |
---|
| 668 | poly_text += "STD: the standard deviation" |
---|
| 669 | poly_text += " from the mean value." |
---|
| 670 | ctl1.SetToolTipString(poly_text) |
---|
[2296316] | 671 | ctl1.SetValue(str (format_number(value, True))) |
---|
[780d095] | 672 | self.sizer4_4.Add(ctl1, (iy,ix),(1,1),wx.EXPAND) |
---|
| 673 | ## text to show error sign |
---|
| 674 | ix = 2 |
---|
| 675 | text2=wx.StaticText(self, -1, '+/-') |
---|
| 676 | self.sizer4_4.Add(text2,(iy, ix),(1,1), |
---|
| 677 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[ce92ded] | 678 | if not self.is_mac: |
---|
| 679 | text2.Hide() |
---|
[b421b1a] | 680 | |
---|
[780d095] | 681 | ix = 3 |
---|
[2296316] | 682 | ctl2 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH/1.3,20), |
---|
[d7b7156] | 683 | style=0) |
---|
[eacf1d66] | 684 | |
---|
[d7b7156] | 685 | self.sizer4_4.Add(ctl2, (iy,ix),(1,1), |
---|
| 686 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[ce92ded] | 687 | if not self.is_mac: |
---|
| 688 | ctl2.Hide() |
---|
[eacf1d66] | 689 | |
---|
[920a6e5] | 690 | ix = 4 |
---|
[d7b7156] | 691 | ctl3 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/2, |
---|
| 692 | 20), style=wx.TE_PROCESS_ENTER, |
---|
| 693 | text_enter_callback = self._onparamRangeEnter) |
---|
[b9405cd] | 694 | |
---|
[d7b7156] | 695 | self.sizer4_4.Add(ctl3, (iy,ix),(1,1), |
---|
| 696 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[2296316] | 697 | |
---|
[920a6e5] | 698 | |
---|
| 699 | ix = 5 |
---|
[d7b7156] | 700 | ctl4 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/2, |
---|
| 701 | 20), style=wx.TE_PROCESS_ENTER, |
---|
| 702 | text_enter_callback = self._onparamRangeEnter) |
---|
[b9405cd] | 703 | |
---|
[d7b7156] | 704 | self.sizer4_4.Add(ctl4, (iy,ix),(1,1), |
---|
| 705 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[eacf1d66] | 706 | |
---|
[920a6e5] | 707 | |
---|
| 708 | if self.engine_type=="park": |
---|
| 709 | ctl3.Show(True) |
---|
| 710 | ctl4.Show(True) |
---|
[2296316] | 711 | |
---|
[780d095] | 712 | elif p=="npts": |
---|
[920a6e5] | 713 | ix = 6 |
---|
[780d095] | 714 | value= self.model.getParam(name2) |
---|
[d7b7156] | 715 | Tctl = self.ModelTextCtrl(self, -1, |
---|
[2296316] | 716 | size=(_BOX_WIDTH/2.2,20), |
---|
[780d095] | 717 | style=wx.TE_PROCESS_ENTER) |
---|
[1a94c36] | 718 | |
---|
[780d095] | 719 | Tctl.SetValue(str (format_number(value))) |
---|
| 720 | self.sizer4_4.Add(Tctl, (iy,ix),(1,1), |
---|
| 721 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 722 | self.fixed_param.append([None,name2, Tctl,None,None, |
---|
| 723 | None, None,None]) |
---|
| 724 | elif p=="nsigmas": |
---|
[920a6e5] | 725 | ix = 7 |
---|
[780d095] | 726 | value= self.model.getParam(name3) |
---|
[d7b7156] | 727 | Tct2 = self.ModelTextCtrl(self, -1, |
---|
[2296316] | 728 | size=(_BOX_WIDTH/2.2,20), |
---|
[780d095] | 729 | style=wx.TE_PROCESS_ENTER) |
---|
[1a94c36] | 730 | |
---|
[c985bef] | 731 | Tct2.SetValue(str (format_number(value))) |
---|
| 732 | self.sizer4_4.Add(Tct2, (iy,ix),(1,1), |
---|
[780d095] | 733 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[2296316] | 734 | #ix +=1 |
---|
| 735 | #self.sizer4_4.Add((20,20), (iy,ix),(1,1), |
---|
| 736 | # wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[920a6e5] | 737 | |
---|
[2296316] | 738 | self.fixed_param.append([None, name3, Tct2, |
---|
| 739 | None, None, None, |
---|
| 740 | None, None]) |
---|
| 741 | |
---|
| 742 | |
---|
| 743 | ix = 8 |
---|
| 744 | disp_box = wx.ComboBox(self, -1,size=(65,-1), |
---|
| 745 | style=wx.CB_READONLY, name = '%s'% name1) |
---|
| 746 | for key, value in self.polydisp.iteritems(): |
---|
| 747 | name_disp = str(key) |
---|
| 748 | disp_box.Append(name_disp,value) |
---|
| 749 | disp_box.SetStringSelection("gaussian") |
---|
| 750 | wx.EVT_COMBOBOX(disp_box,-1, self._on_disp_func) |
---|
| 751 | self.sizer4_4.Add(disp_box,(iy,ix),(1,1), wx.EXPAND) |
---|
| 752 | self.fittable_param.append([cb,name1,ctl1,text2, |
---|
| 753 | ctl2, ctl3, ctl4, disp_box]) |
---|
| 754 | |
---|
[780d095] | 755 | ix =0 |
---|
| 756 | iy +=1 |
---|
[d7b7156] | 757 | self.sizer4_4.Add((20,20),(iy,ix),(1,1), |
---|
| 758 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 759 | first_orient = True |
---|
[780d095] | 760 | for item in self.model.dispersion.keys(): |
---|
| 761 | if item in self.model.orientation_params: |
---|
[edd166b] | 762 | if not self.disp_cb_dict.has_key(item): |
---|
| 763 | self.disp_cb_dict[item]= None |
---|
[d7b7156] | 764 | name0="Distribution of " + item |
---|
[780d095] | 765 | name1=item+".width" |
---|
| 766 | name2=item+".npts" |
---|
| 767 | name3=item+".nsigmas" |
---|
[d7b7156] | 768 | |
---|
[c99a6c5] | 769 | if not self.model.details.has_key(name1): |
---|
[b421b1a] | 770 | self.model.details [name1] = ["",None,None] |
---|
| 771 | |
---|
| 772 | |
---|
[780d095] | 773 | iy += 1 |
---|
| 774 | for p in self.model.dispersion[item].keys(): |
---|
| 775 | |
---|
| 776 | if p=="width": |
---|
| 777 | ix = 0 |
---|
[d7b7156] | 778 | cb = wx.CheckBox(self, -1, name0, (10, 10)) |
---|
[2296316] | 779 | cb.SetToolTipString("Check mark to fit") |
---|
[780d095] | 780 | wx.EVT_CHECKBOX(self, cb.GetId(), self.select_param) |
---|
| 781 | self.sizer4_4.Add( cb,( iy, ix),(1,1), |
---|
[d7b7156] | 782 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, |
---|
[2296316] | 783 | 5) |
---|
[ba1f0b2] | 784 | if self.data.__class__.__name__ == "Data2D" or \ |
---|
| 785 | self.enable2D: |
---|
[6dc9ad8] | 786 | cb.Show(True) |
---|
[c99a6c5] | 787 | elif cb.IsShown(): |
---|
[6dc9ad8] | 788 | cb.Hide() |
---|
[780d095] | 789 | ix = 1 |
---|
| 790 | value= self.model.getParam(name1) |
---|
[2296316] | 791 | ctl1 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/1.3, |
---|
[d7b7156] | 792 | 20),style=wx.TE_PROCESS_ENTER) |
---|
[01b6bd0] | 793 | poly_tip = "Absolute Sigma for %s." % item |
---|
| 794 | ctl1.SetToolTipString(poly_tip) |
---|
[2296316] | 795 | ctl1.SetValue(str (format_number(value, True))) |
---|
[ba1f0b2] | 796 | if self.data.__class__.__name__ == "Data2D" or \ |
---|
| 797 | self.enable2D: |
---|
[d7b7156] | 798 | if first_orient: |
---|
[01b6bd0] | 799 | values.SetLabel('PD[ratio], Sig[deg]') |
---|
| 800 | poly_text = "PD(polydispersity for lengths):\n" |
---|
| 801 | poly_text += "It should be a value between" |
---|
| 802 | poly_text += "0 and 1\n" |
---|
| 803 | poly_text += "Sigma for angles: \n" |
---|
| 804 | poly_text += "It is the STD (ratio*mean)" |
---|
[2b0f822] | 805 | poly_text += " of the distribution.\n " |
---|
[01b6bd0] | 806 | |
---|
| 807 | values.SetToolTipString(poly_text) |
---|
[d7b7156] | 808 | first_orient = False |
---|
[6dc9ad8] | 809 | ctl1.Show(True) |
---|
[c99a6c5] | 810 | elif ctl1.IsShown(): |
---|
[6dc9ad8] | 811 | ctl1.Hide() |
---|
[d7b7156] | 812 | |
---|
[780d095] | 813 | self.sizer4_4.Add(ctl1, (iy,ix),(1,1),wx.EXPAND) |
---|
| 814 | ## text to show error sign |
---|
| 815 | ix = 2 |
---|
| 816 | text2=wx.StaticText(self, -1, '+/-') |
---|
| 817 | self.sizer4_4.Add(text2,(iy, ix),(1,1), |
---|
| 818 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[e792aee] | 819 | |
---|
| 820 | text2.Hide() |
---|
[b421b1a] | 821 | |
---|
[780d095] | 822 | ix = 3 |
---|
[2296316] | 823 | ctl2 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH/1.3,20), |
---|
[d7b7156] | 824 | style=0) |
---|
[b421b1a] | 825 | |
---|
[d7b7156] | 826 | self.sizer4_4.Add(ctl2, (iy,ix),(1,1), |
---|
| 827 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[e792aee] | 828 | |
---|
| 829 | ctl2.Hide() |
---|
[1180528] | 830 | if self.data.__class__.__name__ == "Data2D" or \ |
---|
| 831 | self.enable2D: |
---|
| 832 | if self.is_mac: |
---|
| 833 | text2.Show(True) |
---|
| 834 | ctl2.Show(True) |
---|
[920a6e5] | 835 | |
---|
| 836 | ix = 4 |
---|
[d7b7156] | 837 | ctl3 = self.ModelTextCtrl(self, -1, |
---|
| 838 | size=(_BOX_WIDTH/2,20), |
---|
| 839 | style=wx.TE_PROCESS_ENTER, |
---|
| 840 | text_enter_callback = self._onparamRangeEnter) |
---|
[eacf1d66] | 841 | |
---|
[d7b7156] | 842 | self.sizer4_4.Add(ctl3, (iy,ix),(1,1), |
---|
| 843 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[c99a6c5] | 844 | |
---|
[920a6e5] | 845 | ctl3.Hide() |
---|
| 846 | |
---|
| 847 | ix = 5 |
---|
[d7b7156] | 848 | ctl4 = self.ModelTextCtrl(self, -1, |
---|
| 849 | size=(_BOX_WIDTH/2,20), style=wx.TE_PROCESS_ENTER, |
---|
| 850 | text_enter_callback = self._onparamRangeEnter) |
---|
| 851 | self.sizer4_4.Add(ctl4, (iy,ix),(1,1), |
---|
| 852 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[920a6e5] | 853 | ctl4.Hide() |
---|
| 854 | |
---|
[ba1f0b2] | 855 | if self.data.__class__.__name__ == "Data2D" or \ |
---|
| 856 | self.enable2D: |
---|
[920a6e5] | 857 | ctl3.Show(True) |
---|
[c99a6c5] | 858 | ctl4.Show(True) |
---|
[2296316] | 859 | |
---|
[780d095] | 860 | elif p=="npts": |
---|
[920a6e5] | 861 | ix = 6 |
---|
[780d095] | 862 | value= self.model.getParam(name2) |
---|
[d7b7156] | 863 | Tctl = self.ModelTextCtrl(self, -1, |
---|
[2296316] | 864 | size=(_BOX_WIDTH/2.2, 20), |
---|
[780d095] | 865 | style=wx.TE_PROCESS_ENTER) |
---|
[1a94c36] | 866 | |
---|
[780d095] | 867 | Tctl.SetValue(str (format_number(value))) |
---|
[ba1f0b2] | 868 | if self.data.__class__.__name__ == "Data2D" or \ |
---|
| 869 | self.enable2D: |
---|
[6dc9ad8] | 870 | Tctl.Show(True) |
---|
[780d095] | 871 | else: |
---|
[6dc9ad8] | 872 | Tctl.Hide() |
---|
[780d095] | 873 | self.sizer4_4.Add(Tctl, (iy,ix),(1,1), |
---|
| 874 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 875 | self.fixed_param.append([None,name2, Tctl,None,None, |
---|
| 876 | None, None,None]) |
---|
[d7b7156] | 877 | self.orientation_params_disp.append([None,name2, |
---|
| 878 | Tctl,None,None, |
---|
[780d095] | 879 | None, None,None]) |
---|
| 880 | elif p=="nsigmas": |
---|
[920a6e5] | 881 | ix = 7 |
---|
[780d095] | 882 | value= self.model.getParam(name3) |
---|
[d7b7156] | 883 | Tct2 = self.ModelTextCtrl(self, -1, |
---|
[2296316] | 884 | size=(_BOX_WIDTH/2.2,20), |
---|
[780d095] | 885 | style=wx.TE_PROCESS_ENTER) |
---|
[1a94c36] | 886 | |
---|
[c985bef] | 887 | Tct2.SetValue(str (format_number(value))) |
---|
[ba1f0b2] | 888 | if self.data.__class__.__name__ == "Data2D" or \ |
---|
| 889 | self.enable2D: |
---|
[c985bef] | 890 | Tct2.Show(True) |
---|
[780d095] | 891 | else: |
---|
[c985bef] | 892 | Tct2.Hide() |
---|
| 893 | self.sizer4_4.Add(Tct2, (iy,ix),(1,1), |
---|
[780d095] | 894 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[2296316] | 895 | |
---|
[7975f2b] | 896 | |
---|
[c985bef] | 897 | self.fixed_param.append([None,name3, Tct2 |
---|
[d7b7156] | 898 | ,None,None, None, None,None]) |
---|
[920a6e5] | 899 | |
---|
[d7b7156] | 900 | self.orientation_params_disp.append([None,name3, |
---|
| 901 | Tct2 ,None,None, None, None,None]) |
---|
| 902 | |
---|
[2296316] | 903 | |
---|
| 904 | ix = 8 |
---|
| 905 | disp_box = wx.ComboBox(self, -1,size=(65,-1), |
---|
| 906 | style=wx.CB_READONLY, name = '%s'% name1) |
---|
| 907 | for key, value in self.polydisp.iteritems(): |
---|
| 908 | name_disp = str(key) |
---|
| 909 | disp_box.Append(name_disp,value) |
---|
| 910 | disp_box.SetStringSelection("gaussian") |
---|
| 911 | wx.EVT_COMBOBOX(disp_box,-1, self._on_disp_func) |
---|
| 912 | self.sizer4_4.Add(disp_box,(iy,ix),(1,1), wx.EXPAND) |
---|
| 913 | self.fittable_param.append([cb,name1,ctl1,text2, |
---|
| 914 | ctl2, ctl3, ctl4, disp_box]) |
---|
| 915 | self.orientation_params_disp.append([cb,name1,ctl1, |
---|
| 916 | text2, ctl2, ctl3, ctl4, disp_box]) |
---|
| 917 | |
---|
[ba1f0b2] | 918 | if self.data.__class__.__name__ == "Data2D" or \ |
---|
| 919 | self.enable2D: |
---|
[2296316] | 920 | disp_box.Show(True) |
---|
| 921 | else: |
---|
| 922 | disp_box.Hide() |
---|
| 923 | |
---|
| 924 | |
---|
[b421b1a] | 925 | self.state.disp_cb_dict = copy.deepcopy(self.disp_cb_dict) |
---|
| 926 | |
---|
[71f0373] | 927 | self.state.model = self.model.clone() |
---|
[240b9966] | 928 | ## save state into |
---|
[4043c96] | 929 | self.state.cb1 = self.cb1.GetValue() |
---|
[920a6e5] | 930 | self._copy_parameters_state(self.parameters, self.state.parameters) |
---|
[240b9966] | 931 | self._copy_parameters_state(self.orientation_params_disp, |
---|
| 932 | self.state.orientation_params_disp) |
---|
[d7b7156] | 933 | self._copy_parameters_state(self.fittable_param, |
---|
| 934 | self.state.fittable_param) |
---|
[240b9966] | 935 | self._copy_parameters_state(self.fixed_param, self.state.fixed_param) |
---|
[d40a9cd] | 936 | |
---|
| 937 | |
---|
[c77d859] | 938 | wx.PostEvent(self.parent, StatusEvent(status=\ |
---|
| 939 | " Selected Distribution: Gaussian")) |
---|
[b324aa9] | 940 | #Fill the list of fittable parameters |
---|
| 941 | self.select_all_param(event=None) |
---|
| 942 | |
---|
[71f0373] | 943 | self.Layout() |
---|
[7975f2b] | 944 | |
---|
[2296316] | 945 | |
---|
| 946 | def _onDraw(self, event): |
---|
| 947 | """ |
---|
| 948 | Update and Draw the model |
---|
| 949 | """ |
---|
| 950 | if self.model ==None: |
---|
| 951 | msg="Please select a Model first..." |
---|
| 952 | wx.MessageBox(msg, 'Info') |
---|
[06aa2eeb] | 953 | |
---|
[2296316] | 954 | return |
---|
| 955 | flag = self._update_paramv_on_fit() |
---|
| 956 | self._onparamEnter_helper() |
---|
| 957 | if not flag: |
---|
| 958 | msg= "The parameters are invalid" |
---|
| 959 | wx.PostEvent(self.parent.parent, StatusEvent(status= msg )) |
---|
| 960 | return |
---|
| 961 | |
---|
| 962 | |
---|
[c77d859] | 963 | def _onFit(self, event): |
---|
| 964 | """ |
---|
[5062bbf] | 965 | Allow to fit |
---|
[c77d859] | 966 | """ |
---|
[054c10a] | 967 | if event != None: |
---|
| 968 | event.Skip() |
---|
[dc613d6] | 969 | if len(self.parent._manager.fit_thread_list)>0 and\ |
---|
| 970 | self.parent._manager._fit_engine != "park": |
---|
| 971 | msg = "The FitEnging will be set to 'ParkMC'\n" |
---|
| 972 | msg += " to fit with more than one data set..." |
---|
| 973 | wx.MessageBox(msg, 'Info') |
---|
| 974 | #wx.PostEvent(self._manager.parent, StatusEvent(status=\ |
---|
| 975 | # "Fitting: %s"%msg)) |
---|
| 976 | |
---|
[504dd9f5] | 977 | if self.data is None: |
---|
[ecfcef6] | 978 | msg = "Please get Data first..." |
---|
[504dd9f5] | 979 | wx.MessageBox(msg, 'Info') |
---|
| 980 | wx.PostEvent(self._manager.parent, StatusEvent(status=\ |
---|
| 981 | "Fit: %s" % msg)) |
---|
| 982 | return |
---|
| 983 | if self.model is None: |
---|
| 984 | msg = "Please select a Model first..." |
---|
[4470b10] | 985 | wx.MessageBox(msg, 'Info') |
---|
[90a7bbd] | 986 | wx.PostEvent(self._manager.parent, StatusEvent(status=\ |
---|
[2296316] | 987 | "Fit: %s"%msg, type="stop")) |
---|
[4470b10] | 988 | return |
---|
[ecfcef6] | 989 | |
---|
| 990 | if len(self.param_toFit) <= 0: |
---|
| 991 | msg= "Select at least one parameter to fit" |
---|
| 992 | wx.MessageBox(msg, 'Info') |
---|
| 993 | wx.PostEvent(self._manager.parent, StatusEvent(status= msg, |
---|
| 994 | type="stop" )) |
---|
| 995 | return |
---|
| 996 | |
---|
[85b3971] | 997 | flag = self._update_paramv_on_fit() |
---|
[acd0bda3] | 998 | |
---|
[c77d859] | 999 | if not flag: |
---|
[7609f1a] | 1000 | msg= "Fitting range or parameters are invalid" |
---|
[2296316] | 1001 | wx.PostEvent(self.parent.parent, StatusEvent(status= msg, |
---|
| 1002 | type="stop")) |
---|
[c77d859] | 1003 | return |
---|
[ecfcef6] | 1004 | |
---|
[7975f2b] | 1005 | self.select_param(event =None) |
---|
[acd0bda3] | 1006 | |
---|
[c99a6c5] | 1007 | #Clear errors if exist from previous fitting |
---|
[edd166b] | 1008 | #self._clear_Err_on_Fit() |
---|
[d0ce2c30] | 1009 | |
---|
[d7b7156] | 1010 | # Remove or do not allow fitting on the Q=0 point, especially |
---|
| 1011 | # when y(q=0)=None at x[0]. |
---|
[f95301b] | 1012 | self.qmin_x = float(self.qmin.GetValue()) |
---|
[67ae937] | 1013 | self.qmax_x = float(self.qmax.GetValue()) |
---|
[dc613d6] | 1014 | self._manager._reset_schedule_problem(value=0, uid=self.uid) |
---|
[67ae937] | 1015 | self._manager.schedule_for_fit(uid=self.uid,value=1, fitproblem=None) |
---|
| 1016 | self._manager.set_fit_range(uid=self.uid,qmin=self.qmin_x, |
---|
| 1017 | qmax=self.qmax_x) |
---|
[c77d859] | 1018 | #single fit |
---|
[dc613d6] | 1019 | self._manager.onFit(uid=self.uid) |
---|
[66ff250] | 1020 | self.btFit.SetLabel("Stop") |
---|
| 1021 | self.bind_fit_button() |
---|
[cfbd06a] | 1022 | |
---|
[f22e626] | 1023 | |
---|
[66ff250] | 1024 | def bind_fit_button(self): |
---|
| 1025 | """ |
---|
| 1026 | bind the fit button to either fit handler or stop fit handler |
---|
| 1027 | """ |
---|
[29bf83b] | 1028 | self.btFit.Unbind(event=wx.EVT_BUTTON, id= self.btFit.GetId()) |
---|
[66ff250] | 1029 | if self.btFit.GetLabel().lower() == "stop": |
---|
[f22e626] | 1030 | self.fit_started = True |
---|
[29bf83b] | 1031 | self.btFit.SetForegroundColour('red') |
---|
| 1032 | self.btFit.Bind(event=wx.EVT_BUTTON, handler=self._StopFit, |
---|
[66ff250] | 1033 | id=self.btFit.GetId()) |
---|
| 1034 | elif self.btFit.GetLabel().lower() == "fit": |
---|
[f22e626] | 1035 | self.fit_started = False |
---|
[e030625] | 1036 | self.btFit.SetDefault() |
---|
[29bf83b] | 1037 | self.btFit.SetForegroundColour('black') |
---|
[e030625] | 1038 | #self.btFit.SetBackgroundColour(self.default_bt_colour) |
---|
[29bf83b] | 1039 | self.btFit.Bind(event=wx.EVT_BUTTON, handler=self._onFit, |
---|
[66ff250] | 1040 | id=self.btFit.GetId()) |
---|
| 1041 | else: |
---|
| 1042 | msg = "FitPage: fit button has unknown label" |
---|
| 1043 | raise ValuerError, msg |
---|
| 1044 | self._manager._reset_schedule_problem(value=0) |
---|
| 1045 | |
---|
[f22e626] | 1046 | def is_fitting(self): |
---|
| 1047 | if self.fit_started: |
---|
| 1048 | self._StopFit(event=None) |
---|
| 1049 | |
---|
| 1050 | def _StopFit(self, event=None): |
---|
[ad6dd4c] | 1051 | """ |
---|
[5062bbf] | 1052 | Stop fit |
---|
[ad6dd4c] | 1053 | """ |
---|
[3ddc2c4] | 1054 | #time.sleep(0.1) |
---|
[5f2de0aa] | 1055 | if event != None: |
---|
| 1056 | event.Skip() |
---|
[66ff250] | 1057 | #if self.engine_type=="scipy": |
---|
| 1058 | self._manager.stop_fit(self.uid) |
---|
| 1059 | self._manager._reset_schedule_problem(value=0) |
---|
[db47703] | 1060 | self._on_fit_complete() |
---|
[66ff250] | 1061 | |
---|
[0b12abb5] | 1062 | def _on_select_model(self, event=None): |
---|
[c77d859] | 1063 | """ |
---|
[5062bbf] | 1064 | call back for model selection |
---|
[6747217] | 1065 | """ |
---|
[9466f2d6] | 1066 | |
---|
[70468a5] | 1067 | self.Show(False) |
---|
[59a7f2d] | 1068 | self._on_select_model_helper() |
---|
[70c57ebf] | 1069 | self.set_model_param_sizer(self.model) |
---|
[982e953] | 1070 | if self.model is None: |
---|
| 1071 | self._set_bookmark_flag(False) |
---|
[2657df9] | 1072 | self._keep.Enable(False) |
---|
[982e953] | 1073 | self._set_save_flag(False) |
---|
[3b605bb] | 1074 | self.enable_disp.SetValue(False) |
---|
| 1075 | self.disable_disp.SetValue(True) |
---|
[4043c96] | 1076 | try: |
---|
| 1077 | self.set_dispers_sizer() |
---|
| 1078 | except: |
---|
| 1079 | pass |
---|
[53ae26d] | 1080 | #self.btFit.SetFocus() |
---|
[6747217] | 1081 | self.state.enable_disp = self.enable_disp.GetValue() |
---|
| 1082 | self.state.disable_disp = self.disable_disp.GetValue() |
---|
| 1083 | self.state.pinhole_smearer = self.pinhole_smearer.GetValue() |
---|
| 1084 | self.state.slit_smearer = self.slit_smearer.GetValue() |
---|
| 1085 | |
---|
| 1086 | self.state.structurecombobox = self.structurebox.GetCurrentSelection() |
---|
| 1087 | self.state.formfactorcombobox = self.formfactorbox.GetCurrentSelection() |
---|
| 1088 | |
---|
[9237df4] | 1089 | if self.model != None: |
---|
[07c8630] | 1090 | self._set_copy_flag(True) |
---|
| 1091 | self._set_paste_flag(True) |
---|
[1258aa3] | 1092 | if self.data != None: |
---|
| 1093 | self._set_bookmark_flag(True) |
---|
[2657df9] | 1094 | self._keep.Enable(True) |
---|
[f932c02] | 1095 | #self._set_save_flag(True) |
---|
[64bda1e] | 1096 | # Reset smearer, model and data |
---|
[6bbeacd4] | 1097 | self._set_smear(self.data) |
---|
[70c57ebf] | 1098 | try: |
---|
[6bbeacd4] | 1099 | # update smearer sizer |
---|
| 1100 | self.onSmear(None) |
---|
[64bda1e] | 1101 | temp_smear = None |
---|
[70c57ebf] | 1102 | if self.enable_smearer.GetValue(): |
---|
[64bda1e] | 1103 | # Set the smearer environments |
---|
[6bbeacd4] | 1104 | temp_smear = self.smearer |
---|
[70c57ebf] | 1105 | except: |
---|
[66ff250] | 1106 | raise |
---|
[70c57ebf] | 1107 | ## error occured on chisqr computation |
---|
[66ff250] | 1108 | #pass |
---|
[0b12abb5] | 1109 | ## event to post model to fit to fitting plugins |
---|
| 1110 | (ModelEventbox, EVT_MODEL_BOX) = wx.lib.newevent.NewEvent() |
---|
[d9638fd] | 1111 | |
---|
[6bbeacd4] | 1112 | ## set smearing value whether or not |
---|
| 1113 | # the data contain the smearing info |
---|
| 1114 | evt = ModelEventbox(model=self.model, |
---|
| 1115 | smearer=temp_smear, |
---|
| 1116 | qmin=float(self.qmin_x), |
---|
[66ff250] | 1117 | uid=self.uid, |
---|
[6bbeacd4] | 1118 | qmax=float(self.qmax_x)) |
---|
| 1119 | |
---|
| 1120 | self._manager._on_model_panel(evt=evt) |
---|
[88f286d] | 1121 | self.mbox_description.SetLabel("Model [%s]" % str(self.model.name)) |
---|
[0b12abb5] | 1122 | self.state.model = self.model.clone() |
---|
| 1123 | self.state.model.name = self.model.name |
---|
[88f286d] | 1124 | |
---|
[0145a25] | 1125 | |
---|
[6bbeacd4] | 1126 | if event != None: |
---|
[3595309d] | 1127 | ## post state to fit panel |
---|
[e030625] | 1128 | new_event = PageInfoEvent(page = self) |
---|
| 1129 | wx.PostEvent(self.parent, new_event) |
---|
[9466f2d6] | 1130 | #update list of plugins if new plugin is available |
---|
| 1131 | if self.plugin_rbutton.GetValue(): |
---|
| 1132 | temp = self.parent.update_model_list() |
---|
| 1133 | if temp: |
---|
| 1134 | self.model_list_box = temp |
---|
| 1135 | current_val = self.formfactorbox.GetValue() |
---|
| 1136 | pos = self.formfactorbox.GetSelection() |
---|
| 1137 | self._show_combox_helper() |
---|
| 1138 | self.formfactorbox.SetSelection(pos) |
---|
| 1139 | self.formfactorbox.SetValue(current_val) |
---|
[31f9c172] | 1140 | self._onDraw(event=None) |
---|
[0145a25] | 1141 | else: |
---|
| 1142 | self._draw_model() |
---|
[ce92ded] | 1143 | self.SetupScrolling() |
---|
[70468a5] | 1144 | self.Show(True) |
---|
[0b12abb5] | 1145 | |
---|
[dd5949d] | 1146 | def _onparamEnter(self,event): |
---|
| 1147 | """ |
---|
[5062bbf] | 1148 | when enter value on panel redraw model according to changed |
---|
[dd5949d] | 1149 | """ |
---|
[4470b10] | 1150 | if self.model ==None: |
---|
| 1151 | msg="Please select a Model first..." |
---|
| 1152 | wx.MessageBox(msg, 'Info') |
---|
[90a7bbd] | 1153 | #wx.PostEvent(self._manager.parent, StatusEvent(status=\ |
---|
[4470b10] | 1154 | # "Parameters: %s"%msg)) |
---|
| 1155 | return |
---|
| 1156 | |
---|
[51a71a3] | 1157 | #default flag |
---|
[7975f2b] | 1158 | flag = False |
---|
[51a71a3] | 1159 | self.fitrange = True |
---|
| 1160 | #get event object |
---|
[dce84c0] | 1161 | tcrtl = event.GetEventObject() |
---|
| 1162 | |
---|
[66ff250] | 1163 | #wx.PostEvent(self._manager.parent, StatusEvent(status=" \ |
---|
| 1164 | # updating ... ",type="update")) |
---|
[edd166b] | 1165 | #Clear msg if previously shown. |
---|
| 1166 | msg= "" |
---|
| 1167 | wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) |
---|
[c99a6c5] | 1168 | |
---|
[7975f2b] | 1169 | if check_float(tcrtl): |
---|
[2012eae] | 1170 | flag = self._onparamEnter_helper() |
---|
| 1171 | self.set_npts2fit() |
---|
[51a71a3] | 1172 | if self.fitrange: |
---|
| 1173 | temp_smearer = None |
---|
| 1174 | if not self.disable_smearer.GetValue(): |
---|
| 1175 | temp_smearer= self.current_smearer |
---|
[d7b7156] | 1176 | ## set smearing value whether or not |
---|
| 1177 | # the data contain the smearing info |
---|
[51a71a3] | 1178 | if self.slit_smearer.GetValue(): |
---|
| 1179 | flag1 = self.update_slit_smear() |
---|
| 1180 | flag = flag or flag1 |
---|
| 1181 | elif self.pinhole_smearer.GetValue(): |
---|
| 1182 | flag1 = self.update_pinhole_smear() |
---|
| 1183 | flag = flag or flag1 |
---|
[ba1f0b2] | 1184 | elif self.data.__class__.__name__ != "Data2D" and \ |
---|
| 1185 | not self.enable2D: |
---|
[90a7bbd] | 1186 | self._manager.set_smearer(smearer=temp_smearer, |
---|
[ba1f0b2] | 1187 | enable2D=self.enable2D, |
---|
[66ff250] | 1188 | uid=self.uid, |
---|
[d7b7156] | 1189 | qmin= float(self.qmin_x), |
---|
[6bbeacd4] | 1190 | qmax= float(self.qmax_x), |
---|
| 1191 | draw=True) |
---|
[51a71a3] | 1192 | if flag: |
---|
[f72333f] | 1193 | #self.compute_chisqr(smearer= temp_smearer) |
---|
[51a71a3] | 1194 | |
---|
| 1195 | ## new state posted |
---|
| 1196 | if self.state_change: |
---|
| 1197 | #self._undo.Enable(True) |
---|
| 1198 | event = PageInfoEvent(page = self) |
---|
| 1199 | wx.PostEvent(self.parent, event) |
---|
| 1200 | self.state_change= False |
---|
| 1201 | else: |
---|
[d7b7156] | 1202 | # invalid fit range: do nothing here: |
---|
| 1203 | # msg already displayed in validate |
---|
| 1204 | return |
---|
[69bee6d] | 1205 | else: |
---|
[7975f2b] | 1206 | self.save_current_state() |
---|
[69bee6d] | 1207 | msg= "Cannot Plot :Must enter a number!!! " |
---|
| 1208 | wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) |
---|
[7609f1a] | 1209 | |
---|
| 1210 | self.save_current_state() |
---|
| 1211 | return |
---|
| 1212 | |
---|
[e2f7b92] | 1213 | def _onparamRangeEnter(self, event): |
---|
[920a6e5] | 1214 | """ |
---|
[5062bbf] | 1215 | Check validity of value enter in the parameters range field |
---|
[920a6e5] | 1216 | """ |
---|
[6bbeacd4] | 1217 | #if self.check_invalid_panel(): |
---|
| 1218 | # return |
---|
[920a6e5] | 1219 | tcrtl= event.GetEventObject() |
---|
[edd166b] | 1220 | #Clear msg if previously shown. |
---|
| 1221 | msg= "" |
---|
| 1222 | wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) |
---|
| 1223 | # Flag to register when a parameter has changed. |
---|
| 1224 | is_modified = False |
---|
[920a6e5] | 1225 | if tcrtl.GetValue().lstrip().rstrip()!="": |
---|
| 1226 | try: |
---|
| 1227 | value = float(tcrtl.GetValue()) |
---|
| 1228 | tcrtl.SetBackgroundColour(wx.WHITE) |
---|
[edd166b] | 1229 | self._check_value_enter(self.fittable_param ,is_modified) |
---|
| 1230 | self._check_value_enter(self.parameters ,is_modified) |
---|
[920a6e5] | 1231 | except: |
---|
| 1232 | tcrtl.SetBackgroundColour("pink") |
---|
[edd166b] | 1233 | msg= "Model Error:wrong value entered : %s"% sys.exc_value |
---|
| 1234 | wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) |
---|
| 1235 | return |
---|
[920a6e5] | 1236 | else: |
---|
| 1237 | tcrtl.SetBackgroundColour(wx.WHITE) |
---|
[e2f7b92] | 1238 | |
---|
[edd166b] | 1239 | #self._undo.Enable(True) |
---|
| 1240 | self.save_current_state() |
---|
| 1241 | event = PageInfoEvent(page = self) |
---|
| 1242 | wx.PostEvent(self.parent, event) |
---|
| 1243 | self.state_change= False |
---|
[c69b6d5] | 1244 | |
---|
[12eac73] | 1245 | |
---|
| 1246 | def _onQrangeEnter(self, event): |
---|
| 1247 | """ |
---|
[5062bbf] | 1248 | Check validity of value enter in the Q range field |
---|
[12eac73] | 1249 | """ |
---|
[6bbeacd4] | 1250 | #if self.check_invalid_panel(): |
---|
| 1251 | # return |
---|
[12eac73] | 1252 | tcrtl= event.GetEventObject() |
---|
| 1253 | #Clear msg if previously shown. |
---|
| 1254 | msg= "" |
---|
| 1255 | wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) |
---|
| 1256 | # Flag to register when a parameter has changed. |
---|
| 1257 | is_modified = False |
---|
| 1258 | if tcrtl.GetValue().lstrip().rstrip()!="": |
---|
| 1259 | try: |
---|
| 1260 | value = float(tcrtl.GetValue()) |
---|
| 1261 | tcrtl.SetBackgroundColour(wx.WHITE) |
---|
| 1262 | |
---|
| 1263 | # If qmin and qmax have been modified, update qmin and qmax |
---|
[f95301b] | 1264 | if self._validate_qrange( self.qmin, self.qmax): |
---|
| 1265 | tempmin = float(self.qmin.GetValue()) |
---|
[12eac73] | 1266 | if tempmin != self.qmin_x: |
---|
| 1267 | self.qmin_x = tempmin |
---|
| 1268 | tempmax = float(self.qmax.GetValue()) |
---|
| 1269 | if tempmax != self.qmax_x: |
---|
| 1270 | self.qmax_x = tempmax |
---|
| 1271 | else: |
---|
| 1272 | tcrtl.SetBackgroundColour("pink") |
---|
| 1273 | msg= "Model Error:wrong value entered : %s"% sys.exc_value |
---|
| 1274 | wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) |
---|
| 1275 | return |
---|
| 1276 | |
---|
| 1277 | except: |
---|
| 1278 | tcrtl.SetBackgroundColour("pink") |
---|
| 1279 | msg= "Model Error:wrong value entered : %s"% sys.exc_value |
---|
| 1280 | wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) |
---|
| 1281 | return |
---|
| 1282 | #Check if # of points for theory model are valid(>0). |
---|
[51a71a3] | 1283 | # check for 2d |
---|
[ba64348] | 1284 | if self.data is not None: |
---|
[ba1f0b2] | 1285 | if self.data.__class__.__name__ == "Data2D" or \ |
---|
| 1286 | self.enable2D: |
---|
[ba64348] | 1287 | # set mask |
---|
| 1288 | radius= numpy.sqrt( self.data.qx_data*self.data.qx_data + |
---|
| 1289 | self.data.qy_data*self.data.qy_data ) |
---|
| 1290 | index_data = ((self.qmin_x <= radius)& \ |
---|
| 1291 | (radius<= self.qmax_x)) |
---|
| 1292 | index_data = (index_data)&(self.data.mask) |
---|
| 1293 | index_data = (index_data)&(numpy.isfinite(self.data.data)) |
---|
| 1294 | if len(index_data[index_data]) < 10: |
---|
| 1295 | msg = "Cannot Plot :No or too little npts in" |
---|
| 1296 | msg += " that data range!!! " |
---|
[3f36675] | 1297 | wx.PostEvent(self.parent.parent, |
---|
| 1298 | StatusEvent(status=msg)) |
---|
[ba64348] | 1299 | return |
---|
| 1300 | else: |
---|
| 1301 | self.data.mask = index_data |
---|
| 1302 | #self.Npts_fit.SetValue(str(len(self.data.mask))) |
---|
| 1303 | self.set_npts2fit() |
---|
[51a71a3] | 1304 | else: |
---|
[ba64348] | 1305 | index_data = ((self.qmin_x <= self.data.x)& \ |
---|
| 1306 | (self.data.x <= self.qmax_x)) |
---|
| 1307 | self.Npts_fit.SetValue(str(len(self.data.x[index_data]))) |
---|
[0cf97c5] | 1308 | else: |
---|
| 1309 | self.npts_x = self.Npts_total.GetValue() |
---|
| 1310 | self._save_plotting_range() |
---|
| 1311 | |
---|
[12eac73] | 1312 | else: |
---|
| 1313 | tcrtl.SetBackgroundColour("pink") |
---|
| 1314 | msg= "Model Error:wrong value entered!!!" |
---|
| 1315 | wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) |
---|
| 1316 | |
---|
[f72333f] | 1317 | self._draw_model() |
---|
| 1318 | ##update chi2 |
---|
| 1319 | #self.compute_chisqr(smearer= temp_smearer) |
---|
[12eac73] | 1320 | #self._undo.Enable(True) |
---|
| 1321 | self.save_current_state() |
---|
| 1322 | event = PageInfoEvent(page = self) |
---|
| 1323 | wx.PostEvent(self.parent, event) |
---|
| 1324 | self.state_change= False |
---|
[51a71a3] | 1325 | return |
---|
[5062bbf] | 1326 | |
---|
[edd166b] | 1327 | def _clear_Err_on_Fit(self): |
---|
| 1328 | """ |
---|
[5062bbf] | 1329 | hide the error text control shown |
---|
| 1330 | after fitting |
---|
[edd166b] | 1331 | """ |
---|
[ce92ded] | 1332 | if self.is_mac: |
---|
| 1333 | return |
---|
[edd166b] | 1334 | if hasattr(self,"text2_3"): |
---|
| 1335 | self.text2_3.Hide() |
---|
| 1336 | |
---|
| 1337 | if len(self.parameters)>0: |
---|
| 1338 | for item in self.parameters: |
---|
| 1339 | #Skip t ifhe angle parameters if 1D data |
---|
[ba1f0b2] | 1340 | if self.data.__class__.__name__ != "Data2D" and \ |
---|
| 1341 | not self.enable2D: |
---|
[edd166b] | 1342 | if item in self.orientation_params: |
---|
| 1343 | continue |
---|
| 1344 | if item in self.param_toFit: |
---|
| 1345 | continue |
---|
| 1346 | ## hide statictext +/- |
---|
[1dd00f4] | 1347 | if len(item) < 4 : |
---|
| 1348 | continue |
---|
[edd166b] | 1349 | if item[3]!=None and item[3].IsShown(): |
---|
| 1350 | item[3].Hide() |
---|
| 1351 | ## hide textcrtl for error after fit |
---|
| 1352 | if item[4]!=None and item[4].IsShown(): |
---|
| 1353 | item[4].Hide() |
---|
[7975f2b] | 1354 | |
---|
[edd166b] | 1355 | if len(self.fittable_param)>0: |
---|
| 1356 | for item in self.fittable_param: |
---|
| 1357 | #Skip t ifhe angle parameters if 1D data |
---|
[ba1f0b2] | 1358 | if self.data.__class__.__name__ != "Data2D" and \ |
---|
| 1359 | not self.enable2D: |
---|
[edd166b] | 1360 | if item in self.orientation_params: |
---|
| 1361 | continue |
---|
| 1362 | if item in self.param_toFit: |
---|
| 1363 | continue |
---|
[1dd00f4] | 1364 | if len(item) < 4 : |
---|
| 1365 | continue |
---|
[edd166b] | 1366 | ## hide statictext +/- |
---|
| 1367 | if item[3]!=None and item[3].IsShown(): |
---|
| 1368 | item[3].Hide() |
---|
| 1369 | ## hide textcrtl for error after fit |
---|
| 1370 | if item[4]!=None and item[4].IsShown(): |
---|
| 1371 | item[4].Hide() |
---|
| 1372 | return |
---|
[920a6e5] | 1373 | |
---|
[7609f1a] | 1374 | def _get_defult_custom_smear(self): |
---|
| 1375 | """ |
---|
[5062bbf] | 1376 | Get the defult values for custum smearing. |
---|
[7609f1a] | 1377 | """ |
---|
| 1378 | # get the default values |
---|
| 1379 | if self.dxl == None: self.dxl = 0.0 |
---|
| 1380 | if self.dxw == None: self.dxw = "" |
---|
| 1381 | if self.dx_min == None: self.dx_min = SMEAR_SIZE_L |
---|
| 1382 | if self.dx_max == None: self.dx_max = SMEAR_SIZE_H |
---|
| 1383 | |
---|
| 1384 | def _get_smear_info(self): |
---|
| 1385 | """ |
---|
[5062bbf] | 1386 | Get the smear info from data. |
---|
| 1387 | |
---|
| 1388 | :return: self.smear_type, self.dq_l and self.dq_r, |
---|
[d7b7156] | 1389 | respectively the type of the smear, dq_min and |
---|
| 1390 | dq_max for pinhole smear data |
---|
[7609f1a] | 1391 | while dxl and dxw for slit smear |
---|
[5062bbf] | 1392 | |
---|
[7609f1a] | 1393 | """ |
---|
| 1394 | |
---|
| 1395 | # default |
---|
| 1396 | self.smear_type = None |
---|
| 1397 | self.dq_l = None |
---|
| 1398 | self.dq_r = None |
---|
[f72333f] | 1399 | data = self.data |
---|
| 1400 | if self.data is None: |
---|
[7609f1a] | 1401 | return |
---|
[ba1f0b2] | 1402 | elif self.data.__class__.__name__ == "Data2D" or \ |
---|
| 1403 | self.enable2D: |
---|
[f72333f] | 1404 | if data.dqx_data == None or data.dqy_data ==None: |
---|
| 1405 | return |
---|
[d7b7156] | 1406 | elif self.smearer != None and (data.dqx_data.any()!=0) and \ |
---|
| 1407 | (data.dqx_data.any()!=0): |
---|
[f72333f] | 1408 | self.smear_type = "Pinhole2d" |
---|
| 1409 | self.dq_l = format_number(numpy.average(data.dqx_data)) |
---|
| 1410 | self.dq_r = format_number(numpy.average(data.dqy_data)) |
---|
| 1411 | return |
---|
| 1412 | else: |
---|
| 1413 | return |
---|
[7609f1a] | 1414 | # check if it is pinhole smear and get min max if it is. |
---|
| 1415 | if data.dx != None and all(data.dx !=0): |
---|
| 1416 | self.smear_type = "Pinhole" |
---|
[f72333f] | 1417 | self.dq_l = data.dx[0] |
---|
| 1418 | self.dq_r = data.dx[-1] |
---|
[7609f1a] | 1419 | |
---|
| 1420 | # check if it is slit smear and get min max if it is. |
---|
| 1421 | elif data.dxl != None or data.dxw != None: |
---|
| 1422 | self.smear_type = "Slit" |
---|
| 1423 | if data.dxl != None and all(data.dxl !=0): |
---|
| 1424 | self.dq_l = data.dxl[0] |
---|
| 1425 | if data.dxw != None and all(data.dxw !=0): |
---|
[5062bbf] | 1426 | self.dq_r = data.dxw[0] |
---|
[7609f1a] | 1427 | #return self.smear_type,self.dq_l,self.dq_r |
---|
| 1428 | |
---|
| 1429 | def _show_smear_sizer(self): |
---|
| 1430 | """ |
---|
[5062bbf] | 1431 | Show only the sizers depending on smear selection |
---|
[7609f1a] | 1432 | """ |
---|
[f72333f] | 1433 | # smear disabled |
---|
[7609f1a] | 1434 | if self.disable_smearer.GetValue(): |
---|
| 1435 | self.smear_description_none.Show(True) |
---|
[f72333f] | 1436 | # 2Dsmear |
---|
| 1437 | elif self._is_2D(): |
---|
| 1438 | self.smear_description_accuracy_type.Show(True) |
---|
| 1439 | self.smear_accuracy.Show(True) |
---|
| 1440 | self.smear_description_accuracy_type.Show(True) |
---|
| 1441 | self.smear_description_2d.Show(True) |
---|
| 1442 | self.smear_description_2d_x.Show(True) |
---|
| 1443 | self.smear_description_2d_y.Show(True) |
---|
| 1444 | if self.pinhole_smearer.GetValue(): |
---|
| 1445 | self.smear_pinhole_min.Show(True) |
---|
| 1446 | self.smear_pinhole_max.Show(True) |
---|
| 1447 | # smear from data |
---|
[7609f1a] | 1448 | elif self.enable_smearer.GetValue(): |
---|
[f72333f] | 1449 | |
---|
[7609f1a] | 1450 | self.smear_description_dqdata.Show(True) |
---|
| 1451 | if self.smear_type != None: |
---|
| 1452 | self.smear_description_smear_type.Show(True) |
---|
| 1453 | if self.smear_type == 'Slit': |
---|
| 1454 | self.smear_description_slit_height.Show(True) |
---|
[f72333f] | 1455 | self.smear_description_slit_width.Show(True) |
---|
[7609f1a] | 1456 | elif self.smear_type == 'Pinhole': |
---|
| 1457 | self.smear_description_pin_min.Show(True) |
---|
| 1458 | self.smear_description_pin_max.Show(True) |
---|
[f72333f] | 1459 | self.smear_description_smear_type.Show(True) |
---|
| 1460 | self.smear_description_type.Show(True) |
---|
[7609f1a] | 1461 | self.smear_data_left.Show(True) |
---|
| 1462 | self.smear_data_right.Show(True) |
---|
[f72333f] | 1463 | # custom pinhole smear |
---|
[7609f1a] | 1464 | elif self.pinhole_smearer.GetValue(): |
---|
[f72333f] | 1465 | if self.smear_type == 'Pinhole': |
---|
| 1466 | self.smear_message_new_p.Show(True) |
---|
| 1467 | self.smear_description_pin_min.Show(True) |
---|
| 1468 | self.smear_description_pin_max.Show(True) |
---|
| 1469 | |
---|
[7609f1a] | 1470 | self.smear_pinhole_min.Show(True) |
---|
| 1471 | self.smear_pinhole_max.Show(True) |
---|
[f72333f] | 1472 | # custom slit smear |
---|
[7609f1a] | 1473 | elif self.slit_smearer.GetValue(): |
---|
| 1474 | self.smear_message_new_s.Show(True) |
---|
| 1475 | self.smear_description_slit_height.Show(True) |
---|
| 1476 | self.smear_slit_height.Show(True) |
---|
| 1477 | self.smear_description_slit_width.Show(True) |
---|
| 1478 | self.smear_slit_width.Show(True) |
---|
| 1479 | |
---|
| 1480 | def _hide_all_smear_info(self): |
---|
| 1481 | """ |
---|
[5062bbf] | 1482 | Hide all smearing messages in the set_smearer sizer |
---|
[7609f1a] | 1483 | """ |
---|
| 1484 | self.smear_description_none.Hide() |
---|
| 1485 | self.smear_description_dqdata.Hide() |
---|
| 1486 | self.smear_description_type.Hide() |
---|
| 1487 | self.smear_description_smear_type.Hide() |
---|
[f72333f] | 1488 | self.smear_description_accuracy_type.Hide() |
---|
| 1489 | self.smear_description_2d_x.Hide() |
---|
| 1490 | self.smear_description_2d_y.Hide() |
---|
[7609f1a] | 1491 | self.smear_description_2d.Hide() |
---|
[f72333f] | 1492 | |
---|
| 1493 | self.smear_accuracy.Hide() |
---|
[7609f1a] | 1494 | self.smear_data_left.Hide() |
---|
| 1495 | self.smear_data_right.Hide() |
---|
| 1496 | self.smear_description_pin_min.Hide() |
---|
| 1497 | self.smear_pinhole_min.Hide() |
---|
| 1498 | self.smear_description_pin_max.Hide() |
---|
| 1499 | self.smear_pinhole_max.Hide() |
---|
| 1500 | self.smear_description_slit_height.Hide() |
---|
| 1501 | self.smear_slit_height.Hide() |
---|
| 1502 | self.smear_description_slit_width.Hide() |
---|
| 1503 | self.smear_slit_width.Hide() |
---|
| 1504 | self.smear_message_new_p.Hide() |
---|
| 1505 | self.smear_message_new_s.Hide() |
---|
| 1506 | |
---|
[f72333f] | 1507 | def _set_accuracy_list(self): |
---|
| 1508 | """ |
---|
[5062bbf] | 1509 | Set the list of an accuracy in 2D custum smear: Xhigh, High, Med, or Low |
---|
[f72333f] | 1510 | """ |
---|
| 1511 | # list of accuracy choices |
---|
| 1512 | list = ['Low','Med','High','Xhigh'] |
---|
| 1513 | for idx in range(len(list)): |
---|
| 1514 | self.smear_accuracy.Append(list[idx],idx) |
---|
| 1515 | |
---|
[fb59ed9] | 1516 | def _set_fun_box_list(self,fun_box): |
---|
| 1517 | """ |
---|
| 1518 | Set the list of func for multifunctional models |
---|
| 1519 | """ |
---|
| 1520 | # Check if it is multi_functional model |
---|
[8960479] | 1521 | if self.model.__class__ not in self.model_list_box["Multi-Functions"] \ |
---|
| 1522 | and not self.temp_multi_functional: |
---|
[fb59ed9] | 1523 | return None |
---|
| 1524 | # Get the func name list |
---|
| 1525 | list = self.model.fun_list |
---|
| 1526 | if len(list) == 0: |
---|
| 1527 | return None |
---|
| 1528 | # build function (combo)box |
---|
| 1529 | ind = 0 |
---|
| 1530 | while(ind < len(list)): |
---|
| 1531 | for key, val in list.iteritems(): |
---|
| 1532 | if (val == ind): |
---|
| 1533 | fun_box.Append(key,val) |
---|
| 1534 | break |
---|
| 1535 | ind += 1 |
---|
| 1536 | |
---|
[f72333f] | 1537 | def _on_select_accuracy(self,event): |
---|
| 1538 | """ |
---|
[5062bbf] | 1539 | Select an accuracy in 2D custom smear: Xhigh, High, Med, or Low |
---|
[f72333f] | 1540 | """ |
---|
| 1541 | #event.Skip() |
---|
[4fbc93e] | 1542 | # Check if the accuracy is same as before |
---|
| 1543 | #self.smear2d_accuracy = event.GetEventObject().GetValue() |
---|
| 1544 | self.smear2d_accuracy = self.smear_accuracy.GetValue() |
---|
[f72333f] | 1545 | if self.pinhole_smearer.GetValue(): |
---|
| 1546 | self.onPinholeSmear(event=None) |
---|
[4fbc93e] | 1547 | else: |
---|
| 1548 | self.onSmear(event=None) |
---|
| 1549 | if self.current_smearer != None: |
---|
[d7b7156] | 1550 | self.current_smearer.set_accuracy(accuracy = |
---|
| 1551 | self.smear2d_accuracy) |
---|
[f72333f] | 1552 | event.Skip() |
---|
[fb59ed9] | 1553 | |
---|
| 1554 | def _on_fun_box(self,event): |
---|
| 1555 | """ |
---|
| 1556 | Select an func: Erf,Rparabola,LParabola |
---|
| 1557 | """ |
---|
| 1558 | fun_val = None |
---|
| 1559 | fun_box = event.GetEventObject() |
---|
| 1560 | name = fun_box.Name |
---|
| 1561 | value = fun_box.GetValue() |
---|
| 1562 | if self.model.fun_list.has_key(value): |
---|
| 1563 | fun_val = self.model.fun_list[value] |
---|
| 1564 | |
---|
| 1565 | self.model.setParam(name,fun_val) |
---|
| 1566 | # save state |
---|
[d7b7156] | 1567 | self._copy_parameters_state(self.str_parameters, |
---|
| 1568 | self.state.str_parameters) |
---|
[fb59ed9] | 1569 | # update params |
---|
| 1570 | self._update_paramv_on_fit() |
---|
| 1571 | # draw |
---|
| 1572 | self._draw_model() |
---|
| 1573 | self.Refresh() |
---|
| 1574 | # get ready for new event |
---|
| 1575 | event.Skip() |
---|
[4fbc93e] | 1576 | |
---|
[51a71a3] | 1577 | def _onMask(self, event): |
---|
| 1578 | """ |
---|
[5062bbf] | 1579 | Build a panel to allow to edit Mask |
---|
[51a71a3] | 1580 | """ |
---|
| 1581 | |
---|
[d7b7156] | 1582 | from sans.guiframe.local_perspectives.plotting.masking \ |
---|
| 1583 | import MaskPanel as MaskDialog |
---|
[51a71a3] | 1584 | |
---|
[25952cd] | 1585 | self.panel = MaskDialog(base=self, data=self.data, id=wx.NewId()) |
---|
[b9d68ff] | 1586 | #self.panel.Bind(wx.EVT_CLOSE, self._draw_masked_model) |
---|
[51a71a3] | 1587 | self.panel.ShowModal() |
---|
| 1588 | #wx.PostEvent(self.parent, event) |
---|
| 1589 | |
---|
[c365765] | 1590 | def _draw_masked_model(self, event): |
---|
[f72333f] | 1591 | """ |
---|
| 1592 | Draw model image w/mask |
---|
| 1593 | """ |
---|
[48bab15] | 1594 | #event.Skip() |
---|
[51a71a3] | 1595 | is_valid_qrange = self._update_paramv_on_fit() |
---|
[247cb58] | 1596 | |
---|
[6d03e00] | 1597 | if is_valid_qrange and self.model != None: |
---|
[c365765] | 1598 | #self.panel.Show(0) |
---|
| 1599 | #self.panel.Destroy() # frame |
---|
| 1600 | self.panel.MakeModal(False) |
---|
| 1601 | event.Skip() |
---|
[247cb58] | 1602 | # try re draw the model plot if it exists |
---|
[2e51013] | 1603 | self._draw_model() |
---|
[51a71a3] | 1604 | self.set_npts2fit() |
---|
[247cb58] | 1605 | elif self.model == None: |
---|
[c365765] | 1606 | #self.panel.Show(0) |
---|
| 1607 | #self.panel.Destroy() # frame |
---|
| 1608 | self.panel.MakeModal(False) |
---|
| 1609 | event.Skip() |
---|
[2e51013] | 1610 | self.set_npts2fit() |
---|
[247cb58] | 1611 | msg= "No model is found on updating MASK in the model plot... " |
---|
| 1612 | wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) |
---|
[51a71a3] | 1613 | else: |
---|
[c365765] | 1614 | event.Skip() |
---|
[247cb58] | 1615 | msg = ' Please consider your Q range, too.' |
---|
[51a71a3] | 1616 | self.panel.ShowMessage(msg) |
---|
[48bab15] | 1617 | |
---|
[882a912] | 1618 | |
---|
[6bbeacd4] | 1619 | def _set_smear(self, data): |
---|
| 1620 | """ |
---|
| 1621 | """ |
---|
| 1622 | if data is None: |
---|
| 1623 | return |
---|
[ba1f0b2] | 1624 | self.smearer = smear_selection(data, self.model) |
---|
[6bbeacd4] | 1625 | self.disable_smearer.SetValue(True) |
---|
| 1626 | if self.smearer == None: |
---|
| 1627 | self.enable_smearer.Disable() |
---|
| 1628 | else: |
---|
| 1629 | self.enable_smearer.Enable() |
---|
[f6aee42] | 1630 | |
---|
| 1631 | def _mac_sleep(self, sec=0.2): |
---|
| 1632 | """ |
---|
| 1633 | Give sleep to MAC |
---|
| 1634 | """ |
---|
| 1635 | if self.is_mac: |
---|
| 1636 | time.sleep(sec) |
---|
| 1637 | |
---|
[a5701e6] | 1638 | def get_view_mode(self): |
---|
| 1639 | """ |
---|
| 1640 | return True if the panel allow 2D or False if 1D |
---|
| 1641 | """ |
---|
| 1642 | return self.enable2D |
---|
| 1643 | |
---|
[4225aed] | 1644 | def compute_data_set_range(self, data): |
---|
| 1645 | """ |
---|
| 1646 | find the range that include all data in the set |
---|
| 1647 | return the minimum and the maximum values |
---|
| 1648 | """ |
---|
| 1649 | if data is not None: |
---|
[67ae937] | 1650 | qmin, qmax, npts = self.compute_data_range(data) |
---|
[4225aed] | 1651 | self.qmin_data_set = min(self.qmin_data_set, qmin) |
---|
| 1652 | self.qmax_data_set = max(self.qmax_data_set, qmax) |
---|
[67ae937] | 1653 | self.npts_data_set += npts |
---|
[4225aed] | 1654 | |
---|
[75daa79] | 1655 | def compute_data_range(self, data): |
---|
| 1656 | """ |
---|
| 1657 | compute the minimum and the maximum range of the data |
---|
| 1658 | return the npts contains in data |
---|
| 1659 | :param data: |
---|
| 1660 | """ |
---|
| 1661 | qmin, qmax, npts = None, None, None |
---|
| 1662 | if data is not None: |
---|
| 1663 | if not hasattr(data,"data"): |
---|
| 1664 | qmin = min(data.x) |
---|
| 1665 | # Maximum value of data |
---|
| 1666 | qmax = max(data.x) |
---|
| 1667 | npts = len(data.x) |
---|
| 1668 | else: |
---|
| 1669 | qmin = 0 |
---|
| 1670 | x = max(math.fabs(data.xmin), math.fabs(data.xmax)) |
---|
| 1671 | y = max(math.fabs(data.ymin), math.fabs(data.ymax)) |
---|
| 1672 | ## Maximum value of data |
---|
| 1673 | qmax = math.sqrt(x*x + y*y) |
---|
| 1674 | npts = len(data.data) |
---|
[4225aed] | 1675 | print "compute single data range", qmin, qmax |
---|
[75daa79] | 1676 | return qmin, qmax, npts |
---|
| 1677 | |
---|
| 1678 | |
---|
[9237df4] | 1679 | def set_data(self, data): |
---|
[882a912] | 1680 | """ |
---|
[5062bbf] | 1681 | reset the current data |
---|
[882a912] | 1682 | """ |
---|
[cc31608] | 1683 | id = None |
---|
| 1684 | group_id = None |
---|
[6bbeacd4] | 1685 | flag = False |
---|
| 1686 | if self.data is None and data is not None: |
---|
| 1687 | flag = True |
---|
[cc31608] | 1688 | if data is not None: |
---|
| 1689 | id = data.id |
---|
| 1690 | group_id = data.group_id |
---|
| 1691 | if self.data is not None: |
---|
| 1692 | flag = (data.id != self.data.id) |
---|
[9237df4] | 1693 | self.data = data |
---|
| 1694 | if self.data is None: |
---|
| 1695 | data_min = "" |
---|
| 1696 | data_max = "" |
---|
| 1697 | data_name = "" |
---|
[982e953] | 1698 | self._set_bookmark_flag(False) |
---|
[2657df9] | 1699 | self._keep.Enable(False) |
---|
[982e953] | 1700 | self._set_save_flag(False) |
---|
[9237df4] | 1701 | else: |
---|
[1258aa3] | 1702 | if self.model != None: |
---|
| 1703 | self._set_bookmark_flag(True) |
---|
[2657df9] | 1704 | self._keep.Enable(True) |
---|
[982e953] | 1705 | self._set_save_flag(True) |
---|
[aad74b3] | 1706 | self._set_preview_flag(True) |
---|
[ba1f0b2] | 1707 | |
---|
[6bbeacd4] | 1708 | self._set_smear(data) |
---|
[7609f1a] | 1709 | # more disables for 2D |
---|
[ba1f0b2] | 1710 | if self.data.__class__.__name__ == "Data2D" or \ |
---|
| 1711 | self.enable2D: |
---|
[7609f1a] | 1712 | self.slit_smearer.Disable() |
---|
[ba1f0b2] | 1713 | self.pinhole_smearer.Enable(True) |
---|
[51a71a3] | 1714 | self.default_mask = copy.deepcopy(self.data.mask) |
---|
[0f8f831] | 1715 | else: |
---|
| 1716 | self.slit_smearer.Enable(True) |
---|
| 1717 | self.pinhole_smearer.Enable(True) |
---|
[e2f0554] | 1718 | |
---|
[ffa69b6] | 1719 | self.formfactorbox.Enable() |
---|
| 1720 | self.structurebox.Enable() |
---|
[9237df4] | 1721 | data_name = self.data.name |
---|
[67ae937] | 1722 | #data_min, data_max, npts = self.compute_data_range(self.data) |
---|
| 1723 | data_min, data_max = self.qmin_data_set, self.qmax_data_set |
---|
| 1724 | npts = self.npts_data_set |
---|
[9237df4] | 1725 | #set maximum range for x in linear scale |
---|
| 1726 | if not hasattr(self.data,"data"): #Display only for 1D data fit |
---|
[19403da] | 1727 | self.btEditMask.Disable() |
---|
| 1728 | self.EditMask_title.Disable() |
---|
[9237df4] | 1729 | else: |
---|
[e2f0554] | 1730 | |
---|
[19403da] | 1731 | self.btEditMask.Enable() |
---|
| 1732 | self.EditMask_title.Enable() |
---|
[75daa79] | 1733 | self.Npts_total.SetValue(str(npts)) |
---|
| 1734 | #default:number of data points selected to fit |
---|
| 1735 | self.Npts_fit.SetValue(str(npts)) |
---|
[e9875db] | 1736 | self.Npts_total.SetEditable(False) |
---|
| 1737 | self.Npts_total.SetBackgroundColour(\ |
---|
| 1738 | self.GetParent().GetBackgroundColour()) |
---|
| 1739 | |
---|
| 1740 | self.Npts_total.Bind(wx.EVT_MOUSE_EVENTS, self._npts_click) |
---|
| 1741 | #self.Npts_total.Disable() |
---|
[9237df4] | 1742 | self.dataSource.SetValue(data_name) |
---|
| 1743 | self.qmin_x = data_min |
---|
| 1744 | self.qmax_x = data_max |
---|
[4efefc6] | 1745 | #self.minimum_q.SetValue(str(data_min)) |
---|
| 1746 | #self.maximum_q.SetValue(str(data_max)) |
---|
[75daa79] | 1747 | if data_min is None: |
---|
| 1748 | data_min = "" |
---|
| 1749 | if data_max is None: |
---|
| 1750 | data_max = "" |
---|
[f95301b] | 1751 | self.qmin.SetValue(str(data_min)) |
---|
[ffa69b6] | 1752 | self.qmax.SetValue(str(data_max)) |
---|
[f95301b] | 1753 | self.qmin.SetBackgroundColour("white") |
---|
[ffa69b6] | 1754 | self.qmax.SetBackgroundColour("white") |
---|
| 1755 | self.state.data = data |
---|
| 1756 | self.state.qmin = self.qmin_x |
---|
| 1757 | self.state.qmax = self.qmax_x |
---|
[ce180bd] | 1758 | |
---|
[6bbeacd4] | 1759 | #update model plot with new data information |
---|
| 1760 | if flag: |
---|
[e2f0554] | 1761 | #set model view button |
---|
| 1762 | if self.data.__class__.__name__ == "Data2D": |
---|
| 1763 | self.enable2D = True |
---|
| 1764 | self.model_view.SetLabel("2D Mode") |
---|
| 1765 | else: |
---|
| 1766 | self.enable2D = False |
---|
| 1767 | self.model_view.SetLabel("1D Mode") |
---|
[fa65e99] | 1768 | |
---|
[e2f0554] | 1769 | self.model_view.Disable() |
---|
[cc31608] | 1770 | |
---|
| 1771 | #replace data plot on combo box selection |
---|
| 1772 | #by removing the previous selected data |
---|
| 1773 | wx.PostEvent(self._manager.parent, NewPlotEvent(action="remove", |
---|
| 1774 | group_id=group_id, id=id)) |
---|
| 1775 | #plot the current selected data |
---|
| 1776 | wx.PostEvent(self._manager.parent, NewPlotEvent(plot=self.data, |
---|
[3f36675] | 1777 | title=str(self.data.title))) |
---|
[cc31608] | 1778 | self._manager.store_data(uid=self.uid, data=data, |
---|
| 1779 | data_list=self.data_list, |
---|
| 1780 | caption=self.window_name) |
---|
[6bbeacd4] | 1781 | self._draw_model() |
---|
[515bf4f] | 1782 | |
---|
[e9875db] | 1783 | def _npts_click(self, event): |
---|
| 1784 | """ |
---|
| 1785 | Prevent further handling of the mouse event on Npts_total |
---|
| 1786 | by not calling Skip(). |
---|
| 1787 | """ |
---|
| 1788 | pass |
---|
| 1789 | |
---|
[240b9966] | 1790 | def reset_page(self, state,first=False): |
---|
[a074145] | 1791 | """ |
---|
[5062bbf] | 1792 | reset the state |
---|
[a074145] | 1793 | """ |
---|
| 1794 | self.reset_page_helper(state) |
---|
[0b12abb5] | 1795 | #import sans.guiframe.gui_manager |
---|
| 1796 | #evt = ModelEventbox(model=state.model) |
---|
| 1797 | #wx.PostEvent(self.event_owner, evt) |
---|
[edd166b] | 1798 | |
---|
| 1799 | if self.engine_type != None: |
---|
[90a7bbd] | 1800 | self._manager._on_change_engine(engine=self.engine_type) |
---|
[7975f2b] | 1801 | |
---|
[edd166b] | 1802 | self.select_param(event = None) |
---|
| 1803 | #Save state_fit |
---|
[c985bef] | 1804 | self.save_current_state_fit() |
---|
[7975f2b] | 1805 | self._lay_out() |
---|
[c985bef] | 1806 | self.Refresh() |
---|
[edd166b] | 1807 | |
---|
[2140e68] | 1808 | def get_range(self): |
---|
| 1809 | """ |
---|
[5062bbf] | 1810 | return the fitting range |
---|
[2140e68] | 1811 | """ |
---|
[c9a4377] | 1812 | return float(self.qmin_x) , float(self.qmax_x) |
---|
[7975f2b] | 1813 | |
---|
| 1814 | def get_npts2fit(self): |
---|
| 1815 | """ |
---|
[5062bbf] | 1816 | return numbers of data points within qrange |
---|
| 1817 | |
---|
| 1818 | :Note: This is for Park where chi2 is not normalized by Npts of fit |
---|
| 1819 | |
---|
[7975f2b] | 1820 | """ |
---|
[6bbeacd4] | 1821 | if self.data is None: |
---|
| 1822 | return |
---|
[7975f2b] | 1823 | npts2fit = 0 |
---|
| 1824 | qmin,qmax = self.get_range() |
---|
[ba1f0b2] | 1825 | if self.data.__class__.__name__ == "Data2D" or \ |
---|
| 1826 | self.enable2D: |
---|
[d7b7156] | 1827 | radius= numpy.sqrt( self.data.qx_data*self.data.qx_data + |
---|
| 1828 | self.data.qy_data*self.data.qy_data ) |
---|
[51a71a3] | 1829 | index_data = (self.qmin_x <= radius)&(radius<= self.qmax_x) |
---|
| 1830 | index_data= (index_data)&(self.data.mask) |
---|
| 1831 | index_data = (index_data)&(numpy.isfinite(self.data.data)) |
---|
| 1832 | npts2fit = len(self.data.data[index_data]) |
---|
[7975f2b] | 1833 | else: |
---|
| 1834 | for qx in self.data.x: |
---|
| 1835 | if qx >= qmin and qx <= qmax: |
---|
| 1836 | npts2fit += 1 |
---|
| 1837 | return npts2fit |
---|
| 1838 | |
---|
[51a71a3] | 1839 | def set_npts2fit(self): |
---|
| 1840 | """ |
---|
[5062bbf] | 1841 | setValue Npts for fitting |
---|
[51a71a3] | 1842 | """ |
---|
| 1843 | self.Npts_fit.SetValue(str(self.get_npts2fit())) |
---|
| 1844 | |
---|
[c69b6d5] | 1845 | def get_chi2(self): |
---|
| 1846 | """ |
---|
[5062bbf] | 1847 | return the current chi2 |
---|
[c69b6d5] | 1848 | """ |
---|
[2012eae] | 1849 | return self.tcChi.GetValue() |
---|
[c77d859] | 1850 | |
---|
| 1851 | def get_param_list(self): |
---|
| 1852 | """ |
---|
[5062bbf] | 1853 | :return self.param_toFit: list containing references to TextCtrl |
---|
[c77d859] | 1854 | checked.Theses TextCtrl will allow reference to parameters to fit. |
---|
[5062bbf] | 1855 | |
---|
| 1856 | :raise: if return an empty list of parameter fit will nnote work |
---|
[c77d859] | 1857 | properly so raise ValueError,"missing parameter to fit" |
---|
| 1858 | """ |
---|
| 1859 | if self.param_toFit !=[]: |
---|
| 1860 | return self.param_toFit |
---|
| 1861 | else: |
---|
[ba1f0b2] | 1862 | msg = "missing parameters to fit" |
---|
| 1863 | wx.MessageBox(msg, 'warning') |
---|
| 1864 | return False |
---|
| 1865 | #raise ValueError,"missing parameters to fit" |
---|
[c77d859] | 1866 | |
---|
[2296316] | 1867 | def onsetValues(self, chisqr, p_name, out, cov): |
---|
[c77d859] | 1868 | """ |
---|
[5062bbf] | 1869 | Build the panel from the fit result |
---|
| 1870 | |
---|
| 1871 | :param chisqr: Value of the goodness of fit metric |
---|
| 1872 | :param p_name: the name of parameters |
---|
| 1873 | :param out: list of parameter with the best value found during fitting |
---|
| 1874 | :param cov: Covariance matrix |
---|
| 1875 | |
---|
[c77d859] | 1876 | """ |
---|
[edd166b] | 1877 | if out == None or not numpy.isfinite(chisqr): |
---|
| 1878 | raise ValueError,"Fit error occured..." |
---|
| 1879 | |
---|
| 1880 | is_modified = False |
---|
[bd0a098e] | 1881 | has_error = False |
---|
| 1882 | dispersity = '' |
---|
[7975f2b] | 1883 | |
---|
| 1884 | #Hide textctrl boxes of errors. |
---|
[edd166b] | 1885 | self._clear_Err_on_Fit() |
---|
[7975f2b] | 1886 | |
---|
| 1887 | #Check if chi2 is finite |
---|
[2296316] | 1888 | if chisqr != None and numpy.isfinite(chisqr): |
---|
[e575db9] | 1889 | #format chi2 |
---|
[7609f1a] | 1890 | if self.engine_type == "park": |
---|
[e575db9] | 1891 | npt_fit = float(self.get_npts2fit()) |
---|
[7609f1a] | 1892 | if npt_fit > 0: |
---|
| 1893 | chisqr =chisqr/npt_fit |
---|
[2296316] | 1894 | chi2 = format_number(chisqr, True) |
---|
[2012eae] | 1895 | self.tcChi.SetValue(chi2) |
---|
[7975f2b] | 1896 | self.tcChi.Refresh() |
---|
| 1897 | else: |
---|
[2012eae] | 1898 | self.tcChi.SetValue("-") |
---|
[c13b8cc] | 1899 | |
---|
[edd166b] | 1900 | #Hide error title |
---|
[ce92ded] | 1901 | if self.text2_3.IsShown() and not self.is_mac: |
---|
| 1902 | self.text2_3.Hide() |
---|
[edd166b] | 1903 | |
---|
[e473e4f5] | 1904 | try: |
---|
[2296316] | 1905 | if self.enable_disp.GetValue(): |
---|
| 1906 | if hasattr(self,"text_disp_1" ): |
---|
[ce92ded] | 1907 | if self.text_disp_1 != None and not self.is_mac: |
---|
[2296316] | 1908 | self.text_disp_1.Hide() |
---|
[e473e4f5] | 1909 | except: |
---|
[bd0a098e] | 1910 | dispersity = None |
---|
[e473e4f5] | 1911 | pass |
---|
[c77d859] | 1912 | #set the panel when fit result are float not list |
---|
[c99a6c5] | 1913 | if out.__class__== numpy.float64: |
---|
[2296316] | 1914 | self.param_toFit[0][2].SetValue(format_number(out, True)) |
---|
[0a518e4c] | 1915 | |
---|
[ce92ded] | 1916 | if self.param_toFit[0][4].IsShown and not self.is_mac: |
---|
[c69b6d5] | 1917 | self.param_toFit[0][4].Hide() |
---|
[c77d859] | 1918 | if cov !=None : |
---|
| 1919 | self.text2_3.Show(True) |
---|
[e473e4f5] | 1920 | try: |
---|
[2296316] | 1921 | if self.enable_disp.GetValue(): |
---|
| 1922 | if hasattr(self,"text_disp_1" ): |
---|
| 1923 | if self.text_disp_1 !=None: |
---|
| 1924 | self.text_disp_1.Show(True) |
---|
[e473e4f5] | 1925 | except: |
---|
| 1926 | pass |
---|
[c99a6c5] | 1927 | |
---|
[ad6dd4c] | 1928 | if cov[0]==None or not numpy.isfinite(cov[0]): |
---|
[ce92ded] | 1929 | if self.param_toFit[0][3].IsShown and not self.is_mac: |
---|
[c69b6d5] | 1930 | self.param_toFit[0][3].Hide() |
---|
[7975f2b] | 1931 | else: |
---|
| 1932 | self.param_toFit[0][3].Show(True) |
---|
[69bee6d] | 1933 | self.param_toFit[0][4].Show(True) |
---|
[2296316] | 1934 | self.param_toFit[0][4].SetValue(format_number(cov[0], True)) |
---|
[ffb838f] | 1935 | has_error = True |
---|
[c77d859] | 1936 | else: |
---|
[edd166b] | 1937 | |
---|
[c69b6d5] | 1938 | i = 0 |
---|
[c77d859] | 1939 | #Set the panel when fit result are list |
---|
[ce92ded] | 1940 | for item in self.param_toFit: |
---|
[f56bf29] | 1941 | if len(item)>5 and item != None: |
---|
[edd166b] | 1942 | ## reset error value to initial state |
---|
[f56bf29] | 1943 | if not self.is_mac: |
---|
| 1944 | item[3].Hide() |
---|
| 1945 | item[4].Hide() |
---|
[d3fe885] | 1946 | |
---|
[edd166b] | 1947 | for ind in range(len(out)): |
---|
| 1948 | |
---|
[ce92ded] | 1949 | if item[1] == p_name[ind]: |
---|
[edd166b] | 1950 | break |
---|
[7975f2b] | 1951 | if len(out)<=len(self.param_toFit) and out[ind] !=None: |
---|
[ce92ded] | 1952 | val_out = format_number(out[ind], True) |
---|
| 1953 | item[2].SetValue(val_out) |
---|
[c4d723b] | 1954 | |
---|
[c99a6c5] | 1955 | |
---|
[7975f2b] | 1956 | if(cov !=None): |
---|
[edd166b] | 1957 | |
---|
| 1958 | try: |
---|
[7975f2b] | 1959 | if dispersity !=None: |
---|
[2296316] | 1960 | if self.enable_disp.GetValue(): |
---|
[7975f2b] | 1961 | if hasattr(self,"text_disp_1" ): |
---|
| 1962 | if self.text_disp_1!=None: |
---|
[ce92ded] | 1963 | if not self.text_disp_1.IsShown()\ |
---|
| 1964 | and not self.is_mac: |
---|
[7975f2b] | 1965 | self.text_disp_1.Show(True) |
---|
[edd166b] | 1966 | except: |
---|
| 1967 | pass |
---|
| 1968 | |
---|
[7975f2b] | 1969 | if cov[ind]!=None : |
---|
| 1970 | if numpy.isfinite(float(cov[ind])): |
---|
[2296316] | 1971 | val_err = format_number(cov[ind], True) |
---|
[ce92ded] | 1972 | if not self.is_mac: |
---|
| 1973 | item[3].Show(True) |
---|
| 1974 | item[4].Show(True) |
---|
| 1975 | item[4].SetValue(val_err) |
---|
[c4d723b] | 1976 | |
---|
[7975f2b] | 1977 | has_error = True |
---|
[e575db9] | 1978 | i += 1 |
---|
[c99a6c5] | 1979 | #Show error title when any errors displayed |
---|
[b421b1a] | 1980 | if has_error: |
---|
[c99a6c5] | 1981 | if not self.text2_3.IsShown(): |
---|
[86ab3f2] | 1982 | self.text2_3.Show(True) |
---|
[7975f2b] | 1983 | ## save current state |
---|
| 1984 | self.save_current_state() |
---|
[c4d723b] | 1985 | |
---|
[cdb042d] | 1986 | #self._lay_out() |
---|
[3821f64] | 1987 | if not self.is_mac: |
---|
| 1988 | self.Layout() |
---|
| 1989 | self.Refresh() |
---|
[f6aee42] | 1990 | self._mac_sleep(0.1) |
---|
[37290c4] | 1991 | #plot model ( when drawing, do not update chisqr value again) |
---|
[bd02c72] | 1992 | self._draw_model(update_chisqr=False) |
---|
[7975f2b] | 1993 | #PostStatusEvent |
---|
[12cd4ec] | 1994 | #msg = "Fit completed!dddd " |
---|
| 1995 | #wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) |
---|
[c69b6d5] | 1996 | |
---|
[7609f1a] | 1997 | def onPinholeSmear(self, event): |
---|
| 1998 | """ |
---|
[5062bbf] | 1999 | Create a custom pinhole smear object that will change the way residuals |
---|
| 2000 | are compute when fitting |
---|
| 2001 | |
---|
| 2002 | :Note: accuracy is given by strings'High','Med', 'Low' FOR 2d, |
---|
| 2003 | None for 1D |
---|
| 2004 | |
---|
[7609f1a] | 2005 | """ |
---|
| 2006 | |
---|
[6bbeacd4] | 2007 | #if self.check_invalid_panel(): |
---|
| 2008 | # return |
---|
[7609f1a] | 2009 | if self.model ==None: |
---|
[4470b10] | 2010 | self.disable_smearer.SetValue(True) |
---|
| 2011 | msg="Please select a Model first..." |
---|
| 2012 | wx.MessageBox(msg, 'Info') |
---|
[90a7bbd] | 2013 | wx.PostEvent(self._manager.parent, StatusEvent(status=\ |
---|
[7609f1a] | 2014 | "Smear: %s"%msg)) |
---|
| 2015 | return |
---|
[4470b10] | 2016 | |
---|
[2d409fa] | 2017 | # Need update param values |
---|
[f72333f] | 2018 | self._update_paramv_on_fit() |
---|
| 2019 | |
---|
[7609f1a] | 2020 | # msg default |
---|
| 2021 | msg = None |
---|
| 2022 | if event != None: |
---|
| 2023 | tcrtl= event.GetEventObject() |
---|
| 2024 | # event case of radio button |
---|
| 2025 | if tcrtl.GetValue()== True: |
---|
| 2026 | self.dx_min = 0.0 |
---|
| 2027 | self.dx_max = 0.0 |
---|
| 2028 | is_new_pinhole = True |
---|
| 2029 | else: |
---|
| 2030 | is_new_pinhole = self._is_changed_pinhole() |
---|
[d493f66] | 2031 | else: |
---|
[1da28b8] | 2032 | is_new_pinhole = True |
---|
[7609f1a] | 2033 | # if any value is changed |
---|
| 2034 | if is_new_pinhole: |
---|
| 2035 | msg = self._set_pinhole_smear() |
---|
| 2036 | # hide all silt sizer |
---|
| 2037 | self._hide_all_smear_info() |
---|
[f72333f] | 2038 | |
---|
[7609f1a] | 2039 | ##Calculate chi2 |
---|
[f72333f] | 2040 | temp_smearer = self.current_smearer |
---|
| 2041 | #self.compute_chisqr(smearer= temp_smearer) |
---|
| 2042 | |
---|
[7609f1a] | 2043 | # show relevant slit sizers |
---|
| 2044 | self._show_smear_sizer() |
---|
[f72333f] | 2045 | |
---|
[7609f1a] | 2046 | self.sizer_set_smearer.Layout() |
---|
| 2047 | self.Layout() |
---|
| 2048 | |
---|
| 2049 | if event != None: |
---|
| 2050 | event.Skip() |
---|
| 2051 | #self._undo.Enable(True) |
---|
| 2052 | self.save_current_state() |
---|
| 2053 | event = PageInfoEvent(page = self) |
---|
| 2054 | wx.PostEvent(self.parent, event) |
---|
| 2055 | |
---|
| 2056 | def _is_changed_pinhole(self): |
---|
| 2057 | """ |
---|
[5062bbf] | 2058 | check if any of pinhole smear is changed |
---|
| 2059 | |
---|
| 2060 | :return: True or False |
---|
| 2061 | |
---|
[7609f1a] | 2062 | """ |
---|
| 2063 | # get the values |
---|
| 2064 | pin_min = self.smear_pinhole_min.GetValue() |
---|
| 2065 | pin_max = self.smear_pinhole_max.GetValue() |
---|
| 2066 | |
---|
| 2067 | # Check changes in slit width |
---|
| 2068 | try: |
---|
| 2069 | dx_min = float(pin_min) |
---|
| 2070 | except: |
---|
| 2071 | return True |
---|
| 2072 | if self.dx_min != dx_min: |
---|
| 2073 | return True |
---|
| 2074 | |
---|
| 2075 | # Check changes in slit heigth |
---|
| 2076 | try: |
---|
| 2077 | dx_max = float(pin_max) |
---|
| 2078 | except: |
---|
| 2079 | return True |
---|
| 2080 | if self.dx_max != dx_max: |
---|
| 2081 | return True |
---|
| 2082 | return False |
---|
| 2083 | |
---|
| 2084 | def _set_pinhole_smear(self): |
---|
| 2085 | """ |
---|
[5062bbf] | 2086 | Set custom pinhole smear |
---|
| 2087 | |
---|
| 2088 | :return: msg |
---|
| 2089 | |
---|
[7609f1a] | 2090 | """ |
---|
| 2091 | # copy data |
---|
| 2092 | data = copy.deepcopy(self.data) |
---|
[f72333f] | 2093 | if self._is_2D(): |
---|
| 2094 | self.smear_type = 'Pinhole2d' |
---|
| 2095 | len_data = len(data.data) |
---|
| 2096 | data.dqx_data = numpy.zeros(len_data) |
---|
| 2097 | data.dqy_data = numpy.zeros(len_data) |
---|
| 2098 | else: |
---|
| 2099 | self.smear_type = 'Pinhole' |
---|
| 2100 | len_data = len(data.x) |
---|
| 2101 | data.dx = numpy.zeros(len_data) |
---|
| 2102 | data.dxl = None |
---|
| 2103 | data.dxw = None |
---|
[7609f1a] | 2104 | msg = None |
---|
| 2105 | |
---|
| 2106 | get_pin_min = self.smear_pinhole_min |
---|
| 2107 | get_pin_max = self.smear_pinhole_max |
---|
| 2108 | |
---|
[f72333f] | 2109 | if not check_float(get_pin_min): |
---|
| 2110 | get_pin_min.SetBackgroundColour("pink") |
---|
| 2111 | msg= "Model Error:wrong value entered!!!" |
---|
| 2112 | elif not check_float(get_pin_max ): |
---|
| 2113 | get_pin_max.SetBackgroundColour("pink") |
---|
| 2114 | msg= "Model Error:wrong value entered!!!" |
---|
| 2115 | else: |
---|
[7609f1a] | 2116 | if len_data < 2: len_data = 2 |
---|
| 2117 | self.dx_min = float(get_pin_min.GetValue()) |
---|
| 2118 | self.dx_max = float(get_pin_max.GetValue()) |
---|
[f72333f] | 2119 | if self.dx_min < 0: |
---|
| 2120 | get_pin_min.SetBackgroundColour("pink") |
---|
| 2121 | msg= "Model Error:This value can not be negative!!!" |
---|
| 2122 | elif self.dx_max <0: |
---|
| 2123 | get_pin_max.SetBackgroundColour("pink") |
---|
| 2124 | msg= "Model Error:This value can not be negative!!!" |
---|
| 2125 | elif self.dx_min != None and self.dx_max != None: |
---|
| 2126 | if self._is_2D(): |
---|
| 2127 | data.dqx_data[data.dqx_data==0] = self.dx_min |
---|
| 2128 | data.dqy_data[data.dqy_data==0] = self.dx_max |
---|
| 2129 | elif self.dx_min == self.dx_max: |
---|
[7609f1a] | 2130 | data.dx[data.dx==0] = self.dx_min |
---|
| 2131 | else: |
---|
[f72333f] | 2132 | step = (self.dx_max - self.dx_min)/(len_data-1) |
---|
[d7b7156] | 2133 | data.dx = numpy.arange(self.dx_min,self.dx_max+step/1.1, |
---|
| 2134 | step) |
---|
[7609f1a] | 2135 | elif self.dx_min != None: |
---|
[f72333f] | 2136 | if self._is_2D(): data.dqx_data[data.dqx_data==0] = self.dx_min |
---|
| 2137 | else: data.dx[data.dx==0] = self.dx_min |
---|
[7609f1a] | 2138 | elif self.dx_max != None: |
---|
[f72333f] | 2139 | if self._is_2D(): data.dqy_data[data.dqy_data==0] = self.dx_max |
---|
| 2140 | else: data.dx[data.dx==0] = self.dx_max |
---|
[f867cd9] | 2141 | self.current_smearer = smear_selection(data, self.model) |
---|
[4fbc93e] | 2142 | # 2D need to set accuracy |
---|
| 2143 | if self._is_2D(): |
---|
[d7b7156] | 2144 | self.current_smearer.set_accuracy(accuracy = \ |
---|
| 2145 | self.smear2d_accuracy) |
---|
[7609f1a] | 2146 | |
---|
[f72333f] | 2147 | if msg != None: |
---|
[90a7bbd] | 2148 | wx.PostEvent(self._manager.parent, StatusEvent(status = msg )) |
---|
[f72333f] | 2149 | else: |
---|
| 2150 | get_pin_min.SetBackgroundColour("white") |
---|
| 2151 | get_pin_max.SetBackgroundColour("white") |
---|
[7609f1a] | 2152 | ## set smearing value whether or not the data contain the smearing info |
---|
[6bbeacd4] | 2153 | self._manager.set_smearer(smearer=self.current_smearer, |
---|
[ba1f0b2] | 2154 | enable2D=self.enable2D, |
---|
[6bbeacd4] | 2155 | qmin=float(self.qmin_x), |
---|
| 2156 | qmax= float(self.qmax_x), |
---|
[b29e47e] | 2157 | uid=self.uid) |
---|
[7609f1a] | 2158 | return msg |
---|
| 2159 | |
---|
| 2160 | def update_pinhole_smear(self): |
---|
| 2161 | """ |
---|
[5062bbf] | 2162 | called by kill_focus on pinhole TextCntrl |
---|
| 2163 | to update the changes |
---|
| 2164 | |
---|
| 2165 | :return: False when wrong value was entered |
---|
| 2166 | |
---|
[7609f1a] | 2167 | """ |
---|
| 2168 | # msg default |
---|
| 2169 | msg = None |
---|
| 2170 | # check if any value is changed |
---|
| 2171 | if self._is_changed_pinhole(): |
---|
| 2172 | msg = self._set_pinhole_smear() |
---|
| 2173 | #self._undo.Enable(True) |
---|
| 2174 | self.save_current_state() |
---|
| 2175 | |
---|
| 2176 | if msg != None: |
---|
| 2177 | return False |
---|
| 2178 | else: |
---|
| 2179 | return True |
---|
| 2180 | |
---|
| 2181 | def onSlitSmear(self, event): |
---|
| 2182 | """ |
---|
[5062bbf] | 2183 | Create a custom slit smear object that will change the way residuals |
---|
| 2184 | are compute when fitting |
---|
[7609f1a] | 2185 | """ |
---|
[4470b10] | 2186 | |
---|
[6bbeacd4] | 2187 | #if self.check_invalid_panel(): |
---|
| 2188 | # return |
---|
[4470b10] | 2189 | |
---|
[7609f1a] | 2190 | if self.model ==None: |
---|
[4470b10] | 2191 | self.disable_smearer.SetValue(True) |
---|
| 2192 | |
---|
| 2193 | msg="Please select a Model first..." |
---|
| 2194 | wx.MessageBox(msg, 'Info') |
---|
[90a7bbd] | 2195 | wx.PostEvent(self._manager.parent, StatusEvent(status=\ |
---|
[7609f1a] | 2196 | "Smear: %s"%msg)) |
---|
| 2197 | return |
---|
[4470b10] | 2198 | |
---|
[2d409fa] | 2199 | # Need update param values |
---|
| 2200 | self._update_paramv_on_fit() |
---|
[f72333f] | 2201 | |
---|
[7609f1a] | 2202 | # msg default |
---|
| 2203 | msg = None |
---|
| 2204 | # for event given |
---|
| 2205 | if event != None: |
---|
| 2206 | tcrtl= event.GetEventObject() |
---|
| 2207 | # event case of radio button |
---|
| 2208 | if tcrtl.GetValue(): |
---|
| 2209 | self.dxl = 0.0 |
---|
| 2210 | self.dxw = 0.0 |
---|
| 2211 | is_new_slit = True |
---|
| 2212 | else: |
---|
| 2213 | is_new_slit = self._is_changed_slit() |
---|
[d493f66] | 2214 | else: |
---|
[1da28b8] | 2215 | is_new_slit = True |
---|
[4470b10] | 2216 | |
---|
[7609f1a] | 2217 | # if any value is changed |
---|
| 2218 | if is_new_slit: |
---|
| 2219 | msg = self._set_slit_smear() |
---|
[4470b10] | 2220 | |
---|
[7609f1a] | 2221 | # hide all silt sizer |
---|
| 2222 | self._hide_all_smear_info() |
---|
| 2223 | ##Calculate chi2 |
---|
[f72333f] | 2224 | #self.compute_chisqr(smearer= self.current_smearer) |
---|
[7609f1a] | 2225 | # show relevant slit sizers |
---|
| 2226 | self._show_smear_sizer() |
---|
| 2227 | self.sizer_set_smearer.Layout() |
---|
| 2228 | self.Layout() |
---|
[4470b10] | 2229 | |
---|
[7609f1a] | 2230 | if event != None: |
---|
| 2231 | event.Skip() |
---|
| 2232 | #self._undo.Enable(True) |
---|
| 2233 | self.save_current_state() |
---|
| 2234 | event = PageInfoEvent(page = self) |
---|
| 2235 | wx.PostEvent(self.parent, event) |
---|
| 2236 | if msg != None: |
---|
[90a7bbd] | 2237 | wx.PostEvent(self._manager.parent, StatusEvent(status = msg)) |
---|
[7609f1a] | 2238 | |
---|
| 2239 | def _is_changed_slit(self): |
---|
| 2240 | """ |
---|
[5062bbf] | 2241 | check if any of slit lengths is changed |
---|
| 2242 | |
---|
| 2243 | :return: True or False |
---|
[4470b10] | 2244 | |
---|
[5062bbf] | 2245 | """ |
---|
[7609f1a] | 2246 | # get the values |
---|
| 2247 | width = self.smear_slit_width.GetValue() |
---|
| 2248 | height = self.smear_slit_height.GetValue() |
---|
| 2249 | |
---|
[d7b7156] | 2250 | # check and change the box bg color if it was pink |
---|
| 2251 | # but it should be white now |
---|
[7609f1a] | 2252 | # because this is the case that _set_slit_smear() will not handle |
---|
| 2253 | if height.lstrip().rstrip()=="": |
---|
| 2254 | self.smear_slit_height.SetBackgroundColour(wx.WHITE) |
---|
| 2255 | if width.lstrip().rstrip()=="": |
---|
| 2256 | self.smear_slit_width.SetBackgroundColour(wx.WHITE) |
---|
| 2257 | |
---|
| 2258 | # Check changes in slit width |
---|
| 2259 | if width == "": |
---|
| 2260 | dxw = 0.0 |
---|
| 2261 | else: |
---|
| 2262 | try: |
---|
| 2263 | dxw = float(width) |
---|
| 2264 | except: |
---|
| 2265 | return True |
---|
| 2266 | if self.dxw != dxw: |
---|
| 2267 | return True |
---|
| 2268 | |
---|
| 2269 | # Check changes in slit heigth |
---|
| 2270 | if height == "": |
---|
| 2271 | dxl = 0.0 |
---|
| 2272 | else: |
---|
| 2273 | try: |
---|
| 2274 | dxl = float(height) |
---|
| 2275 | except: |
---|
| 2276 | return True |
---|
| 2277 | if self.dxl != dxl: |
---|
| 2278 | return True |
---|
[4470b10] | 2279 | |
---|
[7609f1a] | 2280 | return False |
---|
| 2281 | |
---|
| 2282 | def _set_slit_smear(self): |
---|
| 2283 | """ |
---|
[5062bbf] | 2284 | Set custom slit smear |
---|
| 2285 | |
---|
| 2286 | :return: message to inform the user about the validity |
---|
| 2287 | of the values entered for slit smear |
---|
[7609f1a] | 2288 | """ |
---|
[ba1f0b2] | 2289 | if self.data.__class__.__name__ == "Data2D" or \ |
---|
| 2290 | self.enable2D: |
---|
[0b12abb5] | 2291 | return |
---|
[7609f1a] | 2292 | temp_smearer = None |
---|
| 2293 | # make sure once more if it is smearer |
---|
| 2294 | data = copy.deepcopy(self.data) |
---|
| 2295 | data_len = len(data.x) |
---|
| 2296 | data.dx = None |
---|
| 2297 | data.dxl = None |
---|
| 2298 | data.dxw = None |
---|
| 2299 | msg = None |
---|
| 2300 | |
---|
| 2301 | try: |
---|
| 2302 | self.dxl = float(self.smear_slit_height.GetValue()) |
---|
| 2303 | data.dxl = self.dxl* numpy.ones(data_len) |
---|
| 2304 | self.smear_slit_height.SetBackgroundColour(wx.WHITE) |
---|
| 2305 | except: |
---|
| 2306 | data.dxl = numpy.zeros(data_len) |
---|
| 2307 | if self.smear_slit_height.GetValue().lstrip().rstrip()!="": |
---|
| 2308 | self.smear_slit_height.SetBackgroundColour("pink") |
---|
| 2309 | msg = "Wrong value entered... " |
---|
| 2310 | else: |
---|
| 2311 | self.smear_slit_height.SetBackgroundColour(wx.WHITE) |
---|
| 2312 | try: |
---|
| 2313 | self.dxw = float(self.smear_slit_width.GetValue()) |
---|
| 2314 | self.smear_slit_width.SetBackgroundColour(wx.WHITE) |
---|
| 2315 | data.dxw = self.dxw* numpy.ones(data_len) |
---|
| 2316 | except: |
---|
| 2317 | data.dxw = numpy.zeros(data_len) |
---|
| 2318 | if self.smear_slit_width.GetValue().lstrip().rstrip()!="": |
---|
| 2319 | self.smear_slit_width.SetBackgroundColour("pink") |
---|
| 2320 | msg = "Wrong Fit value entered... " |
---|
| 2321 | else: |
---|
| 2322 | self.smear_slit_width.SetBackgroundColour(wx.WHITE) |
---|
[4470b10] | 2323 | |
---|
[f867cd9] | 2324 | self.current_smearer = smear_selection(data, self.model) |
---|
[7609f1a] | 2325 | #temp_smearer = self.current_smearer |
---|
| 2326 | ## set smearing value whether or not the data contain the smearing info |
---|
[6bbeacd4] | 2327 | self._manager.set_smearer(smearer=self.current_smearer, |
---|
[ba1f0b2] | 2328 | enable2D=self.enable2D, |
---|
[6bbeacd4] | 2329 | qmin=float(self.qmin_x), |
---|
| 2330 | qmax= float(self.qmax_x), |
---|
[512bbd0] | 2331 | uid=self.uid) |
---|
[7609f1a] | 2332 | return msg |
---|
| 2333 | |
---|
| 2334 | def update_slit_smear(self): |
---|
| 2335 | """ |
---|
[5062bbf] | 2336 | called by kill_focus on pinhole TextCntrl |
---|
| 2337 | to update the changes |
---|
| 2338 | |
---|
| 2339 | :return: False when wrong value was entered |
---|
| 2340 | |
---|
[7609f1a] | 2341 | """ |
---|
| 2342 | # msg default |
---|
| 2343 | msg = None |
---|
| 2344 | # check if any value is changed |
---|
| 2345 | if self._is_changed_slit(): |
---|
| 2346 | msg = self._set_slit_smear() |
---|
| 2347 | #self._undo.Enable(True) |
---|
| 2348 | self.save_current_state() |
---|
| 2349 | |
---|
| 2350 | if msg != None: |
---|
| 2351 | return False |
---|
| 2352 | else: |
---|
| 2353 | return True |
---|
| 2354 | |
---|
[c77d859] | 2355 | def onSmear(self, event): |
---|
| 2356 | """ |
---|
[5062bbf] | 2357 | Create a smear object that will change the way residuals |
---|
| 2358 | are compute when fitting |
---|
[c77d859] | 2359 | """ |
---|
[f72333f] | 2360 | if event != None: |
---|
| 2361 | event.Skip() |
---|
[6bbeacd4] | 2362 | if self.data is None: |
---|
[ffa69b6] | 2363 | return |
---|
[6bbeacd4] | 2364 | |
---|
[64bda1e] | 2365 | if self.model == None: |
---|
[4470b10] | 2366 | self.disable_smearer.SetValue(True) |
---|
| 2367 | msg="Please select a Model first..." |
---|
| 2368 | wx.MessageBox(msg, 'Info') |
---|
[90a7bbd] | 2369 | wx.PostEvent(self._manager.parent, StatusEvent(status=\ |
---|
[2a2af47] | 2370 | "Smear: %s"%msg)) |
---|
| 2371 | return |
---|
[f72333f] | 2372 | |
---|
[2d409fa] | 2373 | # Need update param values |
---|
| 2374 | self._update_paramv_on_fit() |
---|
[6bbeacd4] | 2375 | |
---|
[3370922] | 2376 | temp_smearer = None |
---|
[7609f1a] | 2377 | self._get_smear_info() |
---|
| 2378 | |
---|
| 2379 | #renew smear sizer |
---|
| 2380 | if self.smear_type != None: |
---|
| 2381 | self.smear_description_smear_type.SetValue(str(self.smear_type)) |
---|
| 2382 | self.smear_data_left.SetValue(str(self.dq_l)) |
---|
| 2383 | self.smear_data_right.SetValue(str(self.dq_r)) |
---|
[f72333f] | 2384 | |
---|
[7609f1a] | 2385 | self._hide_all_smear_info() |
---|
| 2386 | |
---|
| 2387 | data = copy.deepcopy(self.data) |
---|
| 2388 | # make sure once more if it is smearer |
---|
[f867cd9] | 2389 | self.current_smearer = smear_selection(data, self.model) |
---|
[f72333f] | 2390 | |
---|
[c77d859] | 2391 | if self.enable_smearer.GetValue(): |
---|
| 2392 | if hasattr(self.data,"dxl"): |
---|
[7609f1a] | 2393 | |
---|
[c77d859] | 2394 | msg= ": Resolution smearing parameters" |
---|
| 2395 | if hasattr(self.data,"dxw"): |
---|
| 2396 | msg= ": Slit smearing parameters" |
---|
[997131a] | 2397 | if self.smearer ==None: |
---|
[90a7bbd] | 2398 | wx.PostEvent(self._manager.parent, StatusEvent(status=\ |
---|
[c77d859] | 2399 | "Data contains no smearing information")) |
---|
| 2400 | else: |
---|
[90a7bbd] | 2401 | wx.PostEvent(self._manager.parent, StatusEvent(status=\ |
---|
[f72333f] | 2402 | "Data contains smearing information")) |
---|
| 2403 | |
---|
| 2404 | #self.smear_description_dqdata.Show(True) |
---|
[7609f1a] | 2405 | self.smear_data_left.Show(True) |
---|
| 2406 | self.smear_data_right.Show(True) |
---|
[f72333f] | 2407 | temp_smearer= self.current_smearer |
---|
[7609f1a] | 2408 | elif self.disable_smearer.GetValue(): |
---|
| 2409 | self.smear_description_none.Show(True) |
---|
| 2410 | |
---|
| 2411 | self._show_smear_sizer() |
---|
[f72333f] | 2412 | |
---|
[7609f1a] | 2413 | self.sizer_set_smearer.Layout() |
---|
| 2414 | self.Layout() |
---|
[fb8daaaf] | 2415 | ## set smearing value whether or not the data contain the smearing info |
---|
[ba1f0b2] | 2416 | self._manager.set_smearer(uid=self.uid, smearer=temp_smearer, |
---|
| 2417 | enable2D=self.enable2D, |
---|
| 2418 | qmin= float(self.qmin_x), |
---|
[6bbeacd4] | 2419 | qmax= float(self.qmax_x), draw=True) |
---|
| 2420 | |
---|
[5582a9f1] | 2421 | self.state.enable_smearer= self.enable_smearer.GetValue() |
---|
| 2422 | self.state.disable_smearer=self.disable_smearer.GetValue() |
---|
[7609f1a] | 2423 | self.state.pinhole_smearer = self.pinhole_smearer.GetValue() |
---|
| 2424 | self.state.slit_smearer = self.slit_smearer.GetValue() |
---|
[f72333f] | 2425 | |
---|
| 2426 | def on_complete_chisqr(self, event): |
---|
| 2427 | """ |
---|
[5062bbf] | 2428 | print result chisqr |
---|
| 2429 | |
---|
| 2430 | :event: activated by fitting/ complete after draw |
---|
| 2431 | |
---|
[f72333f] | 2432 | """ |
---|
| 2433 | try: |
---|
[06aa2eeb] | 2434 | if event == None: |
---|
| 2435 | output= "-" |
---|
| 2436 | elif not numpy.isfinite(event.output): |
---|
[f72333f] | 2437 | output= "-" |
---|
| 2438 | else: |
---|
| 2439 | output = event.output |
---|
[2296316] | 2440 | self.tcChi.SetValue(str(format_number(output, True))) |
---|
[f72333f] | 2441 | |
---|
[3c44c66] | 2442 | self.state.tcChi = self.tcChi.GetValue() |
---|
[f72333f] | 2443 | except: |
---|
| 2444 | pass |
---|
[c77d859] | 2445 | |
---|
[5062bbf] | 2446 | |
---|
[c77d859] | 2447 | def select_all_param(self,event): |
---|
| 2448 | """ |
---|
[5062bbf] | 2449 | set to true or false all checkBox given the main checkbox value cb1 |
---|
[d1e0473] | 2450 | """ |
---|
[c77d859] | 2451 | self.param_toFit=[] |
---|
| 2452 | if self.parameters !=[]: |
---|
[998b6b8] | 2453 | if self.cb1.GetValue(): |
---|
[c77d859] | 2454 | for item in self.parameters: |
---|
[3fef0a8] | 2455 | ## for data2D select all to fit |
---|
[ba1f0b2] | 2456 | if self.data.__class__.__name__== "Data2D" or \ |
---|
| 2457 | self.enable2D: |
---|
[c77d859] | 2458 | item[0].SetValue(True) |
---|
| 2459 | self.param_toFit.append(item ) |
---|
[3fef0a8] | 2460 | else: |
---|
| 2461 | ## for 1D all parameters except orientation |
---|
| 2462 | if not item in self.orientation_params: |
---|
| 2463 | item[0].SetValue(True) |
---|
| 2464 | self.param_toFit.append(item ) |
---|
[b324aa9] | 2465 | #if len(self.fittable_param)>0: |
---|
| 2466 | for item in self.fittable_param: |
---|
[ba1f0b2] | 2467 | if self.data.__class__.__name__== "Data2D" or \ |
---|
| 2468 | self.enable2D: |
---|
[b324aa9] | 2469 | item[0].SetValue(True) |
---|
| 2470 | self.param_toFit.append(item ) |
---|
[2296316] | 2471 | try: |
---|
| 2472 | if len(self.values[item[1]]) > 0: |
---|
| 2473 | item[0].SetValue(False) |
---|
| 2474 | except: |
---|
| 2475 | pass |
---|
| 2476 | |
---|
[b324aa9] | 2477 | else: |
---|
| 2478 | ## for 1D all parameters except orientation |
---|
| 2479 | if not item in self.orientation_params_disp: |
---|
[3fef0a8] | 2480 | item[0].SetValue(True) |
---|
| 2481 | self.param_toFit.append(item ) |
---|
[2296316] | 2482 | try: |
---|
| 2483 | if len(self.values[item[1]]) > 0: |
---|
| 2484 | item[0].SetValue(False) |
---|
| 2485 | except: |
---|
| 2486 | pass |
---|
| 2487 | |
---|
[c77d859] | 2488 | else: |
---|
| 2489 | for item in self.parameters: |
---|
| 2490 | item[0].SetValue(False) |
---|
| 2491 | for item in self.fittable_param: |
---|
| 2492 | item[0].SetValue(False) |
---|
| 2493 | self.param_toFit=[] |
---|
[330573d] | 2494 | |
---|
[52cac46] | 2495 | self.save_current_state_fit() |
---|
[b324aa9] | 2496 | |
---|
[3595309d] | 2497 | if event !=None: |
---|
[3a37fe0] | 2498 | #self._undo.Enable(True) |
---|
[3595309d] | 2499 | ## post state to fit panel |
---|
| 2500 | event = PageInfoEvent(page = self) |
---|
| 2501 | wx.PostEvent(self.parent, event) |
---|
| 2502 | |
---|
[c77d859] | 2503 | def select_param(self,event): |
---|
| 2504 | """ |
---|
[5062bbf] | 2505 | Select TextCtrl checked for fitting purpose and stores them |
---|
| 2506 | in self.param_toFit=[] list |
---|
[c77d859] | 2507 | """ |
---|
| 2508 | self.param_toFit=[] |
---|
| 2509 | for item in self.parameters: |
---|
[edd166b] | 2510 | #Skip t ifhe angle parameters if 1D data |
---|
[ba1f0b2] | 2511 | if self.data.__class__.__name__ != "Data2D" and\ |
---|
| 2512 | not self.enable2D: |
---|
[edd166b] | 2513 | if item in self.orientation_params: |
---|
| 2514 | continue |
---|
[c77d859] | 2515 | #Select parameters to fit for list of primary parameters |
---|
[998b6b8] | 2516 | if item[0].GetValue(): |
---|
[c77d859] | 2517 | if not (item in self.param_toFit): |
---|
| 2518 | self.param_toFit.append(item ) |
---|
| 2519 | else: |
---|
| 2520 | #remove parameters from the fitting list |
---|
| 2521 | if item in self.param_toFit: |
---|
| 2522 | self.param_toFit.remove(item) |
---|
[edd166b] | 2523 | |
---|
[d7b7156] | 2524 | #Select parameters to fit for list of fittable parameters |
---|
| 2525 | # with dispersion |
---|
[c77d859] | 2526 | for item in self.fittable_param: |
---|
[edd166b] | 2527 | #Skip t ifhe angle parameters if 1D data |
---|
[ba1f0b2] | 2528 | if self.data.__class__.__name__ != "Data2D" and\ |
---|
| 2529 | not self.enable2D: |
---|
[edd166b] | 2530 | if item in self.orientation_params: |
---|
| 2531 | continue |
---|
[998b6b8] | 2532 | if item[0].GetValue(): |
---|
[c77d859] | 2533 | if not (item in self.param_toFit): |
---|
| 2534 | self.param_toFit.append(item) |
---|
| 2535 | else: |
---|
| 2536 | #remove parameters from the fitting list |
---|
| 2537 | if item in self.param_toFit: |
---|
[edd166b] | 2538 | self.param_toFit.remove(item) |
---|
| 2539 | |
---|
| 2540 | #Calculate num. of angle parameters |
---|
[ba1f0b2] | 2541 | if self.data.__class__.__name__ == "Data2D" or \ |
---|
| 2542 | self.enable2D: |
---|
[edd166b] | 2543 | len_orient_para = 0 |
---|
| 2544 | else: |
---|
| 2545 | len_orient_para = len(self.orientation_params) #assume even len |
---|
| 2546 | #Total num. of angle parameters |
---|
| 2547 | if len(self.fittable_param) > 0: |
---|
| 2548 | len_orient_para *= 2 |
---|
[c77d859] | 2549 | #Set the value of checkbox that selected every checkbox or not |
---|
[d7b7156] | 2550 | if len(self.parameters)+len(self.fittable_param)-len_orient_para ==\ |
---|
| 2551 | len(self.param_toFit): |
---|
[c77d859] | 2552 | self.cb1.SetValue(True) |
---|
| 2553 | else: |
---|
| 2554 | self.cb1.SetValue(False) |
---|
[52cac46] | 2555 | self.save_current_state_fit() |
---|
[3595309d] | 2556 | if event !=None: |
---|
[3a37fe0] | 2557 | #self._undo.Enable(True) |
---|
[3595309d] | 2558 | ## post state to fit panel |
---|
| 2559 | event = PageInfoEvent(page = self) |
---|
| 2560 | wx.PostEvent(self.parent, event) |
---|
[c77d859] | 2561 | |
---|
[77e23a2] | 2562 | def set_model_param_sizer(self, model): |
---|
[c77d859] | 2563 | """ |
---|
[5062bbf] | 2564 | Build the panel from the model content |
---|
| 2565 | |
---|
| 2566 | :param model: the model selected in combo box for fitting purpose |
---|
| 2567 | |
---|
[c77d859] | 2568 | """ |
---|
| 2569 | self.sizer3.Clear(True) |
---|
| 2570 | self.parameters = [] |
---|
[fb59ed9] | 2571 | self.str_parameters = [] |
---|
[c77d859] | 2572 | self.param_toFit=[] |
---|
| 2573 | self.fittable_param=[] |
---|
| 2574 | self.fixed_param=[] |
---|
[780d095] | 2575 | self.orientation_params=[] |
---|
[60132ef] | 2576 | self.orientation_params_disp=[] |
---|
[c77d859] | 2577 | |
---|
| 2578 | if model ==None: |
---|
| 2579 | self.sizer3.Layout() |
---|
[ce92ded] | 2580 | self.SetupScrolling() |
---|
[c77d859] | 2581 | return |
---|
[707436d] | 2582 | ## the panel is drawn using the current value of the fit engine |
---|
[90a7bbd] | 2583 | if self.engine_type==None and self._manager !=None: |
---|
| 2584 | self.engine_type= self._manager._return_engine_type() |
---|
[c99a6c5] | 2585 | |
---|
[c77d859] | 2586 | box_description= wx.StaticBox(self, -1,str("Model Parameters")) |
---|
| 2587 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
| 2588 | sizer = wx.GridBagSizer(5,5) |
---|
| 2589 | ## save the current model |
---|
| 2590 | self.model = model |
---|
| 2591 | |
---|
| 2592 | keys = self.model.getParamList() |
---|
| 2593 | #list of dispersion paramaters |
---|
| 2594 | self.disp_list=self.model.getDispParamList() |
---|
[b421b1a] | 2595 | |
---|
[db08737] | 2596 | def custom_compare(a,b): |
---|
| 2597 | """ |
---|
| 2598 | Custom compare to order, first by alphabets then second by number. |
---|
| 2599 | """ |
---|
[fb59ed9] | 2600 | # number at the last digit |
---|
[db08737] | 2601 | a_last = a[len(a)-1] |
---|
| 2602 | b_last = b[len(b)-1] |
---|
[fb59ed9] | 2603 | # default |
---|
[db08737] | 2604 | num_a = None |
---|
| 2605 | num_b = None |
---|
[fb59ed9] | 2606 | # split the names |
---|
| 2607 | a2 = a.lower().split('_') |
---|
| 2608 | b2 = b.lower().split('_') |
---|
| 2609 | # check length of a2, b2 |
---|
| 2610 | len_a2 = len(a2) |
---|
| 2611 | len_b2 = len(b2) |
---|
[db08737] | 2612 | # check if it contains a int number(<10) |
---|
| 2613 | try: |
---|
| 2614 | num_a = int(a_last) |
---|
| 2615 | except: pass |
---|
| 2616 | try: |
---|
| 2617 | num_b = int(b_last) |
---|
| 2618 | except: pass |
---|
[fb59ed9] | 2619 | # Put 'scale' near the top; happens |
---|
| 2620 | # when numbered param name exists |
---|
| 2621 | if a == 'scale': |
---|
| 2622 | return -1 |
---|
[db08737] | 2623 | # both have a number |
---|
| 2624 | if num_a != None and num_b != None: |
---|
[fb59ed9] | 2625 | if num_a > num_b: return -1 |
---|
| 2626 | # same number |
---|
[db08737] | 2627 | elif num_a == num_b: |
---|
[fb59ed9] | 2628 | # different last names |
---|
| 2629 | if a2[len_a2-1] != b2[len_b2-1] and num_a != 0: |
---|
| 2630 | return -cmp(a2[len_a2-1], b2[len_b2-1]) |
---|
| 2631 | else: |
---|
| 2632 | return cmp(a, b) |
---|
| 2633 | else: return 1 |
---|
[db08737] | 2634 | # one of them has a number |
---|
[20905a0] | 2635 | elif num_a != None: return 1 |
---|
| 2636 | elif num_b != None: return -1 |
---|
[fb59ed9] | 2637 | # no numbers |
---|
[20905a0] | 2638 | else: return cmp(a.lower(), b.lower()) |
---|
[fb59ed9] | 2639 | |
---|
[20905a0] | 2640 | |
---|
[db08737] | 2641 | keys.sort(custom_compare) |
---|
[c77d859] | 2642 | |
---|
[6dc9ad8] | 2643 | iy = 0 |
---|
[c77d859] | 2644 | ix = 0 |
---|
[2f6c260] | 2645 | select_text = "Select All" |
---|
[b324aa9] | 2646 | self.cb1 = wx.CheckBox(self, -1,str(select_text), (10, 10)) |
---|
[c77d859] | 2647 | wx.EVT_CHECKBOX(self, self.cb1.GetId(), self.select_all_param) |
---|
[2f6c260] | 2648 | self.cb1.SetToolTipString("To check/uncheck all the boxes below.") |
---|
[ecfcef6] | 2649 | self.cb1.SetValue(True) |
---|
[c77d859] | 2650 | |
---|
| 2651 | sizer.Add(self.cb1,(iy, ix),(1,1),\ |
---|
[eda428b] | 2652 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 5) |
---|
[c77d859] | 2653 | ix +=1 |
---|
[f56bf29] | 2654 | self.text2_2 = wx.StaticText(self, -1, 'Value') |
---|
[c77d859] | 2655 | sizer.Add(self.text2_2,(iy, ix),(1,1),\ |
---|
| 2656 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 2657 | ix +=2 |
---|
[f56bf29] | 2658 | self.text2_3 = wx.StaticText(self, -1, 'Error') |
---|
[c77d859] | 2659 | sizer.Add(self.text2_3,(iy, ix),(1,1),\ |
---|
| 2660 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[3821f64] | 2661 | if not self.is_mac: |
---|
| 2662 | self.text2_3.Hide() |
---|
[c77d859] | 2663 | ix +=1 |
---|
| 2664 | self.text2_min = wx.StaticText(self, -1, 'Min') |
---|
| 2665 | sizer.Add(self.text2_min,(iy, ix),(1,1),\ |
---|
| 2666 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[2296316] | 2667 | #self.text2_min.Hide() |
---|
[c77d859] | 2668 | ix +=1 |
---|
| 2669 | self.text2_max = wx.StaticText(self, -1, 'Max') |
---|
| 2670 | sizer.Add(self.text2_max,(iy, ix),(1,1),\ |
---|
| 2671 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[2296316] | 2672 | #self.text2_max.Hide() |
---|
[6fdfc8f] | 2673 | ix += 1 |
---|
| 2674 | self.text2_4 = wx.StaticText(self, -1, '[Units]') |
---|
| 2675 | sizer.Add(self.text2_4,(iy, ix),(1,1),\ |
---|
| 2676 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 2677 | self.text2_4.Hide() |
---|
[b421b1a] | 2678 | |
---|
[c77d859] | 2679 | for item in keys: |
---|
[d7b7156] | 2680 | if not item in self.disp_list and not item in \ |
---|
| 2681 | self.model.orientation_params: |
---|
[b421b1a] | 2682 | |
---|
| 2683 | ##prepare a spot to store errors |
---|
| 2684 | if not self.model.details.has_key(item): |
---|
| 2685 | self.model.details [item] = ["",None,None] |
---|
| 2686 | |
---|
[c77d859] | 2687 | iy += 1 |
---|
| 2688 | ix = 0 |
---|
[8960479] | 2689 | if (self.model.__class__ in \ |
---|
| 2690 | self.model_list_box["Multi-Functions"] or \ |
---|
| 2691 | self.temp_multi_functional)\ |
---|
| 2692 | and (item in self.model.non_fittable): |
---|
[fb59ed9] | 2693 | non_fittable_name = wx.StaticText(self, -1, item ) |
---|
| 2694 | sizer.Add(non_fittable_name,(iy, ix),(1,1),\ |
---|
| 2695 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 21) |
---|
| 2696 | ## add parameter value |
---|
| 2697 | ix += 1 |
---|
| 2698 | value= self.model.getParam(item) |
---|
| 2699 | if len(self.model.fun_list) > 0: |
---|
| 2700 | num = item.split('_')[1][5:7] |
---|
[d7b7156] | 2701 | fun_box = wx.ComboBox(self, -1,size=(100,-1), |
---|
| 2702 | style=wx.CB_READONLY, name = '%s'% item) |
---|
[fb59ed9] | 2703 | self._set_fun_box_list(fun_box) |
---|
| 2704 | fun_box.SetSelection(0) |
---|
[d7b7156] | 2705 | #self.fun_box.SetToolTipString("A function |
---|
| 2706 | # describing the interface") |
---|
[fb59ed9] | 2707 | wx.EVT_COMBOBOX(fun_box,-1, self._on_fun_box) |
---|
| 2708 | else: |
---|
[d7b7156] | 2709 | fun_box = self.ModelTextCtrl(self, -1, |
---|
| 2710 | size=(_BOX_WIDTH,20), |
---|
| 2711 | style=wx.TE_PROCESS_ENTER, name ='%s'% item) |
---|
[fb59ed9] | 2712 | fun_box.SetToolTipString("Hit 'Enter' after typing.") |
---|
[2296316] | 2713 | fun_box.SetValue(format_number(value, True)) |
---|
[fb59ed9] | 2714 | sizer.Add(fun_box, (iy,ix),(1,1), wx.EXPAND) |
---|
[d7b7156] | 2715 | self.str_parameters.append([None,item, fun_box, |
---|
[2296316] | 2716 | None, None, None, |
---|
| 2717 | None, None]) |
---|
[fb59ed9] | 2718 | |
---|
| 2719 | |
---|
[7975f2b] | 2720 | else: |
---|
[fb59ed9] | 2721 | ## add parameters name with checkbox for selecting to fit |
---|
| 2722 | cb = wx.CheckBox(self, -1, item ) |
---|
[2296316] | 2723 | cb.SetToolTipString(" Check mark to fit.") |
---|
[fb59ed9] | 2724 | #cb.SetValue(True) |
---|
| 2725 | wx.EVT_CHECKBOX(self, cb.GetId(), self.select_param) |
---|
[dcf29d7] | 2726 | |
---|
[fb59ed9] | 2727 | sizer.Add( cb,( iy, ix),(1,1), |
---|
| 2728 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 5) |
---|
| 2729 | |
---|
| 2730 | ## add parameter value |
---|
| 2731 | ix += 1 |
---|
| 2732 | value= self.model.getParam(item) |
---|
| 2733 | ctl1 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH,20), |
---|
| 2734 | style=wx.TE_PROCESS_ENTER) |
---|
| 2735 | ctl1.SetToolTipString("Hit 'Enter' after typing.") |
---|
[2296316] | 2736 | ctl1.SetValue(format_number(value, True)) |
---|
[fb59ed9] | 2737 | sizer.Add(ctl1, (iy,ix),(1,1), wx.EXPAND) |
---|
| 2738 | ## text to show error sign |
---|
| 2739 | ix += 1 |
---|
| 2740 | text2=wx.StaticText(self, -1, '+/-') |
---|
| 2741 | sizer.Add(text2,(iy, ix),(1,1),\ |
---|
| 2742 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[ce92ded] | 2743 | if not self.is_mac: |
---|
| 2744 | text2.Hide() |
---|
[fb59ed9] | 2745 | ix += 1 |
---|
[2296316] | 2746 | ctl2 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH/1.2,20), style=0) |
---|
[d7b7156] | 2747 | sizer.Add(ctl2, (iy,ix),(1,1), |
---|
| 2748 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[ce92ded] | 2749 | if not self.is_mac: |
---|
| 2750 | ctl2.Hide() |
---|
[fb59ed9] | 2751 | |
---|
| 2752 | ix += 1 |
---|
[2296316] | 2753 | ctl3 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/1.9,20), |
---|
[d7b7156] | 2754 | style=wx.TE_PROCESS_ENTER, |
---|
| 2755 | text_enter_callback = self._onparamRangeEnter) |
---|
[fb59ed9] | 2756 | |
---|
[d7b7156] | 2757 | sizer.Add(ctl3, (iy,ix),(1,1), |
---|
| 2758 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[fb59ed9] | 2759 | |
---|
| 2760 | ix += 1 |
---|
[2296316] | 2761 | ctl4 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/1.9,20), |
---|
[d7b7156] | 2762 | style=wx.TE_PROCESS_ENTER, |
---|
| 2763 | text_enter_callback = self._onparamRangeEnter) |
---|
| 2764 | sizer.Add(ctl4, (iy,ix),(1,1), |
---|
[2296316] | 2765 | wx.EXPAND|wx.FIXED_MINSIZE, 0) |
---|
[fb59ed9] | 2766 | |
---|
| 2767 | ix +=1 |
---|
| 2768 | # Units |
---|
| 2769 | if self.model.details.has_key(item): |
---|
[d7b7156] | 2770 | units = wx.StaticText(self, -1, |
---|
| 2771 | self.model.details[item][0], style=wx.ALIGN_LEFT) |
---|
[fb59ed9] | 2772 | else: |
---|
| 2773 | units = wx.StaticText(self, -1, "", style=wx.ALIGN_LEFT) |
---|
[d7b7156] | 2774 | sizer.Add(units, (iy,ix),(1,1), |
---|
| 2775 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[fb59ed9] | 2776 | |
---|
| 2777 | ##[cb state, name, value, "+/-", error of fit, min, max , units] |
---|
| 2778 | self.parameters.append([cb,item, ctl1, |
---|
| 2779 | text2,ctl2, ctl3, ctl4,units]) |
---|
| 2780 | |
---|
[c77d859] | 2781 | iy+=1 |
---|
[d7b7156] | 2782 | sizer.Add((10,10),(iy,ix),(1,1), |
---|
| 2783 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
[5af5183] | 2784 | |
---|
[f20767b] | 2785 | # type can be either Guassian or Array |
---|
[5b53a5c] | 2786 | if len(self.model.dispersion.values())>0: |
---|
| 2787 | type= self.model.dispersion.values()[0]["type"] |
---|
| 2788 | else: |
---|
| 2789 | type = "Gaussian" |
---|
[6dc9ad8] | 2790 | |
---|
| 2791 | iy += 1 |
---|
| 2792 | ix = 0 |
---|
| 2793 | #Add tile for orientational angle |
---|
| 2794 | for item in keys: |
---|
| 2795 | if item in self.model.orientation_params: |
---|
| 2796 | orient_angle = wx.StaticText(self, -1, '[For 2D only]:') |
---|
[d7b7156] | 2797 | sizer.Add(orient_angle,(iy, ix),(1,1), |
---|
| 2798 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
[ba1f0b2] | 2799 | if not self.data.__class__.__name__ == "Data2D" and \ |
---|
| 2800 | not self.enable2D: |
---|
[6dc9ad8] | 2801 | orient_angle.Hide() |
---|
| 2802 | else: |
---|
| 2803 | orient_angle.Show(True) |
---|
| 2804 | break |
---|
[5b53a5c] | 2805 | |
---|
[f20767b] | 2806 | #For Gaussian only |
---|
| 2807 | if type.lower() != "array": |
---|
| 2808 | for item in self.model.orientation_params: |
---|
| 2809 | if not item in self.disp_list: |
---|
[c13b8cc] | 2810 | ##prepare a spot to store min max |
---|
| 2811 | if not self.model.details.has_key(item): |
---|
| 2812 | self.model.details [item] = ["",None,None] |
---|
| 2813 | |
---|
[f20767b] | 2814 | iy += 1 |
---|
| 2815 | ix = 0 |
---|
| 2816 | ## add parameters name with checkbox for selecting to fit |
---|
| 2817 | cb = wx.CheckBox(self, -1, item ) |
---|
| 2818 | cb.SetValue(False) |
---|
[2296316] | 2819 | cb.SetToolTipString("Check mark to fit") |
---|
[f20767b] | 2820 | wx.EVT_CHECKBOX(self, cb.GetId(), self.select_param) |
---|
[ba1f0b2] | 2821 | if self.data.__class__.__name__ == "Data2D" or \ |
---|
| 2822 | self.enable2D: |
---|
[6dc9ad8] | 2823 | cb.Show(True) |
---|
[f20767b] | 2824 | else: |
---|
[6dc9ad8] | 2825 | cb.Hide() |
---|
[f20767b] | 2826 | sizer.Add( cb,( iy, ix),(1,1), |
---|
| 2827 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 5) |
---|
| 2828 | |
---|
| 2829 | ## add parameter value |
---|
| 2830 | ix += 1 |
---|
| 2831 | value= self.model.getParam(item) |
---|
[7975f2b] | 2832 | ctl1 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH,20), |
---|
[f20767b] | 2833 | style=wx.TE_PROCESS_ENTER) |
---|
[1a94c36] | 2834 | ctl1.SetToolTipString("Hit 'Enter' after typing.") |
---|
[2296316] | 2835 | ctl1.SetValue(format_number(value, True)) |
---|
[ba1f0b2] | 2836 | if self.data.__class__.__name__ == "Data2D" or \ |
---|
| 2837 | self.enable2D: |
---|
[c5cd3b9] | 2838 | ctl1.Show(True) |
---|
[f20767b] | 2839 | else: |
---|
[c5cd3b9] | 2840 | ctl1.Hide() |
---|
[f20767b] | 2841 | sizer.Add(ctl1, (iy,ix),(1,1), wx.EXPAND) |
---|
| 2842 | ## text to show error sign |
---|
| 2843 | ix += 1 |
---|
| 2844 | text2=wx.StaticText(self, -1, '+/-') |
---|
| 2845 | sizer.Add(text2,(iy, ix),(1,1),\ |
---|
| 2846 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[e792aee] | 2847 | |
---|
| 2848 | text2.Hide() |
---|
[f20767b] | 2849 | ix += 1 |
---|
[2296316] | 2850 | ctl2 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH/1.2,20), style=0) |
---|
[d7b7156] | 2851 | sizer.Add(ctl2, (iy,ix),(1,1), |
---|
| 2852 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[e792aee] | 2853 | |
---|
| 2854 | ctl2.Hide() |
---|
[e2f7b92] | 2855 | |
---|
[c99a6c5] | 2856 | |
---|
[f20767b] | 2857 | ix += 1 |
---|
[2296316] | 2858 | ctl3 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/1.8,20), |
---|
[d7b7156] | 2859 | style=wx.TE_PROCESS_ENTER, |
---|
| 2860 | text_enter_callback = self._onparamRangeEnter) |
---|
[b9405cd] | 2861 | |
---|
[d7b7156] | 2862 | sizer.Add(ctl3, (iy,ix),(1,1), |
---|
| 2863 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[f20767b] | 2864 | ctl3.Hide() |
---|
[b324aa9] | 2865 | |
---|
[f20767b] | 2866 | ix += 1 |
---|
[2296316] | 2867 | ctl4 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/1.8,20), |
---|
[d7b7156] | 2868 | style=wx.TE_PROCESS_ENTER, |
---|
| 2869 | text_enter_callback = self._onparamRangeEnter) |
---|
| 2870 | sizer.Add(ctl4, (iy,ix),(1,1), |
---|
| 2871 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[eacf1d66] | 2872 | |
---|
[f20767b] | 2873 | ctl4.Hide() |
---|
[edd166b] | 2874 | |
---|
[ba1f0b2] | 2875 | if self.data.__class__.__name__ == "Data2D" or \ |
---|
[1180528] | 2876 | self.enable2D: |
---|
| 2877 | if self.is_mac: |
---|
| 2878 | text2.Show(True) |
---|
| 2879 | ctl2.Show(True) |
---|
[f20767b] | 2880 | ctl3.Show(True) |
---|
| 2881 | ctl4.Show(True) |
---|
[c5cd3b9] | 2882 | |
---|
[f20767b] | 2883 | ix +=1 |
---|
| 2884 | # Units |
---|
[7975f2b] | 2885 | if self.model.details.has_key(item): |
---|
[d7b7156] | 2886 | units = wx.StaticText(self, -1, |
---|
| 2887 | self.model.details[item][0], |
---|
| 2888 | style=wx.ALIGN_LEFT) |
---|
[7975f2b] | 2889 | else: |
---|
[f20767b] | 2890 | units = wx.StaticText(self, -1, "", style=wx.ALIGN_LEFT) |
---|
[ba1f0b2] | 2891 | if self.data.__class__.__name__ == "Data2D" or \ |
---|
| 2892 | self.enable2D: |
---|
[6dc9ad8] | 2893 | units.Show(True) |
---|
[c99a6c5] | 2894 | |
---|
[f20767b] | 2895 | else: |
---|
[6dc9ad8] | 2896 | units.Hide() |
---|
[c99a6c5] | 2897 | |
---|
[d7b7156] | 2898 | sizer.Add(units, (iy,ix),(1,1), |
---|
| 2899 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[7975f2b] | 2900 | |
---|
[d7b7156] | 2901 | ##[cb state, name, value, "+/-", error of fit,min,max,units] |
---|
[f20767b] | 2902 | self.parameters.append([cb,item, ctl1, |
---|
| 2903 | text2,ctl2, ctl3, ctl4,units]) |
---|
| 2904 | self.orientation_params.append([cb,item, ctl1, |
---|
| 2905 | text2,ctl2, ctl3, ctl4,units]) |
---|
[780d095] | 2906 | |
---|
| 2907 | iy+=1 |
---|
[c77d859] | 2908 | |
---|
| 2909 | #Display units text on panel |
---|
| 2910 | for item in keys: |
---|
[7975f2b] | 2911 | if self.model.details.has_key(item): |
---|
[c77d859] | 2912 | self.text2_4.Show() |
---|
[b324aa9] | 2913 | #Fill the list of fittable parameters |
---|
| 2914 | self.select_all_param(event=None) |
---|
[7975f2b] | 2915 | |
---|
[52cac46] | 2916 | self.save_current_state_fit() |
---|
[240b9966] | 2917 | boxsizer1.Add(sizer) |
---|
[c77d859] | 2918 | self.sizer3.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10) |
---|
| 2919 | self.sizer3.Layout() |
---|
[330573d] | 2920 | self.Layout() |
---|
[70468a5] | 2921 | #self.Refresh() |
---|
| 2922 | |
---|
[2296316] | 2923 | def on_right_down(self, event): |
---|
| 2924 | """ |
---|
| 2925 | Get key stroke event |
---|
| 2926 | """ |
---|
| 2927 | if self.data == None: |
---|
| 2928 | return |
---|
| 2929 | # Figuring out key combo: Cmd for copy, Alt for paste |
---|
| 2930 | if event.AltDown() and event.ShiftDown(): |
---|
[2c6b224] | 2931 | self._manager.show_ftol_dialog() |
---|
[2296316] | 2932 | flag = True |
---|
[1b1bbf9] | 2933 | elif event.AltDown() or event.ShiftDown(): |
---|
[2296316] | 2934 | flag = False |
---|
[1b1bbf9] | 2935 | else: |
---|
| 2936 | return |
---|
[2296316] | 2937 | # make event free |
---|
| 2938 | event.Skip() |
---|
| 2939 | # messages depending on the flag |
---|
| 2940 | if not flag: |
---|
| 2941 | msg = " Could not open ftol dialog;" |
---|
| 2942 | msg += " Check if the Scipy fit engine is selected in the menubar." |
---|
| 2943 | infor = 'warning' |
---|
| 2944 | # inform msg to wx |
---|
| 2945 | wx.PostEvent( self.parent.parent, |
---|
| 2946 | StatusEvent(status= msg, info=infor)) |
---|
| 2947 | |
---|
| 2948 | |
---|
[8b6f489] | 2949 | def _onModel2D(self, event): |
---|
| 2950 | """ |
---|
| 2951 | toggle view of model from 1D to 2D or 2D from 1D |
---|
| 2952 | """ |
---|
[6371c9c] | 2953 | if self.model_view.GetLabelText() == "1D Mode": |
---|
| 2954 | self.model_view.SetLabel("2D Mode") |
---|
[8b6f489] | 2955 | self.enable2D = True |
---|
[ba1f0b2] | 2956 | |
---|
[8b6f489] | 2957 | else: |
---|
[6371c9c] | 2958 | self.model_view.SetLabel("1D Mode") |
---|
[8b6f489] | 2959 | self.enable2D = False |
---|
[52cac46] | 2960 | |
---|
[ba1f0b2] | 2961 | self.set_model_param_sizer(self.model) |
---|
| 2962 | self._set_sizer_dispersion() |
---|
| 2963 | self._draw_model() |
---|
| 2964 | |
---|
| 2965 | |
---|
| 2966 | self.state.enable2D = copy.deepcopy(self.enable2D) |
---|
| 2967 | |
---|
[7609f1a] | 2968 | class BGTextCtrl(wx.TextCtrl): |
---|
| 2969 | """ |
---|
[5062bbf] | 2970 | Text control used to display outputs. |
---|
| 2971 | No editing allowed. The background is |
---|
| 2972 | grayed out. User can't select text. |
---|
[7609f1a] | 2973 | """ |
---|
| 2974 | def __init__(self, *args, **kwds): |
---|
| 2975 | wx.TextCtrl.__init__(self, *args, **kwds) |
---|
| 2976 | self.SetEditable(False) |
---|
[59b8c74] | 2977 | self.SetBackgroundColour(self.GetParent().parent.GetBackgroundColour()) |
---|
[7609f1a] | 2978 | |
---|
| 2979 | # Bind to mouse event to avoid text highlighting |
---|
| 2980 | # The event will be skipped once the call-back |
---|
| 2981 | # is called. |
---|
| 2982 | self.Bind(wx.EVT_MOUSE_EVENTS, self._click) |
---|
| 2983 | |
---|
| 2984 | def _click(self, event): |
---|
| 2985 | """ |
---|
[5062bbf] | 2986 | Prevent further handling of the mouse event |
---|
| 2987 | by not calling Skip(). |
---|
[7609f1a] | 2988 | """ |
---|
| 2989 | pass |
---|
[5062bbf] | 2990 | |
---|