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