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