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