[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 |
---|
[2f4b430] | 34 | |
---|
[5062bbf] | 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) |
---|
[2f4b430] | 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) |
---|
[2f4b430] | 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) |
---|
[2f4b430] | 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() |
---|
[2f4b430] | 101 | |
---|
[cc31608] | 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() |
---|
[2f4b430] | 110 | |
---|
[cc31608] | 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() |
---|
[2f4b430] | 145 | |
---|
[cc31608] | 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) |
---|
[2f4b430] | 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() |
---|
[2f4b430] | 164 | |
---|
[f72333f] | 165 | def _is_2D(self): |
---|
| 166 | """ |
---|
[5062bbf] | 167 | Check if data_name is Data2D |
---|
[2f4b430] | 168 | |
---|
[5062bbf] | 169 | :return: True or False |
---|
[2f4b430] | 170 | |
---|
[f72333f] | 171 | """ |
---|
[ba1f0b2] | 172 | if self.data.__class__.__name__ == "Data2D" or \ |
---|
| 173 | self.enable2D: |
---|
[f72333f] | 174 | return True |
---|
| 175 | return False |
---|
[2f4b430] | 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 | """ |
---|
[2f4b430] | 182 | |
---|
[66ff250] | 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() |
---|
[2f4b430] | 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 |
---|
[2f4b430] | 198 | |
---|
[51a71a3] | 199 | # Check if data is 2D |
---|
[f32d144] | 200 | if self.data.__class__.__name__ == "Data2D" or \ |
---|
[ba1f0b2] | 201 | self.enable2D: |
---|
[51a71a3] | 202 | is_2Ddata = True |
---|
[2f4b430] | 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]:" |
---|
[2f4b430] | 220 | |
---|
[7609f1a] | 221 | self._get_smear_info() |
---|
[2f4b430] | 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)) |
---|
[2f4b430] | 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) |
---|
[2f4b430] | 270 | |
---|
[0cf97c5] | 271 | sizer_fit = wx.GridSizer(2, 4, 2, 6) |
---|
[2f4b430] | 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.") |
---|
[2f4b430] | 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.") |
---|
[2f4b430] | 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) |
---|
[2f4b430] | 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)) |
---|
[2f4b430] | 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") |
---|
[2f4b430] | 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.") |
---|
[2f4b430] | 376 | |
---|
| 377 | self.points_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
[cb270ad2] | 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) |
---|
[2f4b430] | 382 | |
---|
[cb270ad2] | 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") |
---|
[2f4b430] | 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, |
---|
[2f4b430] | 406 | - 1, smear_message_dqdata, style=wx.ALIGN_LEFT) |
---|
[f32d144] | 407 | self.smear_description_type = wx.StaticText(self, |
---|
[2f4b430] | 408 | - 1, "Type:", style=wx.ALIGN_LEFT) |
---|
[f32d144] | 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) |
---|
[2f4b430] | 437 | |
---|
[f32d144] | 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, |
---|
[2f4b430] | 470 | 0, wx.CENTER, 10) |
---|
[f32d144] | 471 | self.sizer_new_smear.Add(self.smear_description_pin_max, |
---|
[2f4b430] | 472 | 0, wx.CENTER, 10) |
---|
[f32d144] | 473 | self.sizer_new_smear.Add(self.smear_description_slit_width, |
---|
[2f4b430] | 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) |
---|
[2f4b430] | 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) |
---|
[2f4b430] | 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)) |
---|
[2f4b430] | 491 | |
---|
[7609f1a] | 492 | # hide all smear messages and textctrl |
---|
| 493 | self._hide_all_smear_info() |
---|
[2f4b430] | 494 | |
---|
[7609f1a] | 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 |
---|
[2f4b430] | 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 |
---|
[2f4b430] | 519 | |
---|
[6bbeacd4] | 520 | self.sizer5.Clear(True) |
---|
[2f4b430] | 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) |
---|
[2f4b430] | 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)) |
---|
[2f4b430] | 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") |
---|
[2f4b430] | 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)') |
---|
[2f4b430] | 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) |
---|
[2f4b430] | 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 | |
---|
[2f4b430] | 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 |
---|
[2f4b430] | 604 | |
---|
[376916c] | 605 | self._reset_dispersity() |
---|
[2f4b430] | 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) |
---|
[2f4b430] | 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) |
---|
[2f4b430] | 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) |
---|
[2f4b430] | 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(): |
---|
[2f4b430] | 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) |
---|
[2f4b430] | 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) |
---|
[2f4b430] | 726 | |
---|
[f32d144] | 727 | self.sizer4_4.Add(ctl3, (iy, ix), (1, 1), |
---|
| 728 | wx.EXPAND | wx.ADJUST_MINSIZE, 0) |
---|
[2f4b430] | 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) |
---|
[2f4b430] | 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) |
---|
[2f4b430] | 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) |
---|
[2f4b430] | 748 | |
---|
[f32d144] | 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) |
---|
[2f4b430] | 760 | |
---|
[f32d144] | 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]) |
---|
[2f4b430] | 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" |
---|
[2f4b430] | 796 | |
---|
[308fa87] | 797 | if not name1 in self.model.details: |
---|
| 798 | self.model.details[name1] = ["", None, None] |
---|
[2f4b430] | 799 | |
---|
[780d095] | 800 | iy += 1 |
---|
[308fa87] | 801 | for p in self.model.dispersion[item].keys(): |
---|
[2f4b430] | 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 " |
---|
[2f4b430] | 834 | |
---|
[01b6bd0] | 835 | values.SetToolTipString(poly_text) |
---|
[d7b7156] | 836 | first_orient = False |
---|
[6dc9ad8] | 837 | ctl1.Show(True) |
---|
[c99a6c5] | 838 | elif ctl1.IsShown(): |
---|
[6dc9ad8] | 839 | ctl1.Hide() |
---|
[2f4b430] | 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) |
---|
[2f4b430] | 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) |
---|
[2f4b430] | 864 | |
---|
[920a6e5] | 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() |
---|
[2f4b430] | 875 | |
---|
[920a6e5] | 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() |
---|
[2f4b430] | 884 | |
---|
[308fa87] | 885 | if self.data.__class__.__name__ == "Data2D" or \ |
---|
[ba1f0b2] | 886 | self.enable2D: |
---|
[920a6e5] | 887 | ctl3.Show(True) |
---|
[308fa87] | 888 | ctl4.Show(True) |
---|
[2f4b430] | 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) |
---|
[2f4b430] | 896 | |
---|
[308fa87] | 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) |
---|
[2f4b430] | 916 | |
---|
[308fa87] | 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]) |
---|
[2f4b430] | 928 | |
---|
[308fa87] | 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]) |
---|
[2f4b430] | 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() |
---|
[2f4b430] | 951 | |
---|
[308fa87] | 952 | self.state.disp_cb_dict = copy.deepcopy(self.disp_cb_dict) |
---|
[2f4b430] | 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() |
---|
[2f4b430] | 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 |
---|
[2f4b430] | 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 | |
---|
[504dd9f5] | 1005 | if self.data is None: |
---|
[ecfcef6] | 1006 | msg = "Please get Data first..." |
---|
[504dd9f5] | 1007 | wx.MessageBox(msg, 'Info') |
---|
[308fa87] | 1008 | wx.PostEvent(self._manager.parent, |
---|
| 1009 | StatusEvent(status="Fit: %s" % msg)) |
---|
[504dd9f5] | 1010 | return |
---|
| 1011 | if self.model is None: |
---|
| 1012 | msg = "Please select a Model first..." |
---|
[4470b10] | 1013 | wx.MessageBox(msg, 'Info') |
---|
[308fa87] | 1014 | wx.PostEvent(self._manager.parent, |
---|
| 1015 | StatusEvent(status="Fit: %s" % msg, type="stop")) |
---|
[4470b10] | 1016 | return |
---|
[2f4b430] | 1017 | |
---|
[ecfcef6] | 1018 | if len(self.param_toFit) <= 0: |
---|
[308fa87] | 1019 | msg = "Select at least one parameter to fit" |
---|
[ecfcef6] | 1020 | wx.MessageBox(msg, 'Info') |
---|
[308fa87] | 1021 | wx.PostEvent(self._manager.parent, |
---|
| 1022 | StatusEvent(status=msg, type="stop")) |
---|
| 1023 | return |
---|
[2f4b430] | 1024 | |
---|
[308fa87] | 1025 | flag = self._update_paramv_on_fit() |
---|
[2f4b430] | 1026 | |
---|
[94078a8] | 1027 | if self.batch_on and not self._is_2D(): |
---|
| 1028 | if not self._validate_Npts_1D(): |
---|
| 1029 | return |
---|
[2f4b430] | 1030 | |
---|
[c77d859] | 1031 | if not flag: |
---|
[308fa87] | 1032 | msg = "Fitting range or parameters are invalid" |
---|
[ae84427] | 1033 | wx.PostEvent(self._manager.parent, |
---|
[308fa87] | 1034 | StatusEvent(status=msg, type="stop")) |
---|
| 1035 | return |
---|
[2f4b430] | 1036 | |
---|
[308fa87] | 1037 | self.select_param(event=None) |
---|
[d0ce2c30] | 1038 | |
---|
[308fa87] | 1039 | # Remove or do not allow fitting on the Q=0 point, especially |
---|
| 1040 | # when y(q=0)=None at x[0]. |
---|
[f95301b] | 1041 | self.qmin_x = float(self.qmin.GetValue()) |
---|
[67ae937] | 1042 | self.qmax_x = float(self.qmax.GetValue()) |
---|
[dc613d6] | 1043 | self._manager._reset_schedule_problem(value=0, uid=self.uid) |
---|
[308fa87] | 1044 | self._manager.schedule_for_fit(uid=self.uid, value=1) |
---|
| 1045 | self._manager.set_fit_range(uid=self.uid, qmin=self.qmin_x, |
---|
| 1046 | qmax=self.qmax_x) |
---|
[3b70cc7] | 1047 | |
---|
[308fa87] | 1048 | #single fit |
---|
[2d0756a5] | 1049 | #self._manager.onFit(uid=self.uid) |
---|
| 1050 | self.fit_started = self._manager.onFit(uid=self.uid) |
---|
| 1051 | wx.CallAfter(self.set_fitbutton) |
---|
[2f4b430] | 1052 | |
---|
[308fa87] | 1053 | def set_fitbutton(self): |
---|
[2d0756a5] | 1054 | """ |
---|
| 1055 | Set fit button label depending on the fit_started[bool] |
---|
| 1056 | """ |
---|
[e4cd34c] | 1057 | # Skip this feature if we are not on Windows |
---|
| 1058 | #NOTE: the is_mac data member actually means "is no Windows". |
---|
| 1059 | if self.is_mac: |
---|
| 1060 | return |
---|
[2f4b430] | 1061 | |
---|
[2d0756a5] | 1062 | if self.fit_started: |
---|
| 1063 | label = "Stop" |
---|
| 1064 | color = "red" |
---|
| 1065 | else: |
---|
| 1066 | label = "Fit" |
---|
| 1067 | color = "black" |
---|
| 1068 | self.btFit.Enable(False) |
---|
| 1069 | self.btFit.SetLabel(label) |
---|
| 1070 | self.btFit.SetForegroundColour(color) |
---|
| 1071 | self.btFit.Enable(True) |
---|
[2f4b430] | 1072 | |
---|
[f7ef313] | 1073 | def get_weight_flag(self): |
---|
[55bb249c] | 1074 | """ |
---|
[f7ef313] | 1075 | Get flag corresponding to a given weighting dI data. |
---|
[55bb249c] | 1076 | """ |
---|
| 1077 | button_list = [self.dI_noweight, |
---|
| 1078 | self.dI_didata, |
---|
| 1079 | self.dI_sqrdata, |
---|
| 1080 | self.dI_idata] |
---|
[f7ef313] | 1081 | flag = 1 |
---|
[55bb249c] | 1082 | for item in button_list: |
---|
| 1083 | if item.GetValue(): |
---|
| 1084 | if button_list.index(item) == 0: |
---|
[308fa87] | 1085 | flag = 0 # dy = numpy.ones_like(dy_data) |
---|
[55bb249c] | 1086 | elif button_list.index(item) == 1: |
---|
[308fa87] | 1087 | flag = 1 # dy = dy_data |
---|
[55bb249c] | 1088 | elif button_list.index(item) == 2: |
---|
[308fa87] | 1089 | flag = 2 # dy = numpy.sqrt(numpy.abs(data)) |
---|
[55bb249c] | 1090 | elif button_list.index(item) == 3: |
---|
[308fa87] | 1091 | flag = 3 # dy = numpy.abs(data) |
---|
[55bb249c] | 1092 | break |
---|
[f7ef313] | 1093 | return flag |
---|
[2f4b430] | 1094 | |
---|
[f22e626] | 1095 | def _StopFit(self, event=None): |
---|
[ad6dd4c] | 1096 | """ |
---|
[308fa87] | 1097 | Stop fit |
---|
[ad6dd4c] | 1098 | """ |
---|
[5f2de0aa] | 1099 | if event != None: |
---|
| 1100 | event.Skip() |
---|
[66ff250] | 1101 | self._manager.stop_fit(self.uid) |
---|
| 1102 | self._manager._reset_schedule_problem(value=0) |
---|
[db47703] | 1103 | self._on_fit_complete() |
---|
[2f4b430] | 1104 | |
---|
[6ff97c5] | 1105 | def rename_model(self): |
---|
| 1106 | """ |
---|
| 1107 | find a short name for model |
---|
| 1108 | """ |
---|
| 1109 | if self.model is not None: |
---|
| 1110 | self.model.name = "M" + str(self.index_model) |
---|
[2f4b430] | 1111 | |
---|
[308fa87] | 1112 | def _on_select_model(self, event=None): |
---|
[c77d859] | 1113 | """ |
---|
[5062bbf] | 1114 | call back for model selection |
---|
[308fa87] | 1115 | """ |
---|
| 1116 | self.Show(False) |
---|
| 1117 | copy_flag = False |
---|
| 1118 | is_poly_enabled = None |
---|
[817991b] | 1119 | if event != None: |
---|
[ea5fa58] | 1120 | if (event.GetEventObject() == self.formfactorbox\ |
---|
| 1121 | and self.structurebox.GetLabel() != 'None')\ |
---|
| 1122 | or event.GetEventObject() == self.structurebox\ |
---|
| 1123 | or event.GetEventObject() == self.multifactorbox: |
---|
| 1124 | copy_flag = self.get_copy_params() |
---|
| 1125 | is_poly_enabled = self.enable_disp.GetValue() |
---|
[a86e69b] | 1126 | |
---|
[308fa87] | 1127 | self._on_select_model_helper() |
---|
| 1128 | self.set_model_param_sizer(self.model) |
---|
[982e953] | 1129 | if self.model is None: |
---|
| 1130 | self._set_bookmark_flag(False) |
---|
[2657df9] | 1131 | self._keep.Enable(False) |
---|
[982e953] | 1132 | self._set_save_flag(False) |
---|
[3b605bb] | 1133 | self.enable_disp.SetValue(False) |
---|
| 1134 | self.disable_disp.SetValue(True) |
---|
[4043c96] | 1135 | try: |
---|
| 1136 | self.set_dispers_sizer() |
---|
| 1137 | except: |
---|
| 1138 | pass |
---|
[6747217] | 1139 | self.state.enable_disp = self.enable_disp.GetValue() |
---|
| 1140 | self.state.disable_disp = self.disable_disp.GetValue() |
---|
| 1141 | self.state.pinhole_smearer = self.pinhole_smearer.GetValue() |
---|
| 1142 | self.state.slit_smearer = self.slit_smearer.GetValue() |
---|
[2f4b430] | 1143 | |
---|
[308fa87] | 1144 | self.state.structurecombobox = self.structurebox.GetLabel() |
---|
[ea5fa58] | 1145 | self.state.formfactorcombobox = self.formfactorbox.GetLabel() |
---|
[6ff97c5] | 1146 | self.enable_fit_button() |
---|
[9237df4] | 1147 | if self.model != None: |
---|
[93f0a862] | 1148 | self.m_name = self.model.name |
---|
| 1149 | self.state.m_name = self.m_name |
---|
[6ff97c5] | 1150 | self.rename_model() |
---|
[07c8630] | 1151 | self._set_copy_flag(True) |
---|
| 1152 | self._set_paste_flag(True) |
---|
[817991b] | 1153 | if self.data is not None: |
---|
[308fa87] | 1154 | is_data = check_data_validity(self.data) |
---|
[817991b] | 1155 | if is_data: |
---|
[940aca7] | 1156 | self._set_bookmark_flag(not self.batch_on) |
---|
| 1157 | self._keep.Enable(not self.batch_on) |
---|
[d40038e] | 1158 | self._set_save_flag(True) |
---|
[64bda1e] | 1159 | # Reset smearer, model and data |
---|
[2d34d55] | 1160 | if not copy_flag: |
---|
| 1161 | self.disable_smearer.SetValue(True) |
---|
| 1162 | self.enable_smearer.SetValue(False) |
---|
[2f4b430] | 1163 | |
---|
[2c60cb69] | 1164 | # more disables for 2D |
---|
[3fb5e68] | 1165 | self._set_smear_buttons() |
---|
[2f4b430] | 1166 | |
---|
[70c57ebf] | 1167 | try: |
---|
[6bbeacd4] | 1168 | # update smearer sizer |
---|
[db8590a] | 1169 | #if not self.enable_smearer.GetValue(): |
---|
| 1170 | # self.disable_smearer.SetValue(True) |
---|
[6bbeacd4] | 1171 | self.onSmear(None) |
---|
[64bda1e] | 1172 | temp_smear = None |
---|
[6ff97c5] | 1173 | if not self.disable_smearer.GetValue(): |
---|
[64bda1e] | 1174 | # Set the smearer environments |
---|
[6e4c9fe] | 1175 | temp_smear = self.current_smearer |
---|
[70c57ebf] | 1176 | except: |
---|
[66ff250] | 1177 | raise |
---|
[70c57ebf] | 1178 | ## error occured on chisqr computation |
---|
[66ff250] | 1179 | #pass |
---|
[0b12abb5] | 1180 | ## event to post model to fit to fitting plugins |
---|
| 1181 | (ModelEventbox, EVT_MODEL_BOX) = wx.lib.newevent.NewEvent() |
---|
[2f4b430] | 1182 | |
---|
[308fa87] | 1183 | ## set smearing value whether or not |
---|
[6bbeacd4] | 1184 | # the data contain the smearing info |
---|
[308fa87] | 1185 | evt = ModelEventbox(model=self.model, |
---|
| 1186 | smearer=temp_smear, |
---|
| 1187 | enable_smearer=not self.disable_smearer.GetValue(), |
---|
| 1188 | qmin=float(self.qmin_x), |
---|
| 1189 | uid=self.uid, |
---|
| 1190 | caption=self.window_caption, |
---|
| 1191 | qmax=float(self.qmax_x)) |
---|
[2f4b430] | 1192 | |
---|
[6bbeacd4] | 1193 | self._manager._on_model_panel(evt=evt) |
---|
[2f4b430] | 1194 | self.mbox_description.SetLabel("Model [ %s ]" % str(self.model.name)) |
---|
[dafc36f] | 1195 | self.mbox_description.SetForegroundColour(wx.BLUE) |
---|
[0b12abb5] | 1196 | self.state.model = self.model.clone() |
---|
| 1197 | self.state.model.name = self.model.name |
---|
[88f286d] | 1198 | |
---|
[6bbeacd4] | 1199 | if event != None: |
---|
[3595309d] | 1200 | ## post state to fit panel |
---|
[308fa87] | 1201 | new_event = PageInfoEvent(page=self) |
---|
| 1202 | wx.PostEvent(self.parent, new_event) |
---|
[9466f2d6] | 1203 | #update list of plugins if new plugin is available |
---|
[ea5fa58] | 1204 | custom_model = 'Customized Models' |
---|
| 1205 | mod_cat = self.categorybox.GetStringSelection() |
---|
| 1206 | if mod_cat == custom_model: |
---|
| 1207 | temp = self.parent.update_model_list() |
---|
| 1208 | if temp: |
---|
| 1209 | self.model_list_box = temp |
---|
| 1210 | current_val = self.formfactorbox.GetLabel() |
---|
| 1211 | pos = self.formfactorbox.GetSelection() |
---|
| 1212 | self._show_combox_helper() |
---|
| 1213 | self.formfactorbox.SetSelection(pos) |
---|
| 1214 | self.formfactorbox.SetValue(current_val) |
---|
[817991b] | 1215 | # when select a model only from guictr/button |
---|
| 1216 | if is_poly_enabled != None: |
---|
| 1217 | self.enable_disp.SetValue(is_poly_enabled) |
---|
| 1218 | self.disable_disp.SetValue(not is_poly_enabled) |
---|
| 1219 | self._set_dipers_Param(event=None) |
---|
| 1220 | self.state.enable_disp = self.enable_disp.GetValue() |
---|
| 1221 | self.state.disable_disp = self.disable_disp.GetValue() |
---|
| 1222 | |
---|
| 1223 | # Keep the previous param values |
---|
[d682c92] | 1224 | if copy_flag: |
---|
[817991b] | 1225 | self.get_paste_params(copy_flag) |
---|
[db8590a] | 1226 | wx.CallAfter(self._onDraw, None) |
---|
[2f4b430] | 1227 | |
---|
[0145a25] | 1228 | else: |
---|
[7fd4afd] | 1229 | self._draw_model() |
---|
[2f4b430] | 1230 | |
---|
[1345f2f] | 1231 | if self.batch_on: |
---|
| 1232 | self.slit_smearer.Enable(False) |
---|
| 1233 | self.pinhole_smearer.Enable(False) |
---|
[308fa87] | 1234 | self.btEditMask.Disable() |
---|
[054f004] | 1235 | self.EditMask_title.Disable() |
---|
[2f4b430] | 1236 | |
---|
[308fa87] | 1237 | self.Show(True) |
---|
[ce92ded] | 1238 | self.SetupScrolling() |
---|
[2f4b430] | 1239 | |
---|
[308fa87] | 1240 | def _onparamEnter(self, event): |
---|
| 1241 | """ |
---|
[5062bbf] | 1242 | when enter value on panel redraw model according to changed |
---|
[dd5949d] | 1243 | """ |
---|
[308fa87] | 1244 | if self.model == None: |
---|
| 1245 | msg = "Please select a Model first..." |
---|
[4470b10] | 1246 | wx.MessageBox(msg, 'Info') |
---|
| 1247 | return |
---|
| 1248 | |
---|
[51a71a3] | 1249 | #default flag |
---|
[7975f2b] | 1250 | flag = False |
---|
[51a71a3] | 1251 | self.fitrange = True |
---|
| 1252 | #get event object |
---|
[dce84c0] | 1253 | tcrtl = event.GetEventObject() |
---|
[edd166b] | 1254 | #Clear msg if previously shown. |
---|
[308fa87] | 1255 | msg = "" |
---|
[ae84427] | 1256 | wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) |
---|
[c99a6c5] | 1257 | |
---|
[7975f2b] | 1258 | if check_float(tcrtl): |
---|
[308fa87] | 1259 | flag = self._onparamEnter_helper() |
---|
[bf5e985] | 1260 | self.show_npts2fit() |
---|
[308fa87] | 1261 | if self.fitrange: |
---|
[51a71a3] | 1262 | temp_smearer = None |
---|
| 1263 | if not self.disable_smearer.GetValue(): |
---|
[308fa87] | 1264 | temp_smearer = self.current_smearer |
---|
| 1265 | ## set smearing value whether or not |
---|
[d7b7156] | 1266 | # the data contain the smearing info |
---|
[51a71a3] | 1267 | if self.slit_smearer.GetValue(): |
---|
| 1268 | flag1 = self.update_slit_smear() |
---|
| 1269 | flag = flag or flag1 |
---|
| 1270 | elif self.pinhole_smearer.GetValue(): |
---|
| 1271 | flag1 = self.update_pinhole_smear() |
---|
| 1272 | flag = flag or flag1 |
---|
[308fa87] | 1273 | elif self.data.__class__.__name__ != "Data2D" and \ |
---|
[ba1f0b2] | 1274 | not self.enable2D: |
---|
[308fa87] | 1275 | self._manager.set_smearer(smearer=temp_smearer, |
---|
[6ff97c5] | 1276 | fid=self.data.id, |
---|
[66ff250] | 1277 | uid=self.uid, |
---|
[308fa87] | 1278 | qmin=float(self.qmin_x), |
---|
| 1279 | qmax=float(self.qmax_x), |
---|
[6ff97c5] | 1280 | enable_smearer=not self.disable_smearer.GetValue(), |
---|
[308fa87] | 1281 | draw=True) |
---|
| 1282 | if flag: |
---|
[f72333f] | 1283 | #self.compute_chisqr(smearer= temp_smearer) |
---|
[2f4b430] | 1284 | |
---|
[51a71a3] | 1285 | ## new state posted |
---|
| 1286 | if self.state_change: |
---|
| 1287 | #self._undo.Enable(True) |
---|
[308fa87] | 1288 | event = PageInfoEvent(page=self) |
---|
[51a71a3] | 1289 | wx.PostEvent(self.parent, event) |
---|
[308fa87] | 1290 | self.state_change = False |
---|
| 1291 | else: |
---|
| 1292 | # invalid fit range: do nothing here: |
---|
| 1293 | # msg already displayed in validate |
---|
| 1294 | return |
---|
[69bee6d] | 1295 | else: |
---|
[7975f2b] | 1296 | self.save_current_state() |
---|
[308fa87] | 1297 | msg = "Cannot Plot :Must enter a number!!! " |
---|
[ae84427] | 1298 | wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) |
---|
[2f4b430] | 1299 | |
---|
[308fa87] | 1300 | self.save_current_state() |
---|
| 1301 | return |
---|
[2f4b430] | 1302 | |
---|
[e2f7b92] | 1303 | def _onparamRangeEnter(self, event): |
---|
[920a6e5] | 1304 | """ |
---|
[5062bbf] | 1305 | Check validity of value enter in the parameters range field |
---|
[920a6e5] | 1306 | """ |
---|
[308fa87] | 1307 | tcrtl = event.GetEventObject() |
---|
[edd166b] | 1308 | #Clear msg if previously shown. |
---|
[308fa87] | 1309 | msg = "" |
---|
[ae84427] | 1310 | wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) |
---|
[edd166b] | 1311 | # Flag to register when a parameter has changed. |
---|
| 1312 | is_modified = False |
---|
[308fa87] | 1313 | if tcrtl.GetValue().lstrip().rstrip() != "": |
---|
[920a6e5] | 1314 | try: |
---|
| 1315 | tcrtl.SetBackgroundColour(wx.WHITE) |
---|
[308fa87] | 1316 | self._check_value_enter(self.fittable_param, is_modified) |
---|
| 1317 | self._check_value_enter(self.parameters, is_modified) |
---|
[920a6e5] | 1318 | except: |
---|
| 1319 | tcrtl.SetBackgroundColour("pink") |
---|
[308fa87] | 1320 | msg = "Model Error:wrong value entered : %s" % sys.exc_value |
---|
[ae84427] | 1321 | wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) |
---|
[308fa87] | 1322 | return |
---|
[920a6e5] | 1323 | else: |
---|
[308fa87] | 1324 | tcrtl.SetBackgroundColour(wx.WHITE) |
---|
[2f4b430] | 1325 | |
---|
[edd166b] | 1326 | #self._undo.Enable(True) |
---|
| 1327 | self.save_current_state() |
---|
[308fa87] | 1328 | event = PageInfoEvent(page=self) |
---|
[edd166b] | 1329 | wx.PostEvent(self.parent, event) |
---|
[308fa87] | 1330 | self.state_change = False |
---|
[2f4b430] | 1331 | |
---|
| 1332 | def qrang_set_focus(self, event=None): |
---|
[3e001f9] | 1333 | """ |
---|
| 1334 | ON Qrange focus |
---|
| 1335 | """ |
---|
| 1336 | if event != None: |
---|
| 1337 | event.Skip() |
---|
| 1338 | #tcrtl = event.GetEventObject() |
---|
| 1339 | self._validate_qrange(self.qmin, self.qmax) |
---|
[2f4b430] | 1340 | |
---|
[3e001f9] | 1341 | def qrange_click(self, event): |
---|
| 1342 | """ |
---|
| 1343 | On Qrange textctrl click, make the qrange lines in the plot |
---|
| 1344 | """ |
---|
| 1345 | if event != None: |
---|
| 1346 | event.Skip() |
---|
| 1347 | if self.data.__class__.__name__ == "Data2D": |
---|
| 1348 | return |
---|
| 1349 | is_click = event.LeftDown() |
---|
| 1350 | if is_click: |
---|
| 1351 | d_id = self.data.id |
---|
| 1352 | d_group_id = self.data.group_id |
---|
| 1353 | act_ctrl = event.GetEventObject() |
---|
[2f4b430] | 1354 | wx.PostEvent(self._manager.parent, |
---|
| 1355 | PlotQrangeEvent(ctrl=[self.qmin, self.qmax], id=d_id, |
---|
[3e001f9] | 1356 | group_id=d_group_id, leftdown=is_click, |
---|
| 1357 | active=act_ctrl)) |
---|
[2f4b430] | 1358 | |
---|
[3e001f9] | 1359 | def on_qrange_text(self, event): |
---|
| 1360 | """ |
---|
| 1361 | #On q range value updated. DO not combine with qrange_click(). |
---|
| 1362 | """ |
---|
| 1363 | if event != None: |
---|
| 1364 | event.Skip() |
---|
| 1365 | if self.data.__class__.__name__ == "Data2D": |
---|
| 1366 | return |
---|
| 1367 | act_ctrl = event.GetEventObject() |
---|
| 1368 | d_id = self.data.id |
---|
| 1369 | d_group_id = self.data.group_id |
---|
[2f4b430] | 1370 | wx.PostEvent(self._manager.parent, |
---|
| 1371 | PlotQrangeEvent(ctrl=[self.qmin, self.qmax], id=d_id, |
---|
| 1372 | group_id=d_group_id, leftdown=False, |
---|
[3e001f9] | 1373 | active=act_ctrl)) |
---|
| 1374 | self._validate_qrange(self.qmin, self.qmax) |
---|
[2f4b430] | 1375 | |
---|
| 1376 | def on_key(self, event): |
---|
[3e001f9] | 1377 | """ |
---|
| 1378 | On Key down |
---|
| 1379 | """ |
---|
| 1380 | event.Skip() |
---|
| 1381 | if self.data.__class__.__name__ == "Data2D": |
---|
| 1382 | return |
---|
| 1383 | ctrl = event.GetEventObject() |
---|
| 1384 | try: |
---|
| 1385 | x_data = float(ctrl.GetValue()) |
---|
| 1386 | except: |
---|
[2f4b430] | 1387 | return |
---|
[3e001f9] | 1388 | key = event.GetKeyCode() |
---|
| 1389 | length = len(self.data.x) |
---|
| 1390 | indx = (numpy.abs(self.data.x - x_data)).argmin() |
---|
| 1391 | #return array.flat[idx] |
---|
| 1392 | if key == wx.WXK_PAGEUP or key == wx.WXK_NUMPAD_PAGEUP: |
---|
| 1393 | indx += 1 |
---|
| 1394 | if indx >= length: |
---|
| 1395 | indx = length - 1 |
---|
| 1396 | elif key == wx.WXK_PAGEDOWN or key == wx.WXK_NUMPAD_PAGEDOWN: |
---|
| 1397 | indx -= 1 |
---|
| 1398 | if indx < 0: |
---|
| 1399 | indx = 0 |
---|
| 1400 | else: |
---|
| 1401 | return |
---|
| 1402 | ctrl.SetValue(str(self.data.x[indx])) |
---|
| 1403 | self._validate_qrange(self.qmin, self.qmax) |
---|
[2f4b430] | 1404 | |
---|
[12eac73] | 1405 | def _onQrangeEnter(self, event): |
---|
| 1406 | """ |
---|
[5062bbf] | 1407 | Check validity of value enter in the Q range field |
---|
[12eac73] | 1408 | """ |
---|
[6ff97c5] | 1409 | tcrtl = event.GetEventObject() |
---|
[12eac73] | 1410 | #Clear msg if previously shown. |
---|
[308fa87] | 1411 | msg = "" |
---|
[ae84427] | 1412 | wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) |
---|
[33477fd] | 1413 | # For theory mode |
---|
| 1414 | if not self.data.is_data: |
---|
[d2c4c06] | 1415 | self.npts_x = self.Npts_total.GetValue() |
---|
| 1416 | self.Npts_fit.SetValue(self.npts_x) |
---|
[33477fd] | 1417 | self.create_default_data() |
---|
[12eac73] | 1418 | # Flag to register when a parameter has changed. |
---|
[308fa87] | 1419 | if tcrtl.GetValue().lstrip().rstrip() != "": |
---|
[12eac73] | 1420 | try: |
---|
| 1421 | tcrtl.SetBackgroundColour(wx.WHITE) |
---|
| 1422 | # If qmin and qmax have been modified, update qmin and qmax |
---|
[308fa87] | 1423 | if self._validate_qrange(self.qmin, self.qmax): |
---|
[f95301b] | 1424 | tempmin = float(self.qmin.GetValue()) |
---|
[12eac73] | 1425 | if tempmin != self.qmin_x: |
---|
| 1426 | self.qmin_x = tempmin |
---|
| 1427 | tempmax = float(self.qmax.GetValue()) |
---|
| 1428 | if tempmax != self.qmax_x: |
---|
| 1429 | self.qmax_x = tempmax |
---|
| 1430 | else: |
---|
| 1431 | tcrtl.SetBackgroundColour("pink") |
---|
[308fa87] | 1432 | msg = "Model Error:wrong value entered : %s" % sys.exc_value |
---|
[ae84427] | 1433 | wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) |
---|
[308fa87] | 1434 | return |
---|
[12eac73] | 1435 | except: |
---|
| 1436 | tcrtl.SetBackgroundColour("pink") |
---|
[308fa87] | 1437 | msg = "Model Error:wrong value entered : %s" % sys.exc_value |
---|
[ae84427] | 1438 | wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) |
---|
[308fa87] | 1439 | return |
---|
[12eac73] | 1440 | #Check if # of points for theory model are valid(>0). |
---|
[51a71a3] | 1441 | # check for 2d |
---|
[6ff97c5] | 1442 | if self.data.__class__.__name__ == "Data2D" or \ |
---|
| 1443 | self.enable2D: |
---|
[308fa87] | 1444 | # set mask |
---|
| 1445 | radius = numpy.sqrt(self.data.qx_data * self.data.qx_data + |
---|
| 1446 | self.data.qy_data * self.data.qy_data) |
---|
| 1447 | index_data = ((self.qmin_x <= radius) & \ |
---|
| 1448 | (radius <= self.qmax_x)) |
---|
| 1449 | index_data = (index_data) & (self.data.mask) |
---|
| 1450 | index_data = (index_data) & (numpy.isfinite(self.data.data)) |
---|
[6ff97c5] | 1451 | if len(index_data[index_data]) < 10: |
---|
| 1452 | msg = "Cannot Plot :No or too little npts in" |
---|
| 1453 | msg += " that data range!!! " |
---|
[ae84427] | 1454 | wx.PostEvent(self._manager.parent, |
---|
[6ff97c5] | 1455 | StatusEvent(status=msg)) |
---|
| 1456 | return |
---|
[51a71a3] | 1457 | else: |
---|
[3b70cc7] | 1458 | #self.data.mask = index_data |
---|
[6ff97c5] | 1459 | #self.Npts_fit.SetValue(str(len(self.data.mask))) |
---|
[bf5e985] | 1460 | self.show_npts2fit() |
---|
[0cf97c5] | 1461 | else: |
---|
[308fa87] | 1462 | index_data = ((self.qmin_x <= self.data.x) & \ |
---|
[6ff97c5] | 1463 | (self.data.x <= self.qmax_x)) |
---|
| 1464 | self.Npts_fit.SetValue(str(len(self.data.x[index_data]))) |
---|
[2f4b430] | 1465 | |
---|
[6ff97c5] | 1466 | self.npts_x = self.Npts_total.GetValue() |
---|
| 1467 | self.create_default_data() |
---|
| 1468 | self._save_plotting_range() |
---|
[12eac73] | 1469 | else: |
---|
[308fa87] | 1470 | tcrtl.SetBackgroundColour("pink") |
---|
| 1471 | msg = "Model Error:wrong value entered!!!" |
---|
[ae84427] | 1472 | wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) |
---|
[2f4b430] | 1473 | |
---|
[f72333f] | 1474 | self._draw_model() |
---|
[12eac73] | 1475 | self.save_current_state() |
---|
[308fa87] | 1476 | event = PageInfoEvent(page=self) |
---|
[12eac73] | 1477 | wx.PostEvent(self.parent, event) |
---|
[308fa87] | 1478 | self.state_change = False |
---|
[51a71a3] | 1479 | return |
---|
[2f4b430] | 1480 | |
---|
[edd166b] | 1481 | def _clear_Err_on_Fit(self): |
---|
| 1482 | """ |
---|
[308fa87] | 1483 | hide the error text control shown |
---|
[5062bbf] | 1484 | after fitting |
---|
[edd166b] | 1485 | """ |
---|
[9e11cf5] | 1486 | |
---|
[ce92ded] | 1487 | if self.is_mac: |
---|
| 1488 | return |
---|
[308fa87] | 1489 | if hasattr(self, "text2_3"): |
---|
[edd166b] | 1490 | self.text2_3.Hide() |
---|
| 1491 | |
---|
[308fa87] | 1492 | if len(self.parameters) > 0: |
---|
[edd166b] | 1493 | for item in self.parameters: |
---|
[940aca7] | 1494 | if item[0].IsShown(): |
---|
[9e11cf5] | 1495 | #Skip the angle parameters if 1D data |
---|
[940aca7] | 1496 | if self.data.__class__.__name__ != "Data2D" and \ |
---|
| 1497 | not self.enable2D: |
---|
| 1498 | if item in self.orientation_params: |
---|
| 1499 | continue |
---|
| 1500 | if item in self.param_toFit: |
---|
[edd166b] | 1501 | continue |
---|
[940aca7] | 1502 | ## hide statictext +/- |
---|
| 1503 | if len(item) < 4: |
---|
| 1504 | continue |
---|
| 1505 | if item[3] != None and item[3].IsShown(): |
---|
| 1506 | item[3].Hide() |
---|
| 1507 | ## hide textcrtl for error after fit |
---|
| 1508 | if item[4] != None and item[4].IsShown(): |
---|
| 1509 | item[4].Hide() |
---|
[2f4b430] | 1510 | |
---|
[308fa87] | 1511 | if len(self.fittable_param) > 0: |
---|
[edd166b] | 1512 | for item in self.fittable_param: |
---|
[940aca7] | 1513 | if item[0].IsShown(): |
---|
[9e11cf5] | 1514 | #Skip the angle parameters if 1D data |
---|
[940aca7] | 1515 | if self.data.__class__.__name__ != "Data2D" and \ |
---|
| 1516 | not self.enable2D: |
---|
| 1517 | if item in self.orientation_params: |
---|
| 1518 | continue |
---|
| 1519 | if item in self.param_toFit: |
---|
[edd166b] | 1520 | continue |
---|
[940aca7] | 1521 | if len(item) < 4: |
---|
| 1522 | continue |
---|
| 1523 | ## hide statictext +/- |
---|
| 1524 | if item[3] != None and item[3].IsShown(): |
---|
| 1525 | item[3].Hide() |
---|
| 1526 | ## hide textcrtl for error after fit |
---|
| 1527 | if item[4] != None and item[4].IsShown(): |
---|
| 1528 | item[4].Hide() |
---|
[308fa87] | 1529 | return |
---|
[2f4b430] | 1530 | |
---|
[7609f1a] | 1531 | def _get_defult_custom_smear(self): |
---|
| 1532 | """ |
---|
[5062bbf] | 1533 | Get the defult values for custum smearing. |
---|
[7609f1a] | 1534 | """ |
---|
| 1535 | # get the default values |
---|
[308fa87] | 1536 | if self.dxl == None: |
---|
| 1537 | self.dxl = 0.0 |
---|
| 1538 | if self.dxw == None: |
---|
| 1539 | self.dxw = "" |
---|
| 1540 | if self.dx_min == None: |
---|
| 1541 | self.dx_min = SMEAR_SIZE_L |
---|
| 1542 | if self.dx_max == None: |
---|
| 1543 | self.dx_max = SMEAR_SIZE_H |
---|
[2f4b430] | 1544 | |
---|
[7609f1a] | 1545 | def _get_smear_info(self): |
---|
| 1546 | """ |
---|
[5062bbf] | 1547 | Get the smear info from data. |
---|
[2f4b430] | 1548 | |
---|
[308fa87] | 1549 | :return: self.smear_type, self.dq_l and self.dq_r, |
---|
| 1550 | respectively the type of the smear, dq_min and |
---|
| 1551 | dq_max for pinhole smear data |
---|
[7609f1a] | 1552 | while dxl and dxw for slit smear |
---|
| 1553 | """ |
---|
| 1554 | # default |
---|
| 1555 | self.smear_type = None |
---|
| 1556 | self.dq_l = None |
---|
| 1557 | self.dq_r = None |
---|
[f72333f] | 1558 | data = self.data |
---|
| 1559 | if self.data is None: |
---|
[7609f1a] | 1560 | return |
---|
[308fa87] | 1561 | elif self.data.__class__.__name__ == "Data2D" or \ |
---|
| 1562 | self.enable2D: |
---|
| 1563 | if data.dqx_data == None or data.dqy_data == None: |
---|
[f72333f] | 1564 | return |
---|
[308fa87] | 1565 | elif self.current_smearer != None \ |
---|
| 1566 | and data.dqx_data.any() != 0 \ |
---|
| 1567 | and data.dqx_data.any() != 0: |
---|
[f72333f] | 1568 | self.smear_type = "Pinhole2d" |
---|
[308fa87] | 1569 | self.dq_l = format_number(numpy.average(data.dqx_data)) |
---|
| 1570 | self.dq_r = format_number(numpy.average(data.dqy_data)) |
---|
| 1571 | return |
---|
| 1572 | else: |
---|
[f72333f] | 1573 | return |
---|
[7609f1a] | 1574 | # check if it is pinhole smear and get min max if it is. |
---|
[308fa87] | 1575 | if data.dx != None and all(data.dx != 0): |
---|
| 1576 | self.smear_type = "Pinhole" |
---|
[f72333f] | 1577 | self.dq_l = data.dx[0] |
---|
| 1578 | self.dq_r = data.dx[-1] |
---|
[2f4b430] | 1579 | |
---|
[7609f1a] | 1580 | # check if it is slit smear and get min max if it is. |
---|
[308fa87] | 1581 | elif data.dxl != None or data.dxw != None: |
---|
| 1582 | self.smear_type = "Slit" |
---|
| 1583 | if data.dxl != None and all(data.dxl != 0): |
---|
[7609f1a] | 1584 | self.dq_l = data.dxl[0] |
---|
[308fa87] | 1585 | if data.dxw != None and all(data.dxw != 0): |
---|
| 1586 | self.dq_r = data.dxw[0] |
---|
| 1587 | #return self.smear_type,self.dq_l,self.dq_r |
---|
[2f4b430] | 1588 | |
---|
[308fa87] | 1589 | def _show_smear_sizer(self): |
---|
[7609f1a] | 1590 | """ |
---|
[5062bbf] | 1591 | Show only the sizers depending on smear selection |
---|
[7609f1a] | 1592 | """ |
---|
[f72333f] | 1593 | # smear disabled |
---|
[7609f1a] | 1594 | if self.disable_smearer.GetValue(): |
---|
| 1595 | self.smear_description_none.Show(True) |
---|
[f72333f] | 1596 | # 2Dsmear |
---|
| 1597 | elif self._is_2D(): |
---|
| 1598 | self.smear_description_accuracy_type.Show(True) |
---|
| 1599 | self.smear_accuracy.Show(True) |
---|
| 1600 | self.smear_description_accuracy_type.Show(True) |
---|
| 1601 | self.smear_description_2d.Show(True) |
---|
| 1602 | self.smear_description_2d_x.Show(True) |
---|
| 1603 | self.smear_description_2d_y.Show(True) |
---|
| 1604 | if self.pinhole_smearer.GetValue(): |
---|
| 1605 | self.smear_pinhole_min.Show(True) |
---|
| 1606 | self.smear_pinhole_max.Show(True) |
---|
| 1607 | # smear from data |
---|
[7609f1a] | 1608 | elif self.enable_smearer.GetValue(): |
---|
[f72333f] | 1609 | |
---|
[7609f1a] | 1610 | self.smear_description_dqdata.Show(True) |
---|
| 1611 | if self.smear_type != None: |
---|
| 1612 | self.smear_description_smear_type.Show(True) |
---|
| 1613 | if self.smear_type == 'Slit': |
---|
| 1614 | self.smear_description_slit_height.Show(True) |
---|
[308fa87] | 1615 | self.smear_description_slit_width.Show(True) |
---|
[7609f1a] | 1616 | elif self.smear_type == 'Pinhole': |
---|
| 1617 | self.smear_description_pin_min.Show(True) |
---|
| 1618 | self.smear_description_pin_max.Show(True) |
---|
[f72333f] | 1619 | self.smear_description_smear_type.Show(True) |
---|
| 1620 | self.smear_description_type.Show(True) |
---|
[7609f1a] | 1621 | self.smear_data_left.Show(True) |
---|
| 1622 | self.smear_data_right.Show(True) |
---|
[f72333f] | 1623 | # custom pinhole smear |
---|
[7609f1a] | 1624 | elif self.pinhole_smearer.GetValue(): |
---|
[f72333f] | 1625 | if self.smear_type == 'Pinhole': |
---|
| 1626 | self.smear_message_new_p.Show(True) |
---|
| 1627 | self.smear_description_pin_min.Show(True) |
---|
| 1628 | self.smear_description_pin_max.Show(True) |
---|
| 1629 | |
---|
[7609f1a] | 1630 | self.smear_pinhole_min.Show(True) |
---|
| 1631 | self.smear_pinhole_max.Show(True) |
---|
[f72333f] | 1632 | # custom slit smear |
---|
[7609f1a] | 1633 | elif self.slit_smearer.GetValue(): |
---|
| 1634 | self.smear_message_new_s.Show(True) |
---|
| 1635 | self.smear_description_slit_height.Show(True) |
---|
| 1636 | self.smear_slit_height.Show(True) |
---|
| 1637 | self.smear_description_slit_width.Show(True) |
---|
| 1638 | self.smear_slit_width.Show(True) |
---|
| 1639 | |
---|
| 1640 | def _hide_all_smear_info(self): |
---|
| 1641 | """ |
---|
[5062bbf] | 1642 | Hide all smearing messages in the set_smearer sizer |
---|
[7609f1a] | 1643 | """ |
---|
| 1644 | self.smear_description_none.Hide() |
---|
| 1645 | self.smear_description_dqdata.Hide() |
---|
| 1646 | self.smear_description_type.Hide() |
---|
| 1647 | self.smear_description_smear_type.Hide() |
---|
[f72333f] | 1648 | self.smear_description_accuracy_type.Hide() |
---|
| 1649 | self.smear_description_2d_x.Hide() |
---|
| 1650 | self.smear_description_2d_y.Hide() |
---|
[7609f1a] | 1651 | self.smear_description_2d.Hide() |
---|
[2f4b430] | 1652 | |
---|
[f72333f] | 1653 | self.smear_accuracy.Hide() |
---|
[7609f1a] | 1654 | self.smear_data_left.Hide() |
---|
| 1655 | self.smear_data_right.Hide() |
---|
| 1656 | self.smear_description_pin_min.Hide() |
---|
| 1657 | self.smear_pinhole_min.Hide() |
---|
| 1658 | self.smear_description_pin_max.Hide() |
---|
| 1659 | self.smear_pinhole_max.Hide() |
---|
| 1660 | self.smear_description_slit_height.Hide() |
---|
| 1661 | self.smear_slit_height.Hide() |
---|
| 1662 | self.smear_description_slit_width.Hide() |
---|
| 1663 | self.smear_slit_width.Hide() |
---|
| 1664 | self.smear_message_new_p.Hide() |
---|
| 1665 | self.smear_message_new_s.Hide() |
---|
[2f4b430] | 1666 | |
---|
[f72333f] | 1667 | def _set_accuracy_list(self): |
---|
| 1668 | """ |
---|
[308fa87] | 1669 | Set the list of an accuracy in 2D custum smear: |
---|
| 1670 | Xhigh, High, Med, or Low |
---|
[f72333f] | 1671 | """ |
---|
| 1672 | # list of accuracy choices |
---|
[308fa87] | 1673 | list = ['Low', 'Med', 'High', 'Xhigh'] |
---|
[f72333f] | 1674 | for idx in range(len(list)): |
---|
[308fa87] | 1675 | self.smear_accuracy.Append(list[idx], idx) |
---|
[2f4b430] | 1676 | |
---|
[308fa87] | 1677 | def _set_fun_box_list(self, fun_box): |
---|
[fb59ed9] | 1678 | """ |
---|
| 1679 | Set the list of func for multifunctional models |
---|
| 1680 | """ |
---|
| 1681 | # Check if it is multi_functional model |
---|
[8960479] | 1682 | if self.model.__class__ not in self.model_list_box["Multi-Functions"] \ |
---|
| 1683 | and not self.temp_multi_functional: |
---|
[fb59ed9] | 1684 | return None |
---|
| 1685 | # Get the func name list |
---|
| 1686 | list = self.model.fun_list |
---|
| 1687 | if len(list) == 0: |
---|
| 1688 | return None |
---|
| 1689 | # build function (combo)box |
---|
| 1690 | ind = 0 |
---|
| 1691 | while(ind < len(list)): |
---|
| 1692 | for key, val in list.iteritems(): |
---|
| 1693 | if (val == ind): |
---|
[308fa87] | 1694 | fun_box.Append(key, val) |
---|
[fb59ed9] | 1695 | break |
---|
| 1696 | ind += 1 |
---|
[2f4b430] | 1697 | |
---|
[308fa87] | 1698 | def _on_select_accuracy(self, event): |
---|
[f72333f] | 1699 | """ |
---|
[5062bbf] | 1700 | Select an accuracy in 2D custom smear: Xhigh, High, Med, or Low |
---|
[f72333f] | 1701 | """ |
---|
| 1702 | #event.Skip() |
---|
[4fbc93e] | 1703 | # Check if the accuracy is same as before |
---|
| 1704 | #self.smear2d_accuracy = event.GetEventObject().GetValue() |
---|
| 1705 | self.smear2d_accuracy = self.smear_accuracy.GetValue() |
---|
[f72333f] | 1706 | if self.pinhole_smearer.GetValue(): |
---|
| 1707 | self.onPinholeSmear(event=None) |
---|
[308fa87] | 1708 | else: |
---|
[4fbc93e] | 1709 | self.onSmear(event=None) |
---|
| 1710 | if self.current_smearer != None: |
---|
[075d073] | 1711 | self.current_smearer.set_accuracy(accuracy=\ |
---|
[2f4b430] | 1712 | self.smear2d_accuracy) |
---|
[f72333f] | 1713 | event.Skip() |
---|
[fb59ed9] | 1714 | |
---|
[308fa87] | 1715 | def _on_fun_box(self, event): |
---|
[fb59ed9] | 1716 | """ |
---|
| 1717 | Select an func: Erf,Rparabola,LParabola |
---|
| 1718 | """ |
---|
| 1719 | fun_val = None |
---|
| 1720 | fun_box = event.GetEventObject() |
---|
| 1721 | name = fun_box.Name |
---|
| 1722 | value = fun_box.GetValue() |
---|
[308fa87] | 1723 | if value in self.model.fun_list: |
---|
[fb59ed9] | 1724 | fun_val = self.model.fun_list[value] |
---|
| 1725 | |
---|
[308fa87] | 1726 | self.model.setParam(name, fun_val) |
---|
[fb59ed9] | 1727 | # save state |
---|
[308fa87] | 1728 | self._copy_parameters_state(self.str_parameters, |
---|
[d7b7156] | 1729 | self.state.str_parameters) |
---|
[fb59ed9] | 1730 | # update params |
---|
[308fa87] | 1731 | self._update_paramv_on_fit() |
---|
[fb59ed9] | 1732 | # draw |
---|
| 1733 | self._draw_model() |
---|
| 1734 | self.Refresh() |
---|
| 1735 | # get ready for new event |
---|
| 1736 | event.Skip() |
---|
[2f4b430] | 1737 | |
---|
[308fa87] | 1738 | def _onMask(self, event): |
---|
[51a71a3] | 1739 | """ |
---|
[5062bbf] | 1740 | Build a panel to allow to edit Mask |
---|
[51a71a3] | 1741 | """ |
---|
[79492222] | 1742 | from sas.guiframe.local_perspectives.plotting.masking \ |
---|
[d7b7156] | 1743 | import MaskPanel as MaskDialog |
---|
[2f4b430] | 1744 | |
---|
[25952cd] | 1745 | self.panel = MaskDialog(base=self, data=self.data, id=wx.NewId()) |
---|
[51a71a3] | 1746 | self.panel.ShowModal() |
---|
[2f4b430] | 1747 | |
---|
[c365765] | 1748 | def _draw_masked_model(self, event): |
---|
[f72333f] | 1749 | """ |
---|
| 1750 | Draw model image w/mask |
---|
| 1751 | """ |
---|
[51a71a3] | 1752 | is_valid_qrange = self._update_paramv_on_fit() |
---|
[247cb58] | 1753 | |
---|
[6d03e00] | 1754 | if is_valid_qrange and self.model != None: |
---|
[c365765] | 1755 | self.panel.MakeModal(False) |
---|
[308fa87] | 1756 | event.Skip() |
---|
[247cb58] | 1757 | # try re draw the model plot if it exists |
---|
[2e51013] | 1758 | self._draw_model() |
---|
[bf5e985] | 1759 | self.show_npts2fit() |
---|
[247cb58] | 1760 | elif self.model == None: |
---|
[c365765] | 1761 | self.panel.MakeModal(False) |
---|
| 1762 | event.Skip() |
---|
[bf5e985] | 1763 | self.show_npts2fit() |
---|
[308fa87] | 1764 | msg = "No model is found on updating MASK in the model plot... " |
---|
[ae84427] | 1765 | wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) |
---|
[51a71a3] | 1766 | else: |
---|
[c365765] | 1767 | event.Skip() |
---|
[247cb58] | 1768 | msg = ' Please consider your Q range, too.' |
---|
[51a71a3] | 1769 | self.panel.ShowMessage(msg) |
---|
[48bab15] | 1770 | |
---|
[6bbeacd4] | 1771 | def _set_smear(self, data): |
---|
| 1772 | """ |
---|
[075d073] | 1773 | Set_smear |
---|
[6bbeacd4] | 1774 | """ |
---|
| 1775 | if data is None: |
---|
| 1776 | return |
---|
[6e4c9fe] | 1777 | self.current_smearer = smear_selection(data, self.model) |
---|
[308fa87] | 1778 | flag = self.disable_smearer.GetValue() |
---|
[9c1af44] | 1779 | self.disable_smearer.SetValue(flag) |
---|
[6e4c9fe] | 1780 | if self.current_smearer == None: |
---|
[6bbeacd4] | 1781 | self.enable_smearer.Disable() |
---|
| 1782 | else: |
---|
| 1783 | self.enable_smearer.Enable() |
---|
[9c1af44] | 1784 | if not flag: |
---|
| 1785 | self.onSmear(None) |
---|
[f6aee42] | 1786 | |
---|
| 1787 | def _mac_sleep(self, sec=0.2): |
---|
| 1788 | """ |
---|
| 1789 | Give sleep to MAC |
---|
| 1790 | """ |
---|
| 1791 | if self.is_mac: |
---|
| 1792 | time.sleep(sec) |
---|
| 1793 | |
---|
[a5701e6] | 1794 | def get_view_mode(self): |
---|
| 1795 | """ |
---|
| 1796 | return True if the panel allow 2D or False if 1D |
---|
| 1797 | """ |
---|
| 1798 | return self.enable2D |
---|
[2f4b430] | 1799 | |
---|
[a6d3553] | 1800 | def compute_data_set_range(self, data_list): |
---|
[4225aed] | 1801 | """ |
---|
| 1802 | find the range that include all data in the set |
---|
| 1803 | return the minimum and the maximum values |
---|
| 1804 | """ |
---|
[a6d3553] | 1805 | if data_list is not None and data_list != []: |
---|
| 1806 | for data in data_list: |
---|
| 1807 | qmin, qmax, npts = self.compute_data_range(data) |
---|
| 1808 | self.qmin_data_set = min(self.qmin_data_set, qmin) |
---|
| 1809 | self.qmax_data_set = max(self.qmax_data_set, qmax) |
---|
| 1810 | self.npts_data_set += npts |
---|
| 1811 | return self.qmin_data_set, self.qmax_data_set, self.npts_data_set |
---|
[2f4b430] | 1812 | |
---|
[75daa79] | 1813 | def compute_data_range(self, data): |
---|
| 1814 | """ |
---|
| 1815 | compute the minimum and the maximum range of the data |
---|
| 1816 | return the npts contains in data |
---|
| 1817 | :param data: |
---|
| 1818 | """ |
---|
| 1819 | qmin, qmax, npts = None, None, None |
---|
| 1820 | if data is not None: |
---|
[308fa87] | 1821 | if not hasattr(data, "data"): |
---|
[83b81b8] | 1822 | try: |
---|
| 1823 | qmin = min(data.x) |
---|
| 1824 | # Maximum value of data |
---|
| 1825 | qmax = max(data.x) |
---|
| 1826 | npts = len(data.x) |
---|
| 1827 | except: |
---|
[2f4b430] | 1828 | msg = "Unable to find min/max/length of \n data named %s" % \ |
---|
| 1829 | data.filename |
---|
[83b81b8] | 1830 | wx.PostEvent(self._manager.parent, StatusEvent(status=msg, |
---|
| 1831 | info="error")) |
---|
| 1832 | raise ValueError, msg |
---|
[2f4b430] | 1833 | |
---|
[75daa79] | 1834 | else: |
---|
| 1835 | qmin = 0 |
---|
[83b81b8] | 1836 | try: |
---|
| 1837 | x = max(math.fabs(data.xmin), math.fabs(data.xmax)) |
---|
| 1838 | y = max(math.fabs(data.ymin), math.fabs(data.ymax)) |
---|
| 1839 | except: |
---|
[2f4b430] | 1840 | msg = "Unable to find min/max of \n data named %s" % \ |
---|
| 1841 | data.filename |
---|
[83b81b8] | 1842 | wx.PostEvent(self._manager.parent, StatusEvent(status=msg, |
---|
| 1843 | info="error")) |
---|
| 1844 | raise ValueError, msg |
---|
[308fa87] | 1845 | ## Maximum value of data |
---|
| 1846 | qmax = math.sqrt(x * x + y * y) |
---|
[75daa79] | 1847 | npts = len(data.data) |
---|
| 1848 | return qmin, qmax, npts |
---|
[2f4b430] | 1849 | |
---|
[9237df4] | 1850 | def set_data(self, data): |
---|
[882a912] | 1851 | """ |
---|
[308fa87] | 1852 | reset the current data |
---|
[882a912] | 1853 | """ |
---|
[cc31608] | 1854 | id = None |
---|
[6bbeacd4] | 1855 | flag = False |
---|
[5e48acb] | 1856 | is_data = False |
---|
[b11e127] | 1857 | try: |
---|
| 1858 | old_id = self.data.id |
---|
| 1859 | old_group_id = self.data.group_id |
---|
| 1860 | except: |
---|
| 1861 | old_id = id |
---|
| 1862 | old_group_id = id |
---|
[6ff97c5] | 1863 | if self.data is not None: |
---|
[308fa87] | 1864 | is_data = check_data_validity(self.data) |
---|
[5e48acb] | 1865 | if not is_data and data is not None: |
---|
[6ff97c5] | 1866 | flag = True |
---|
[cc31608] | 1867 | if data is not None: |
---|
| 1868 | id = data.id |
---|
[5e48acb] | 1869 | if is_data: |
---|
| 1870 | self.graph_id = self.data.group_id |
---|
[cc31608] | 1871 | flag = (data.id != self.data.id) |
---|
[9237df4] | 1872 | self.data = data |
---|
[5e48acb] | 1873 | if check_data_validity(data): |
---|
| 1874 | self.graph_id = data.group_id |
---|
| 1875 | self.data.group_id = self.graph_id |
---|
[2f4b430] | 1876 | |
---|
[9237df4] | 1877 | if self.data is None: |
---|
| 1878 | data_name = "" |
---|
[982e953] | 1879 | self._set_bookmark_flag(False) |
---|
[2657df9] | 1880 | self._keep.Enable(False) |
---|
[982e953] | 1881 | self._set_save_flag(False) |
---|
[9237df4] | 1882 | else: |
---|
[1258aa3] | 1883 | if self.model != None: |
---|
[940aca7] | 1884 | self._set_bookmark_flag(not self.batch_on) |
---|
| 1885 | self._keep.Enable(not self.batch_on) |
---|
[2f4b430] | 1886 | if self.data.is_data: |
---|
[3e001f9] | 1887 | self._set_save_flag(True) |
---|
| 1888 | self._set_preview_flag(True) |
---|
[ba1f0b2] | 1889 | |
---|
[6bbeacd4] | 1890 | self._set_smear(data) |
---|
[7609f1a] | 1891 | # more disables for 2D |
---|
[308fa87] | 1892 | if self.data.__class__.__name__ == "Data2D" or \ |
---|
[ba1f0b2] | 1893 | self.enable2D: |
---|
[7609f1a] | 1894 | self.slit_smearer.Disable() |
---|
[308fa87] | 1895 | self.pinhole_smearer.Enable(True) |
---|
[51a71a3] | 1896 | self.default_mask = copy.deepcopy(self.data.mask) |
---|
[55bb249c] | 1897 | if self.data.err_data == None or\ |
---|
| 1898 | (self.data.err_data == 1).all() or\ |
---|
| 1899 | (self.data.err_data == 0).all(): |
---|
| 1900 | self.dI_didata.Enable(False) |
---|
| 1901 | self.dI_noweight.SetValue(True) |
---|
| 1902 | self.weightbt_string = self.dI_noweight.GetLabelText() |
---|
| 1903 | else: |
---|
| 1904 | self.dI_didata.Enable(True) |
---|
| 1905 | self.dI_didata.SetValue(True) |
---|
| 1906 | self.weightbt_string = self.dI_didata.GetLabelText() |
---|
[0f8f831] | 1907 | else: |
---|
[308fa87] | 1908 | self.slit_smearer.Enable(True) |
---|
| 1909 | self.pinhole_smearer.Enable(True) |
---|
[55bb249c] | 1910 | if self.data.dy == None or\ |
---|
| 1911 | (self.data.dy == 1).all() or\ |
---|
| 1912 | (self.data.dy == 0).all(): |
---|
| 1913 | self.dI_didata.Enable(False) |
---|
| 1914 | self.dI_noweight.SetValue(True) |
---|
| 1915 | self.weightbt_string = self.dI_noweight.GetLabelText() |
---|
| 1916 | else: |
---|
| 1917 | self.dI_didata.Enable(True) |
---|
| 1918 | self.dI_didata.SetValue(True) |
---|
| 1919 | self.weightbt_string = self.dI_didata.GetLabelText() |
---|
[308fa87] | 1920 | # Enable weighting radio uttons |
---|
| 1921 | self.dI_noweight.Enable(True) |
---|
[55bb249c] | 1922 | self.dI_sqrdata.Enable(True) |
---|
| 1923 | self.dI_idata.Enable(True) |
---|
[2f4b430] | 1924 | |
---|
[ea5fa58] | 1925 | self.formfactorbox.Enable() |
---|
[ffa69b6] | 1926 | self.structurebox.Enable() |
---|
[9237df4] | 1927 | data_name = self.data.name |
---|
[308fa87] | 1928 | _, _, npts = self.compute_data_range(self.data) |
---|
[9237df4] | 1929 | #set maximum range for x in linear scale |
---|
[308fa87] | 1930 | if not hasattr(self.data, "data"): # Display only for 1D data fit |
---|
| 1931 | self.btEditMask.Disable() |
---|
[19403da] | 1932 | self.EditMask_title.Disable() |
---|
[9237df4] | 1933 | else: |
---|
[308fa87] | 1934 | self.btEditMask.Enable() |
---|
| 1935 | self.EditMask_title.Enable() |
---|
[2f4b430] | 1936 | |
---|
[75daa79] | 1937 | self.Npts_total.SetValue(str(npts)) |
---|
| 1938 | #default:number of data points selected to fit |
---|
| 1939 | self.Npts_fit.SetValue(str(npts)) |
---|
[e9875db] | 1940 | self.Npts_total.SetEditable(False) |
---|
| 1941 | self.Npts_total.SetBackgroundColour(\ |
---|
| 1942 | self.GetParent().GetBackgroundColour()) |
---|
[2f4b430] | 1943 | |
---|
[bc0e08d] | 1944 | self.Npts_total.Bind(wx.EVT_MOUSE_EVENTS, self._npts_click) |
---|
[cb270ad2] | 1945 | self.pointsbox.Disable() |
---|
[9237df4] | 1946 | self.dataSource.SetValue(data_name) |
---|
[ffa69b6] | 1947 | self.state.data = data |
---|
[6ff97c5] | 1948 | self.enable_fit_button() |
---|
[308fa87] | 1949 | # send graph_id to page_finder |
---|
[5e48acb] | 1950 | self._manager.set_graph_id(uid=self.uid, graph_id=self.graph_id) |
---|
[dafc36f] | 1951 | #focus the page |
---|
| 1952 | if check_data_validity(data): |
---|
| 1953 | self.data_box_description.SetForegroundColour(wx.BLUE) |
---|
[2f4b430] | 1954 | |
---|
[1345f2f] | 1955 | if self.batch_on: |
---|
| 1956 | self.slit_smearer.Enable(False) |
---|
| 1957 | self.pinhole_smearer.Enable(False) |
---|
[308fa87] | 1958 | self.btEditMask.Disable() |
---|
[f3f6746] | 1959 | self.EditMask_title.Disable() |
---|
| 1960 | |
---|
[4679e16] | 1961 | self.on_set_focus(None) |
---|
[dafc36f] | 1962 | self.Refresh() |
---|
[6bbeacd4] | 1963 | #update model plot with new data information |
---|
| 1964 | if flag: |
---|
[e2f0554] | 1965 | #set model view button |
---|
[269df2b] | 1966 | if not self.enable_smearer.GetValue(): |
---|
| 1967 | self.disable_smearer.SetValue(True) |
---|
| 1968 | self.onSmear(None) |
---|
| 1969 | |
---|
[e2f0554] | 1970 | if self.data.__class__.__name__ == "Data2D": |
---|
| 1971 | self.enable2D = True |
---|
| 1972 | self.model_view.SetLabel("2D Mode") |
---|
| 1973 | else: |
---|
| 1974 | self.enable2D = False |
---|
| 1975 | self.model_view.SetLabel("1D Mode") |
---|
| 1976 | self.model_view.Disable() |
---|
[cc31608] | 1977 | #replace data plot on combo box selection |
---|
| 1978 | #by removing the previous selected data |
---|
[b11e127] | 1979 | try: |
---|
| 1980 | wx.PostEvent(self._manager.parent, |
---|
[ae84427] | 1981 | NewPlotEvent(action="delete", |
---|
[b11e127] | 1982 | group_id=old_group_id, id=old_id)) |
---|
| 1983 | except: |
---|
| 1984 | pass |
---|
[cc31608] | 1985 | #plot the current selected data |
---|
[308fa87] | 1986 | wx.PostEvent(self._manager.parent, |
---|
[940aca7] | 1987 | NewPlotEvent(action="check", plot=self.data, |
---|
[308fa87] | 1988 | title=str(self.data.title))) |
---|
[6bbeacd4] | 1989 | self._draw_model() |
---|
[2f4b430] | 1990 | |
---|
[e9875db] | 1991 | def _npts_click(self, event): |
---|
| 1992 | """ |
---|
| 1993 | Prevent further handling of the mouse event on Npts_total |
---|
| 1994 | by not calling Skip(). |
---|
[308fa87] | 1995 | """ |
---|
[e9875db] | 1996 | pass |
---|
[2f4b430] | 1997 | |
---|
[308fa87] | 1998 | def reset_page(self, state, first=False): |
---|
[a074145] | 1999 | """ |
---|
[5062bbf] | 2000 | reset the state |
---|
[a074145] | 2001 | """ |
---|
[ae4c139] | 2002 | try: |
---|
| 2003 | self.reset_page_helper(state) |
---|
[2f4b430] | 2004 | |
---|
[ae4c139] | 2005 | self.select_param(event=None) |
---|
| 2006 | #Save state_fit |
---|
| 2007 | self.save_current_state_fit() |
---|
| 2008 | except: |
---|
| 2009 | self._show_combox_helper() |
---|
| 2010 | msg = "Error: This model state has missing or outdated " |
---|
| 2011 | msg += "information.\n" |
---|
[2f4b430] | 2012 | msg += "%s" % (sys.exc_value) |
---|
[ae84427] | 2013 | wx.PostEvent(self._manager.parent, |
---|
[ae4c139] | 2014 | StatusEvent(status=msg, info="error")) |
---|
[7975f2b] | 2015 | self._lay_out() |
---|
[c985bef] | 2016 | self.Refresh() |
---|
[2f4b430] | 2017 | |
---|
[2140e68] | 2018 | def get_range(self): |
---|
| 2019 | """ |
---|
[5062bbf] | 2020 | return the fitting range |
---|
[2140e68] | 2021 | """ |
---|
[308fa87] | 2022 | return float(self.qmin_x), float(self.qmax_x) |
---|
[2f4b430] | 2023 | |
---|
[7975f2b] | 2024 | def get_npts2fit(self): |
---|
| 2025 | """ |
---|
[5062bbf] | 2026 | return numbers of data points within qrange |
---|
[2f4b430] | 2027 | |
---|
[386ffe1] | 2028 | :Note: This is to normalize chisq by Npts of fit |
---|
[2f4b430] | 2029 | |
---|
[7975f2b] | 2030 | """ |
---|
[6bbeacd4] | 2031 | if self.data is None: |
---|
| 2032 | return |
---|
[7975f2b] | 2033 | npts2fit = 0 |
---|
[308fa87] | 2034 | qmin, qmax = self.get_range() |
---|
[ba1f0b2] | 2035 | if self.data.__class__.__name__ == "Data2D" or \ |
---|
| 2036 | self.enable2D: |
---|
[308fa87] | 2037 | radius = numpy.sqrt(self.data.qx_data * self.data.qx_data + |
---|
| 2038 | self.data.qy_data * self.data.qy_data) |
---|
| 2039 | index_data = (self.qmin_x <= radius) & (radius <= self.qmax_x) |
---|
| 2040 | index_data = (index_data) & (self.data.mask) |
---|
| 2041 | index_data = (index_data) & (numpy.isfinite(self.data.data)) |
---|
[51a71a3] | 2042 | npts2fit = len(self.data.data[index_data]) |
---|
[7975f2b] | 2043 | else: |
---|
| 2044 | for qx in self.data.x: |
---|
[308fa87] | 2045 | if qx >= qmin and qx <= qmax: |
---|
| 2046 | npts2fit += 1 |
---|
[7975f2b] | 2047 | return npts2fit |
---|
| 2048 | |
---|
[bf5e985] | 2049 | def show_npts2fit(self): |
---|
[51a71a3] | 2050 | """ |
---|
[308fa87] | 2051 | setValue Npts for fitting |
---|
[51a71a3] | 2052 | """ |
---|
| 2053 | self.Npts_fit.SetValue(str(self.get_npts2fit())) |
---|
[2f4b430] | 2054 | |
---|
[c69b6d5] | 2055 | def get_chi2(self): |
---|
| 2056 | """ |
---|
[5062bbf] | 2057 | return the current chi2 |
---|
[c69b6d5] | 2058 | """ |
---|
[2012eae] | 2059 | return self.tcChi.GetValue() |
---|
[2f4b430] | 2060 | |
---|
[2296316] | 2061 | def onsetValues(self, chisqr, p_name, out, cov): |
---|
[c77d859] | 2062 | """ |
---|
[5062bbf] | 2063 | Build the panel from the fit result |
---|
[2f4b430] | 2064 | |
---|
[5062bbf] | 2065 | :param chisqr: Value of the goodness of fit metric |
---|
| 2066 | :param p_name: the name of parameters |
---|
| 2067 | :param out: list of parameter with the best value found during fitting |
---|
| 2068 | :param cov: Covariance matrix |
---|
[2f4b430] | 2069 | |
---|
[c77d859] | 2070 | """ |
---|
[2f4b430] | 2071 | |
---|
[80f56a3] | 2072 | # make sure stop button to fit button all the time |
---|
| 2073 | self._on_fit_complete() |
---|
[edd166b] | 2074 | if out == None or not numpy.isfinite(chisqr): |
---|
[ac2b835] | 2075 | raise ValueError, "Fit error occured..." |
---|
[2f4b430] | 2076 | |
---|
[edd166b] | 2077 | is_modified = False |
---|
[308fa87] | 2078 | has_error = False |
---|
| 2079 | dispersity = '' |
---|
[2f4b430] | 2080 | |
---|
[7975f2b] | 2081 | #Hide textctrl boxes of errors. |
---|
[308fa87] | 2082 | self._clear_Err_on_Fit() |
---|
[2f4b430] | 2083 | |
---|
[7975f2b] | 2084 | #Check if chi2 is finite |
---|
[2296316] | 2085 | if chisqr != None and numpy.isfinite(chisqr): |
---|
[308fa87] | 2086 | #format chi2 |
---|
| 2087 | chi2 = format_number(chisqr, True) |
---|
| 2088 | self.tcChi.SetValue(chi2) |
---|
| 2089 | self.tcChi.Refresh() |
---|
[7975f2b] | 2090 | else: |
---|
[2012eae] | 2091 | self.tcChi.SetValue("-") |
---|
[2f4b430] | 2092 | |
---|
[edd166b] | 2093 | #Hide error title |
---|
[ce92ded] | 2094 | if self.text2_3.IsShown() and not self.is_mac: |
---|
| 2095 | self.text2_3.Hide() |
---|
[2f4b430] | 2096 | |
---|
[e473e4f5] | 2097 | try: |
---|
[2296316] | 2098 | if self.enable_disp.GetValue(): |
---|
[308fa87] | 2099 | if hasattr(self, "text_disp_1"): |
---|
[ce92ded] | 2100 | if self.text_disp_1 != None and not self.is_mac: |
---|
[2296316] | 2101 | self.text_disp_1.Hide() |
---|
[e473e4f5] | 2102 | except: |
---|
[bd0a098e] | 2103 | dispersity = None |
---|
[e473e4f5] | 2104 | pass |
---|
[2f4b430] | 2105 | |
---|
[6a4002d] | 2106 | i = 0 |
---|
| 2107 | #Set the panel when fit result are list |
---|
[9e11cf5] | 2108 | |
---|
[308fa87] | 2109 | for item in self.param_toFit: |
---|
| 2110 | if len(item) > 5 and item != None: |
---|
[9e11cf5] | 2111 | |
---|
[940aca7] | 2112 | if item[0].IsShown(): |
---|
| 2113 | ## reset error value to initial state |
---|
| 2114 | if not self.is_mac: |
---|
| 2115 | item[3].Hide() |
---|
| 2116 | item[4].Hide() |
---|
| 2117 | for ind in range(len(out)): |
---|
| 2118 | if item[1] == p_name[ind]: |
---|
| 2119 | break |
---|
| 2120 | if len(out) > 0 and out[ind] != None: |
---|
| 2121 | val_out = format_number(out[ind], True) |
---|
| 2122 | item[2].SetValue(val_out) |
---|
[2f4b430] | 2123 | |
---|
[940aca7] | 2124 | if(cov != None and len(cov) == len(out)): |
---|
| 2125 | try: |
---|
| 2126 | if dispersity != None: |
---|
| 2127 | if self.enable_disp.GetValue(): |
---|
| 2128 | if hasattr(self, "text_disp_1"): |
---|
| 2129 | if self.text_disp_1 != None: |
---|
| 2130 | if not self.text_disp_1.IsShown()\ |
---|
| 2131 | and not self.is_mac: |
---|
| 2132 | self.text_disp_1.Show(True) |
---|
| 2133 | except: |
---|
| 2134 | pass |
---|
[2f4b430] | 2135 | |
---|
[940aca7] | 2136 | if cov[ind] != None: |
---|
| 2137 | if numpy.isfinite(float(cov[ind])): |
---|
| 2138 | val_err = format_number(cov[ind], True) |
---|
| 2139 | if not self.is_mac: |
---|
| 2140 | item[3].Show(True) |
---|
| 2141 | item[4].Show(True) |
---|
[9e11cf5] | 2142 | item[4].SetForegroundColour(wx.BLACK) |
---|
| 2143 | item[4].SetValue(val_err) |
---|
| 2144 | has_error = True |
---|
| 2145 | else: |
---|
| 2146 | val_err = 'NaN' |
---|
| 2147 | if not self.is_mac: |
---|
| 2148 | item[3].Show(True) |
---|
| 2149 | item[4].Show(True) |
---|
| 2150 | item[4].SetForegroundColour(wx.RED) |
---|
[940aca7] | 2151 | item[4].SetValue(val_err) |
---|
| 2152 | has_error = True |
---|
[308fa87] | 2153 | i += 1 |
---|
[940aca7] | 2154 | else: |
---|
| 2155 | raise ValueError, "onsetValues: Invalid parameters..." |
---|
[c99a6c5] | 2156 | #Show error title when any errors displayed |
---|
[308fa87] | 2157 | if has_error: |
---|
[c99a6c5] | 2158 | if not self.text2_3.IsShown(): |
---|
[308fa87] | 2159 | self.text2_3.Show(True) |
---|
| 2160 | ## save current state |
---|
| 2161 | self.save_current_state() |
---|
[2f4b430] | 2162 | |
---|
[3821f64] | 2163 | if not self.is_mac: |
---|
[308fa87] | 2164 | self.Layout() |
---|
| 2165 | self.Refresh() |
---|
| 2166 | self._mac_sleep(0.1) |
---|
[37290c4] | 2167 | #plot model ( when drawing, do not update chisqr value again) |
---|
[308fa87] | 2168 | self._draw_model(update_chisqr=False, source='fit') |
---|
[2f4b430] | 2169 | |
---|
[55bb249c] | 2170 | def onWeighting(self, event): |
---|
| 2171 | """ |
---|
| 2172 | On Weighting radio button event, sets the weightbt_string |
---|
| 2173 | """ |
---|
| 2174 | self.weightbt_string = event.GetEventObject().GetLabelText() |
---|
[3fb5e68] | 2175 | self._set_weight() |
---|
[2f4b430] | 2176 | |
---|
[3fb5e68] | 2177 | def _set_weight(self, is_2D=None): |
---|
| 2178 | """ |
---|
| 2179 | Set weight in fit problem |
---|
| 2180 | """ |
---|
[342dc442] | 2181 | # compute weight for the current data |
---|
[b9a5f0e] | 2182 | from sas.perspectives.fitting.utils import get_weight |
---|
[342dc442] | 2183 | flag_weight = self.get_weight_flag() |
---|
[3fb5e68] | 2184 | if is_2D == None: |
---|
| 2185 | is_2D = self._is_2D() |
---|
[308fa87] | 2186 | weight = get_weight(data=self.data, |
---|
| 2187 | is2d=is_2D, |
---|
[342dc442] | 2188 | flag=flag_weight) |
---|
[308fa87] | 2189 | self._manager.set_fit_weight(uid=self.uid, |
---|
| 2190 | flag=flag_weight, |
---|
| 2191 | is2d=is_2D, |
---|
[342dc442] | 2192 | fid=None) |
---|
[2f4b430] | 2193 | |
---|
[7609f1a] | 2194 | def onPinholeSmear(self, event): |
---|
| 2195 | """ |
---|
[5062bbf] | 2196 | Create a custom pinhole smear object that will change the way residuals |
---|
| 2197 | are compute when fitting |
---|
[2f4b430] | 2198 | |
---|
[5062bbf] | 2199 | :Note: accuracy is given by strings'High','Med', 'Low' FOR 2d, |
---|
| 2200 | None for 1D |
---|
[2f4b430] | 2201 | |
---|
[7609f1a] | 2202 | """ |
---|
[269df2b] | 2203 | if self.model == None: |
---|
[4470b10] | 2204 | self.disable_smearer.SetValue(True) |
---|
[269df2b] | 2205 | if event == None: |
---|
| 2206 | return |
---|
[308fa87] | 2207 | msg = "Please select a Model first..." |
---|
[4470b10] | 2208 | wx.MessageBox(msg, 'Info') |
---|
[308fa87] | 2209 | wx.PostEvent(self._manager.parent, |
---|
| 2210 | StatusEvent(status="Smear: %s" % msg)) |
---|
[7609f1a] | 2211 | return |
---|
[4470b10] | 2212 | |
---|
[2d409fa] | 2213 | # Need update param values |
---|
[308fa87] | 2214 | self._update_paramv_on_fit() |
---|
[f72333f] | 2215 | |
---|
[7609f1a] | 2216 | # msg default |
---|
| 2217 | msg = None |
---|
| 2218 | if event != None: |
---|
[308fa87] | 2219 | tcrtl = event.GetEventObject() |
---|
[7609f1a] | 2220 | # event case of radio button |
---|
[308fa87] | 2221 | if tcrtl.GetValue() == True: |
---|
[7609f1a] | 2222 | self.dx_min = 0.0 |
---|
| 2223 | self.dx_max = 0.0 |
---|
| 2224 | is_new_pinhole = True |
---|
| 2225 | else: |
---|
| 2226 | is_new_pinhole = self._is_changed_pinhole() |
---|
[d493f66] | 2227 | else: |
---|
[308fa87] | 2228 | is_new_pinhole = True |
---|
[7609f1a] | 2229 | # if any value is changed |
---|
| 2230 | if is_new_pinhole: |
---|
| 2231 | msg = self._set_pinhole_smear() |
---|
[308fa87] | 2232 | # hide all silt sizer |
---|
[7609f1a] | 2233 | self._hide_all_smear_info() |
---|
[2f4b430] | 2234 | |
---|
[308fa87] | 2235 | # show relevant slit sizers |
---|
[7609f1a] | 2236 | self._show_smear_sizer() |
---|
[f72333f] | 2237 | |
---|
[7609f1a] | 2238 | self.sizer_set_smearer.Layout() |
---|
[308fa87] | 2239 | self.Layout() |
---|
[2f4b430] | 2240 | |
---|
[308fa87] | 2241 | if event != None: |
---|
| 2242 | event.Skip() |
---|
[7609f1a] | 2243 | #self._undo.Enable(True) |
---|
| 2244 | self.save_current_state() |
---|
[308fa87] | 2245 | event = PageInfoEvent(page=self) |
---|
[7609f1a] | 2246 | wx.PostEvent(self.parent, event) |
---|
[2f4b430] | 2247 | |
---|
[308fa87] | 2248 | def _is_changed_pinhole(self): |
---|
[7609f1a] | 2249 | """ |
---|
[5062bbf] | 2250 | check if any of pinhole smear is changed |
---|
[2f4b430] | 2251 | |
---|
[5062bbf] | 2252 | :return: True or False |
---|
[2f4b430] | 2253 | |
---|
[7609f1a] | 2254 | """ |
---|
| 2255 | # get the values |
---|
| 2256 | pin_min = self.smear_pinhole_min.GetValue() |
---|
| 2257 | pin_max = self.smear_pinhole_max.GetValue() |
---|
[2f4b430] | 2258 | |
---|
[308fa87] | 2259 | # Check changes in slit width |
---|
[7609f1a] | 2260 | try: |
---|
| 2261 | dx_min = float(pin_min) |
---|
| 2262 | except: |
---|
| 2263 | return True |
---|
| 2264 | if self.dx_min != dx_min: |
---|
| 2265 | return True |
---|
[2f4b430] | 2266 | |
---|
[7609f1a] | 2267 | # Check changes in slit heigth |
---|
| 2268 | try: |
---|
| 2269 | dx_max = float(pin_max) |
---|
| 2270 | except: |
---|
| 2271 | return True |
---|
| 2272 | if self.dx_max != dx_max: |
---|
| 2273 | return True |
---|
| 2274 | return False |
---|
[2f4b430] | 2275 | |
---|
[7609f1a] | 2276 | def _set_pinhole_smear(self): |
---|
| 2277 | """ |
---|
[5062bbf] | 2278 | Set custom pinhole smear |
---|
[2f4b430] | 2279 | |
---|
[5062bbf] | 2280 | :return: msg |
---|
[2f4b430] | 2281 | |
---|
[7609f1a] | 2282 | """ |
---|
| 2283 | # copy data |
---|
| 2284 | data = copy.deepcopy(self.data) |
---|
[f72333f] | 2285 | if self._is_2D(): |
---|
| 2286 | self.smear_type = 'Pinhole2d' |
---|
| 2287 | len_data = len(data.data) |
---|
| 2288 | data.dqx_data = numpy.zeros(len_data) |
---|
| 2289 | data.dqy_data = numpy.zeros(len_data) |
---|
| 2290 | else: |
---|
| 2291 | self.smear_type = 'Pinhole' |
---|
| 2292 | len_data = len(data.x) |
---|
| 2293 | data.dx = numpy.zeros(len_data) |
---|
| 2294 | data.dxl = None |
---|
| 2295 | data.dxw = None |
---|
[7609f1a] | 2296 | msg = None |
---|
[2f4b430] | 2297 | |
---|
[7609f1a] | 2298 | get_pin_min = self.smear_pinhole_min |
---|
[308fa87] | 2299 | get_pin_max = self.smear_pinhole_max |
---|
[7609f1a] | 2300 | |
---|
[f72333f] | 2301 | if not check_float(get_pin_min): |
---|
| 2302 | get_pin_min.SetBackgroundColour("pink") |
---|
[308fa87] | 2303 | msg = "Model Error:wrong value entered!!!" |
---|
| 2304 | elif not check_float(get_pin_max): |
---|
[f72333f] | 2305 | get_pin_max.SetBackgroundColour("pink") |
---|
[308fa87] | 2306 | msg = "Model Error:wrong value entered!!!" |
---|
[f72333f] | 2307 | else: |
---|
[308fa87] | 2308 | if len_data < 2: |
---|
| 2309 | len_data = 2 |
---|
[7609f1a] | 2310 | self.dx_min = float(get_pin_min.GetValue()) |
---|
| 2311 | self.dx_max = float(get_pin_max.GetValue()) |
---|
[f72333f] | 2312 | if self.dx_min < 0: |
---|
| 2313 | get_pin_min.SetBackgroundColour("pink") |
---|
[308fa87] | 2314 | msg = "Model Error:This value can not be negative!!!" |
---|
| 2315 | elif self.dx_max < 0: |
---|
[f72333f] | 2316 | get_pin_max.SetBackgroundColour("pink") |
---|
[308fa87] | 2317 | msg = "Model Error:This value can not be negative!!!" |
---|
| 2318 | elif self.dx_min != None and self.dx_max != None: |
---|
[f72333f] | 2319 | if self._is_2D(): |
---|
[308fa87] | 2320 | data.dqx_data[data.dqx_data == 0] = self.dx_min |
---|
| 2321 | data.dqy_data[data.dqy_data == 0] = self.dx_max |
---|
[f72333f] | 2322 | elif self.dx_min == self.dx_max: |
---|
[308fa87] | 2323 | data.dx[data.dx == 0] = self.dx_min |
---|
| 2324 | else: |
---|
| 2325 | step = (self.dx_max - self.dx_min) / (len_data - 1) |
---|
| 2326 | data.dx = numpy.arange(self.dx_min, |
---|
| 2327 | self.dx_max + step / 1.1, |
---|
| 2328 | step) |
---|
| 2329 | elif self.dx_min != None: |
---|
| 2330 | if self._is_2D(): |
---|
| 2331 | data.dqx_data[data.dqx_data == 0] = self.dx_min |
---|
[7609f1a] | 2332 | else: |
---|
[308fa87] | 2333 | data.dx[data.dx == 0] = self.dx_min |
---|
[7609f1a] | 2334 | elif self.dx_max != None: |
---|
[308fa87] | 2335 | if self._is_2D(): |
---|
| 2336 | data.dqy_data[data.dqy_data == 0] = self.dx_max |
---|
| 2337 | else: |
---|
| 2338 | data.dx[data.dx == 0] = self.dx_max |
---|
[f867cd9] | 2339 | self.current_smearer = smear_selection(data, self.model) |
---|
[4fbc93e] | 2340 | # 2D need to set accuracy |
---|
[308fa87] | 2341 | if self._is_2D(): |
---|
[075d073] | 2342 | self.current_smearer.set_accuracy(accuracy=\ |
---|
| 2343 | self.smear2d_accuracy) |
---|
[7609f1a] | 2344 | |
---|
[f72333f] | 2345 | if msg != None: |
---|
[308fa87] | 2346 | wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) |
---|
[f72333f] | 2347 | else: |
---|
| 2348 | get_pin_min.SetBackgroundColour("white") |
---|
| 2349 | get_pin_max.SetBackgroundColour("white") |
---|
[7609f1a] | 2350 | ## set smearing value whether or not the data contain the smearing info |
---|
[2f4b430] | 2351 | |
---|
[6bbeacd4] | 2352 | self._manager.set_smearer(smearer=self.current_smearer, |
---|
[075d073] | 2353 | fid=self.data.id, |
---|
| 2354 | qmin=float(self.qmin_x), |
---|
| 2355 | qmax=float(self.qmax_x), |
---|
| 2356 | enable_smearer=not self.disable_smearer.GetValue(), |
---|
| 2357 | uid=self.uid) |
---|
[7609f1a] | 2358 | return msg |
---|
[2f4b430] | 2359 | |
---|
[7609f1a] | 2360 | def update_pinhole_smear(self): |
---|
| 2361 | """ |
---|
[5062bbf] | 2362 | called by kill_focus on pinhole TextCntrl |
---|
[308fa87] | 2363 | to update the changes |
---|
[2f4b430] | 2364 | |
---|
[5062bbf] | 2365 | :return: False when wrong value was entered |
---|
[2f4b430] | 2366 | |
---|
[7609f1a] | 2367 | """ |
---|
| 2368 | # msg default |
---|
| 2369 | msg = None |
---|
| 2370 | # check if any value is changed |
---|
| 2371 | if self._is_changed_pinhole(): |
---|
[308fa87] | 2372 | msg = self._set_pinhole_smear() |
---|
[1363416] | 2373 | wx.CallAfter(self.save_current_state) |
---|
[7609f1a] | 2374 | |
---|
| 2375 | if msg != None: |
---|
[308fa87] | 2376 | return False |
---|
[7609f1a] | 2377 | else: |
---|
| 2378 | return True |
---|
[2f4b430] | 2379 | |
---|
[7609f1a] | 2380 | def onSlitSmear(self, event): |
---|
| 2381 | """ |
---|
[5062bbf] | 2382 | Create a custom slit smear object that will change the way residuals |
---|
| 2383 | are compute when fitting |
---|
[7609f1a] | 2384 | """ |
---|
[269df2b] | 2385 | if self.model == None: |
---|
[4470b10] | 2386 | self.disable_smearer.SetValue(True) |
---|
[269df2b] | 2387 | if event == None: |
---|
| 2388 | return |
---|
[308fa87] | 2389 | msg = "Please select a Model first..." |
---|
[4470b10] | 2390 | wx.MessageBox(msg, 'Info') |
---|
[308fa87] | 2391 | wx.PostEvent(self._manager.parent, |
---|
| 2392 | StatusEvent(status="Smear: %s" % msg)) |
---|
[7609f1a] | 2393 | return |
---|
[4470b10] | 2394 | |
---|
[2d409fa] | 2395 | # Need update param values |
---|
| 2396 | self._update_paramv_on_fit() |
---|
[f72333f] | 2397 | |
---|
[7609f1a] | 2398 | # msg default |
---|
| 2399 | msg = None |
---|
| 2400 | # for event given |
---|
| 2401 | if event != None: |
---|
[308fa87] | 2402 | tcrtl = event.GetEventObject() |
---|
[7609f1a] | 2403 | # event case of radio button |
---|
| 2404 | if tcrtl.GetValue(): |
---|
| 2405 | self.dxl = 0.0 |
---|
| 2406 | self.dxw = 0.0 |
---|
| 2407 | is_new_slit = True |
---|
| 2408 | else: |
---|
| 2409 | is_new_slit = self._is_changed_slit() |
---|
[d493f66] | 2410 | else: |
---|
[308fa87] | 2411 | is_new_slit = True |
---|
[2f4b430] | 2412 | |
---|
[7609f1a] | 2413 | # if any value is changed |
---|
| 2414 | if is_new_slit: |
---|
| 2415 | msg = self._set_slit_smear() |
---|
[2f4b430] | 2416 | |
---|
[7609f1a] | 2417 | # hide all silt sizer |
---|
[308fa87] | 2418 | self._hide_all_smear_info() |
---|
| 2419 | # show relevant slit sizers |
---|
[7609f1a] | 2420 | self._show_smear_sizer() |
---|
| 2421 | self.sizer_set_smearer.Layout() |
---|
| 2422 | self.Layout() |
---|
[4470b10] | 2423 | |
---|
[7609f1a] | 2424 | if event != None: |
---|
[308fa87] | 2425 | event.Skip() |
---|
[7609f1a] | 2426 | self.save_current_state() |
---|
[308fa87] | 2427 | event = PageInfoEvent(page=self) |
---|
[7609f1a] | 2428 | wx.PostEvent(self.parent, event) |
---|
| 2429 | if msg != None: |
---|
[308fa87] | 2430 | wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) |
---|
[7609f1a] | 2431 | |
---|
[308fa87] | 2432 | def _is_changed_slit(self): |
---|
[7609f1a] | 2433 | """ |
---|
[5062bbf] | 2434 | check if any of slit lengths is changed |
---|
[2f4b430] | 2435 | |
---|
[5062bbf] | 2436 | :return: True or False |
---|
[2f4b430] | 2437 | |
---|
[5062bbf] | 2438 | """ |
---|
[7609f1a] | 2439 | # get the values |
---|
| 2440 | width = self.smear_slit_width.GetValue() |
---|
| 2441 | height = self.smear_slit_height.GetValue() |
---|
[2f4b430] | 2442 | |
---|
[308fa87] | 2443 | # check and change the box bg color if it was pink |
---|
[d7b7156] | 2444 | # but it should be white now |
---|
[7609f1a] | 2445 | # because this is the case that _set_slit_smear() will not handle |
---|
[308fa87] | 2446 | if height.lstrip().rstrip() == "": |
---|
[7609f1a] | 2447 | self.smear_slit_height.SetBackgroundColour(wx.WHITE) |
---|
[308fa87] | 2448 | if width.lstrip().rstrip() == "": |
---|
[7609f1a] | 2449 | self.smear_slit_width.SetBackgroundColour(wx.WHITE) |
---|
[2f4b430] | 2450 | |
---|
[308fa87] | 2451 | # Check changes in slit width |
---|
| 2452 | if width == "": |
---|
[7609f1a] | 2453 | dxw = 0.0 |
---|
| 2454 | else: |
---|
| 2455 | try: |
---|
| 2456 | dxw = float(width) |
---|
| 2457 | except: |
---|
| 2458 | return True |
---|
| 2459 | if self.dxw != dxw: |
---|
| 2460 | return True |
---|
[2f4b430] | 2461 | |
---|
[7609f1a] | 2462 | # Check changes in slit heigth |
---|
[308fa87] | 2463 | if height == "": |
---|
[7609f1a] | 2464 | dxl = 0.0 |
---|
| 2465 | else: |
---|
| 2466 | try: |
---|
| 2467 | dxl = float(height) |
---|
| 2468 | except: |
---|
| 2469 | return True |
---|
| 2470 | if self.dxl != dxl: |
---|
| 2471 | return True |
---|
[4470b10] | 2472 | |
---|
[7609f1a] | 2473 | return False |
---|
[2f4b430] | 2474 | |
---|
[7609f1a] | 2475 | def _set_slit_smear(self): |
---|
| 2476 | """ |
---|
[5062bbf] | 2477 | Set custom slit smear |
---|
[2f4b430] | 2478 | |
---|
[5062bbf] | 2479 | :return: message to inform the user about the validity |
---|
| 2480 | of the values entered for slit smear |
---|
[7609f1a] | 2481 | """ |
---|
[308fa87] | 2482 | if self.data.__class__.__name__ == "Data2D" or \ |
---|
[ba1f0b2] | 2483 | self.enable2D: |
---|
[0b12abb5] | 2484 | return |
---|
[7609f1a] | 2485 | # make sure once more if it is smearer |
---|
| 2486 | data = copy.deepcopy(self.data) |
---|
| 2487 | data_len = len(data.x) |
---|
| 2488 | data.dx = None |
---|
| 2489 | data.dxl = None |
---|
| 2490 | data.dxw = None |
---|
| 2491 | msg = None |
---|
[2f4b430] | 2492 | |
---|
[7609f1a] | 2493 | try: |
---|
| 2494 | self.dxl = float(self.smear_slit_height.GetValue()) |
---|
[308fa87] | 2495 | data.dxl = self.dxl * numpy.ones(data_len) |
---|
[7609f1a] | 2496 | self.smear_slit_height.SetBackgroundColour(wx.WHITE) |
---|
[308fa87] | 2497 | except: |
---|
[0d795bf] | 2498 | self.dxl = None |
---|
[7609f1a] | 2499 | data.dxl = numpy.zeros(data_len) |
---|
[308fa87] | 2500 | if self.smear_slit_height.GetValue().lstrip().rstrip() != "": |
---|
[7609f1a] | 2501 | self.smear_slit_height.SetBackgroundColour("pink") |
---|
[308fa87] | 2502 | msg = "Wrong value entered... " |
---|
[7609f1a] | 2503 | else: |
---|
| 2504 | self.smear_slit_height.SetBackgroundColour(wx.WHITE) |
---|
| 2505 | try: |
---|
| 2506 | self.dxw = float(self.smear_slit_width.GetValue()) |
---|
| 2507 | self.smear_slit_width.SetBackgroundColour(wx.WHITE) |
---|
[308fa87] | 2508 | data.dxw = self.dxw * numpy.ones(data_len) |
---|
| 2509 | except: |
---|
[0d795bf] | 2510 | self.dxw = None |
---|
[7609f1a] | 2511 | data.dxw = numpy.zeros(data_len) |
---|
[308fa87] | 2512 | if self.smear_slit_width.GetValue().lstrip().rstrip() != "": |
---|
[7609f1a] | 2513 | self.smear_slit_width.SetBackgroundColour("pink") |
---|
| 2514 | msg = "Wrong Fit value entered... " |
---|
| 2515 | else: |
---|
| 2516 | self.smear_slit_width.SetBackgroundColour(wx.WHITE) |
---|
[2f4b430] | 2517 | |
---|
[f867cd9] | 2518 | self.current_smearer = smear_selection(data, self.model) |
---|
[7609f1a] | 2519 | ## set smearing value whether or not the data contain the smearing info |
---|
[308fa87] | 2520 | self._manager.set_smearer(smearer=self.current_smearer, |
---|
[6ff97c5] | 2521 | fid=self.data.id, |
---|
[308fa87] | 2522 | qmin=float(self.qmin_x), |
---|
| 2523 | qmax=float(self.qmax_x), |
---|
[6ff97c5] | 2524 | enable_smearer=not self.disable_smearer.GetValue(), |
---|
[308fa87] | 2525 | uid=self.uid) |
---|
[7609f1a] | 2526 | return msg |
---|
[2f4b430] | 2527 | |
---|
[7609f1a] | 2528 | def update_slit_smear(self): |
---|
| 2529 | """ |
---|
[5062bbf] | 2530 | called by kill_focus on pinhole TextCntrl |
---|
[308fa87] | 2531 | to update the changes |
---|
[2f4b430] | 2532 | |
---|
[5062bbf] | 2533 | :return: False when wrong value was entered |
---|
[2f4b430] | 2534 | |
---|
[308fa87] | 2535 | """ |
---|
[7609f1a] | 2536 | # msg default |
---|
| 2537 | msg = None |
---|
| 2538 | # check if any value is changed |
---|
| 2539 | if self._is_changed_slit(): |
---|
[308fa87] | 2540 | msg = self._set_slit_smear() |
---|
[7609f1a] | 2541 | #self._undo.Enable(True) |
---|
| 2542 | self.save_current_state() |
---|
| 2543 | |
---|
| 2544 | if msg != None: |
---|
[308fa87] | 2545 | return False |
---|
[7609f1a] | 2546 | else: |
---|
| 2547 | return True |
---|
[2f4b430] | 2548 | |
---|
[c77d859] | 2549 | def onSmear(self, event): |
---|
| 2550 | """ |
---|
[5062bbf] | 2551 | Create a smear object that will change the way residuals |
---|
| 2552 | are compute when fitting |
---|
[c77d859] | 2553 | """ |
---|
[308fa87] | 2554 | if event != None: |
---|
| 2555 | event.Skip() |
---|
[6bbeacd4] | 2556 | if self.data is None: |
---|
[ffa69b6] | 2557 | return |
---|
[269df2b] | 2558 | |
---|
[64bda1e] | 2559 | if self.model == None: |
---|
[4470b10] | 2560 | self.disable_smearer.SetValue(True) |
---|
[269df2b] | 2561 | if event == None: |
---|
| 2562 | return |
---|
[308fa87] | 2563 | msg = "Please select a Model first..." |
---|
[4470b10] | 2564 | wx.MessageBox(msg, 'Info') |
---|
[308fa87] | 2565 | wx.PostEvent(self._manager.parent, |
---|
| 2566 | StatusEvent(status="Smear: %s" % msg)) |
---|
[2a2af47] | 2567 | return |
---|
[2d409fa] | 2568 | # Need update param values |
---|
| 2569 | self._update_paramv_on_fit() |
---|
[0617967b] | 2570 | if self.model != None: |
---|
| 2571 | if self.data.is_data: |
---|
[b0eeabf1] | 2572 | self._manager.page_finder[self.uid].add_data(data=self.data) |
---|
[308fa87] | 2573 | temp_smearer = self.on_smear_helper() |
---|
[2f4b430] | 2574 | |
---|
[33477fd] | 2575 | self.sizer_set_smearer.Layout() |
---|
| 2576 | self.Layout() |
---|
| 2577 | self._set_weight() |
---|
[2f4b430] | 2578 | |
---|
[33477fd] | 2579 | ## set smearing value whether or not the data contain the smearing info |
---|
[308fa87] | 2580 | wx.CallAfter(self._manager.set_smearer, uid=self.uid, |
---|
| 2581 | smearer=temp_smearer, |
---|
| 2582 | fid=self.data.id, |
---|
| 2583 | qmin=float(self.qmin_x), |
---|
| 2584 | qmax=float(self.qmax_x), |
---|
| 2585 | enable_smearer=not self.disable_smearer.GetValue(), |
---|
| 2586 | draw=True) |
---|
[2f4b430] | 2587 | |
---|
[308fa87] | 2588 | self.state.enable_smearer = self.enable_smearer.GetValue() |
---|
| 2589 | self.state.disable_smearer = self.disable_smearer.GetValue() |
---|
[33477fd] | 2590 | self.state.pinhole_smearer = self.pinhole_smearer.GetValue() |
---|
| 2591 | self.state.slit_smearer = self.slit_smearer.GetValue() |
---|
[2f4b430] | 2592 | |
---|
[33477fd] | 2593 | def on_smear_helper(self, update=False): |
---|
| 2594 | """ |
---|
| 2595 | Help for onSmear |
---|
[2f4b430] | 2596 | |
---|
[33477fd] | 2597 | :param update: force or not to update |
---|
| 2598 | """ |
---|
| 2599 | self._get_smear_info() |
---|
[7609f1a] | 2600 | #renew smear sizer |
---|
| 2601 | if self.smear_type != None: |
---|
| 2602 | self.smear_description_smear_type.SetValue(str(self.smear_type)) |
---|
[308fa87] | 2603 | self.smear_data_left.SetValue(str(self.dq_l)) |
---|
| 2604 | self.smear_data_right.SetValue(str(self.dq_r)) |
---|
[f72333f] | 2605 | |
---|
[7609f1a] | 2606 | self._hide_all_smear_info() |
---|
| 2607 | data = copy.deepcopy(self.data) |
---|
[2f4b430] | 2608 | |
---|
[7609f1a] | 2609 | # make sure once more if it is smearer |
---|
[2439c4c] | 2610 | temp_smearer = smear_selection(data, self.model) |
---|
[33477fd] | 2611 | if self.current_smearer != temp_smearer or update: |
---|
[2439c4c] | 2612 | self.current_smearer = temp_smearer |
---|
[c77d859] | 2613 | if self.enable_smearer.GetValue(): |
---|
[308fa87] | 2614 | if self.current_smearer == None: |
---|
| 2615 | wx.PostEvent(self._manager.parent, |
---|
[075d073] | 2616 | StatusEvent(status="Data contains no smearing information")) |
---|
[c77d859] | 2617 | else: |
---|
[308fa87] | 2618 | wx.PostEvent(self._manager.parent, |
---|
[075d073] | 2619 | StatusEvent(status="Data contains smearing information")) |
---|
[f72333f] | 2620 | |
---|
[7609f1a] | 2621 | self.smear_data_left.Show(True) |
---|
| 2622 | self.smear_data_right.Show(True) |
---|
[308fa87] | 2623 | temp_smearer = self.current_smearer |
---|
[7609f1a] | 2624 | elif self.disable_smearer.GetValue(): |
---|
| 2625 | self.smear_description_none.Show(True) |
---|
[2439c4c] | 2626 | elif self.pinhole_smearer.GetValue(): |
---|
| 2627 | self.onPinholeSmear(None) |
---|
| 2628 | elif self.slit_smearer.GetValue(): |
---|
| 2629 | self.onSlitSmear(None) |
---|
[7609f1a] | 2630 | self._show_smear_sizer() |
---|
[2f4b430] | 2631 | |
---|
[33477fd] | 2632 | return temp_smearer |
---|
[2f4b430] | 2633 | |
---|
[308fa87] | 2634 | def on_complete_chisqr(self, event): |
---|
[f72333f] | 2635 | """ |
---|
[6ff97c5] | 2636 | Display result chisqr on the panel |
---|
[5062bbf] | 2637 | :event: activated by fitting/ complete after draw |
---|
[f72333f] | 2638 | """ |
---|
| 2639 | try: |
---|
[06aa2eeb] | 2640 | if event == None: |
---|
[308fa87] | 2641 | output = "-" |
---|
[06aa2eeb] | 2642 | elif not numpy.isfinite(event.output): |
---|
[308fa87] | 2643 | output = "-" |
---|
[f72333f] | 2644 | else: |
---|
| 2645 | output = event.output |
---|
[2296316] | 2646 | self.tcChi.SetValue(str(format_number(output, True))) |
---|
[3c44c66] | 2647 | self.state.tcChi = self.tcChi.GetValue() |
---|
[f72333f] | 2648 | except: |
---|
[308fa87] | 2649 | pass |
---|
[2f4b430] | 2650 | |
---|
[934cfc03] | 2651 | def get_all_checked_params(self): |
---|
| 2652 | """ |
---|
[ac2b835] | 2653 | Found all parameters current check and add them to list of parameters |
---|
| 2654 | to fit |
---|
[934cfc03] | 2655 | """ |
---|
| 2656 | self.param_toFit = [] |
---|
| 2657 | for item in self.parameters: |
---|
| 2658 | if item[0].GetValue() and item not in self.param_toFit: |
---|
[940aca7] | 2659 | if item[0].IsShown(): |
---|
| 2660 | self.param_toFit.append(item) |
---|
[934cfc03] | 2661 | for item in self.fittable_param: |
---|
| 2662 | if item[0].GetValue() and item not in self.param_toFit: |
---|
[940aca7] | 2663 | if item[0].IsShown(): |
---|
| 2664 | self.param_toFit.append(item) |
---|
[308fa87] | 2665 | self.save_current_state_fit() |
---|
[2f4b430] | 2666 | |
---|
[308fa87] | 2667 | event = PageInfoEvent(page=self) |
---|
| 2668 | wx.PostEvent(self.parent, event) |
---|
[934cfc03] | 2669 | param2fit = [] |
---|
| 2670 | for item in self.param_toFit: |
---|
[940aca7] | 2671 | if item[0] and item[0].IsShown(): |
---|
[308fa87] | 2672 | param2fit.append(item[1]) |
---|
[ae84427] | 2673 | self._manager.set_param2fit(self.uid, param2fit) |
---|
[2f4b430] | 2674 | |
---|
[308fa87] | 2675 | def select_all_param(self, event): |
---|
[c77d859] | 2676 | """ |
---|
[5062bbf] | 2677 | set to true or false all checkBox given the main checkbox value cb1 |
---|
[308fa87] | 2678 | """ |
---|
[934cfc03] | 2679 | self.param_toFit = [] |
---|
[ac2b835] | 2680 | if self.parameters != []: |
---|
[998b6b8] | 2681 | if self.cb1.GetValue(): |
---|
[c77d859] | 2682 | for item in self.parameters: |
---|
[940aca7] | 2683 | if item[0].IsShown(): |
---|
| 2684 | ## for data2D select all to fit |
---|
| 2685 | if self.data.__class__.__name__ == "Data2D" or \ |
---|
| 2686 | self.enable2D: |
---|
[3fef0a8] | 2687 | item[0].SetValue(True) |
---|
[308fa87] | 2688 | self.param_toFit.append(item) |
---|
[940aca7] | 2689 | else: |
---|
| 2690 | ## for 1D all parameters except orientation |
---|
| 2691 | if not item in self.orientation_params: |
---|
| 2692 | item[0].SetValue(True) |
---|
| 2693 | self.param_toFit.append(item) |
---|
| 2694 | else: |
---|
| 2695 | item[0].SetValue(False) |
---|
[b324aa9] | 2696 | #if len(self.fittable_param)>0: |
---|
| 2697 | for item in self.fittable_param: |
---|
[940aca7] | 2698 | if item[0].IsShown(): |
---|
| 2699 | if self.data.__class__.__name__ == "Data2D" or \ |
---|
| 2700 | self.enable2D: |
---|
[3fef0a8] | 2701 | item[0].SetValue(True) |
---|
[308fa87] | 2702 | self.param_toFit.append(item) |
---|
[2296316] | 2703 | try: |
---|
| 2704 | if len(self.values[item[1]]) > 0: |
---|
| 2705 | item[0].SetValue(False) |
---|
| 2706 | except: |
---|
| 2707 | pass |
---|
[2f4b430] | 2708 | |
---|
[940aca7] | 2709 | else: |
---|
| 2710 | ## for 1D all parameters except orientation |
---|
| 2711 | if not item in self.orientation_params_disp: |
---|
| 2712 | item[0].SetValue(True) |
---|
| 2713 | self.param_toFit.append(item) |
---|
| 2714 | try: |
---|
| 2715 | if len(self.values[item[1]]) > 0: |
---|
| 2716 | item[0].SetValue(False) |
---|
| 2717 | except: |
---|
| 2718 | pass |
---|
| 2719 | else: |
---|
| 2720 | item[0].SetValue(False) |
---|
[2296316] | 2721 | |
---|
[c77d859] | 2722 | else: |
---|
| 2723 | for item in self.parameters: |
---|
| 2724 | item[0].SetValue(False) |
---|
| 2725 | for item in self.fittable_param: |
---|
| 2726 | item[0].SetValue(False) |
---|
[308fa87] | 2727 | self.param_toFit = [] |
---|
[2f4b430] | 2728 | |
---|
[308fa87] | 2729 | self.save_current_state_fit() |
---|
[2f4b430] | 2730 | |
---|
[308fa87] | 2731 | if event != None: |
---|
[3a37fe0] | 2732 | #self._undo.Enable(True) |
---|
[3595309d] | 2733 | ## post state to fit panel |
---|
[308fa87] | 2734 | event = PageInfoEvent(page=self) |
---|
| 2735 | wx.PostEvent(self.parent, event) |
---|
[1b14795] | 2736 | param2fit = [] |
---|
| 2737 | for item in self.param_toFit: |
---|
[940aca7] | 2738 | if item[0] and item[0].IsShown(): |
---|
[308fa87] | 2739 | param2fit.append(item[1]) |
---|
[1b14795] | 2740 | self.parent._manager.set_param2fit(self.uid, param2fit) |
---|
[2f4b430] | 2741 | |
---|
[ac2b835] | 2742 | def select_param(self, event): |
---|
| 2743 | """ |
---|
[5062bbf] | 2744 | Select TextCtrl checked for fitting purpose and stores them |
---|
| 2745 | in self.param_toFit=[] list |
---|
[c77d859] | 2746 | """ |
---|
[934cfc03] | 2747 | self.param_toFit = [] |
---|
[c77d859] | 2748 | for item in self.parameters: |
---|
[edd166b] | 2749 | #Skip t ifhe angle parameters if 1D data |
---|
[ba1f0b2] | 2750 | if self.data.__class__.__name__ != "Data2D" and\ |
---|
| 2751 | not self.enable2D: |
---|
[edd166b] | 2752 | if item in self.orientation_params: |
---|
| 2753 | continue |
---|
[c77d859] | 2754 | #Select parameters to fit for list of primary parameters |
---|
[940aca7] | 2755 | if item[0].GetValue() and item[0].IsShown(): |
---|
[c77d859] | 2756 | if not (item in self.param_toFit): |
---|
[308fa87] | 2757 | self.param_toFit.append(item) |
---|
[c77d859] | 2758 | else: |
---|
| 2759 | #remove parameters from the fitting list |
---|
| 2760 | if item in self.param_toFit: |
---|
| 2761 | self.param_toFit.remove(item) |
---|
[edd166b] | 2762 | |
---|
[308fa87] | 2763 | #Select parameters to fit for list of fittable parameters |
---|
| 2764 | # with dispersion |
---|
[c77d859] | 2765 | for item in self.fittable_param: |
---|
[edd166b] | 2766 | #Skip t ifhe angle parameters if 1D data |
---|
[308fa87] | 2767 | if self.data.__class__.__name__ != "Data2D" and\ |
---|
[ba1f0b2] | 2768 | not self.enable2D: |
---|
[edd166b] | 2769 | if item in self.orientation_params: |
---|
| 2770 | continue |
---|
[940aca7] | 2771 | if item[0].GetValue() and item[0].IsShown(): |
---|
[c77d859] | 2772 | if not (item in self.param_toFit): |
---|
[308fa87] | 2773 | self.param_toFit.append(item) |
---|
[c77d859] | 2774 | else: |
---|
| 2775 | #remove parameters from the fitting list |
---|
| 2776 | if item in self.param_toFit: |
---|
[edd166b] | 2777 | self.param_toFit.remove(item) |
---|
| 2778 | |
---|
[308fa87] | 2779 | #Calculate num. of angle parameters |
---|
| 2780 | if self.data.__class__.__name__ == "Data2D" or \ |
---|
[ba1f0b2] | 2781 | self.enable2D: |
---|
[edd166b] | 2782 | len_orient_para = 0 |
---|
| 2783 | else: |
---|
[308fa87] | 2784 | len_orient_para = len(self.orientation_params) # assume even len |
---|
[edd166b] | 2785 | #Total num. of angle parameters |
---|
| 2786 | if len(self.fittable_param) > 0: |
---|
| 2787 | len_orient_para *= 2 |
---|
[308fa87] | 2788 | #Set the value of checkbox that selected every checkbox or not |
---|
[ac2b835] | 2789 | if len(self.parameters) + len(self.fittable_param) - len_orient_para \ |
---|
| 2790 | == len(self.param_toFit): |
---|
[c77d859] | 2791 | self.cb1.SetValue(True) |
---|
| 2792 | else: |
---|
| 2793 | self.cb1.SetValue(False) |
---|
[2f4b430] | 2794 | |
---|
[52cac46] | 2795 | self.save_current_state_fit() |
---|
[308fa87] | 2796 | if event != None: |
---|
[3595309d] | 2797 | ## post state to fit panel |
---|
[308fa87] | 2798 | event = PageInfoEvent(page=self) |
---|
| 2799 | wx.PostEvent(self.parent, event) |
---|
[2f4b430] | 2800 | |
---|
[1b14795] | 2801 | param2fit = [] |
---|
| 2802 | for item in self.param_toFit: |
---|
[940aca7] | 2803 | if item[0] and item[0].IsShown(): |
---|
[308fa87] | 2804 | param2fit.append(item[1]) |
---|
[ae84427] | 2805 | self._manager.set_param2fit(self.uid, param2fit) |
---|
[2f4b430] | 2806 | |
---|
[77e23a2] | 2807 | def set_model_param_sizer(self, model): |
---|
[c77d859] | 2808 | """ |
---|
[5062bbf] | 2809 | Build the panel from the model content |
---|
[2f4b430] | 2810 | |
---|
[5062bbf] | 2811 | :param model: the model selected in combo box for fitting purpose |
---|
[2f4b430] | 2812 | |
---|
[c77d859] | 2813 | """ |
---|
| 2814 | self.sizer3.Clear(True) |
---|
| 2815 | self.parameters = [] |
---|
[fb59ed9] | 2816 | self.str_parameters = [] |
---|
[308fa87] | 2817 | self.param_toFit = [] |
---|
| 2818 | self.fittable_param = [] |
---|
| 2819 | self.fixed_param = [] |
---|
| 2820 | self.orientation_params = [] |
---|
| 2821 | self.orientation_params_disp = [] |
---|
[2f4b430] | 2822 | |
---|
[308fa87] | 2823 | if model == None: |
---|
[c77d859] | 2824 | self.sizer3.Layout() |
---|
[ce92ded] | 2825 | self.SetupScrolling() |
---|
[c77d859] | 2826 | return |
---|
[707436d] | 2827 | ## the panel is drawn using the current value of the fit engine |
---|
[ac2b835] | 2828 | if self.engine_type == None and self._manager != None: |
---|
| 2829 | self.engine_type = self._manager._return_engine_type() |
---|
[c99a6c5] | 2830 | |
---|
[ac2b835] | 2831 | box_description = wx.StaticBox(self, -1, str("Model Parameters")) |
---|
[c77d859] | 2832 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
[ac2b835] | 2833 | sizer = wx.GridBagSizer(5, 5) |
---|
[c77d859] | 2834 | ## save the current model |
---|
| 2835 | self.model = model |
---|
[2f4b430] | 2836 | |
---|
[c77d859] | 2837 | keys = self.model.getParamList() |
---|
[2f4b430] | 2838 | |
---|
[9e11cf5] | 2839 | #list of dispersion parameters |
---|
[ac2b835] | 2840 | self.disp_list = self.model.getDispParamList() |
---|
[b421b1a] | 2841 | |
---|
[ac2b835] | 2842 | def custom_compare(a, b): |
---|
[db08737] | 2843 | """ |
---|
| 2844 | Custom compare to order, first by alphabets then second by number. |
---|
[ac2b835] | 2845 | """ |
---|
[fb59ed9] | 2846 | # number at the last digit |
---|
[ac2b835] | 2847 | a_last = a[len(a) - 1] |
---|
| 2848 | b_last = b[len(b) - 1] |
---|
[fb59ed9] | 2849 | # default |
---|
[db08737] | 2850 | num_a = None |
---|
| 2851 | num_b = None |
---|
[fb59ed9] | 2852 | # split the names |
---|
| 2853 | a2 = a.lower().split('_') |
---|
| 2854 | b2 = b.lower().split('_') |
---|
| 2855 | # check length of a2, b2 |
---|
| 2856 | len_a2 = len(a2) |
---|
| 2857 | len_b2 = len(b2) |
---|
[db08737] | 2858 | # check if it contains a int number(<10) |
---|
[ac2b835] | 2859 | try: |
---|
[db08737] | 2860 | num_a = int(a_last) |
---|
[ac2b835] | 2861 | except: |
---|
| 2862 | pass |
---|
[db08737] | 2863 | try: |
---|
| 2864 | num_b = int(b_last) |
---|
[ac2b835] | 2865 | except: |
---|
| 2866 | pass |
---|
| 2867 | # Put 'scale' near the top; happens |
---|
[fb59ed9] | 2868 | # when numbered param name exists |
---|
| 2869 | if a == 'scale': |
---|
| 2870 | return -1 |
---|
[ac2b835] | 2871 | # both have a number |
---|
[db08737] | 2872 | if num_a != None and num_b != None: |
---|
[ac2b835] | 2873 | if num_a > num_b: |
---|
| 2874 | return -1 |
---|
[fb59ed9] | 2875 | # same number |
---|
[ac2b835] | 2876 | elif num_a == num_b: |
---|
[fb59ed9] | 2877 | # different last names |
---|
[ac2b835] | 2878 | if a2[len_a2 - 1] != b2[len_b2 - 1] and num_a != 0: |
---|
| 2879 | return -cmp(a2[len_a2 - 1], b2[len_b2 - 1]) |
---|
| 2880 | else: |
---|
| 2881 | return cmp(a, b) |
---|
| 2882 | else: |
---|
| 2883 | return 1 |
---|
[db08737] | 2884 | # one of them has a number |
---|
[ac2b835] | 2885 | elif num_a != None: |
---|
| 2886 | return 1 |
---|
| 2887 | elif num_b != None: |
---|
| 2888 | return -1 |
---|
[fb59ed9] | 2889 | # no numbers |
---|
[ac2b835] | 2890 | else: |
---|
| 2891 | return cmp(a.lower(), b.lower()) |
---|
[fb59ed9] | 2892 | |
---|
[db08737] | 2893 | keys.sort(custom_compare) |
---|
[2f4b430] | 2894 | |
---|
[6dc9ad8] | 2895 | iy = 0 |
---|
[c77d859] | 2896 | ix = 0 |
---|
[2f6c260] | 2897 | select_text = "Select All" |
---|
[ac2b835] | 2898 | self.cb1 = wx.CheckBox(self, -1, str(select_text), (10, 10)) |
---|
[c77d859] | 2899 | wx.EVT_CHECKBOX(self, self.cb1.GetId(), self.select_all_param) |
---|
[2f6c260] | 2900 | self.cb1.SetToolTipString("To check/uncheck all the boxes below.") |
---|
[ecfcef6] | 2901 | self.cb1.SetValue(True) |
---|
[2f4b430] | 2902 | |
---|
[075d073] | 2903 | sizer.Add(self.cb1, (iy, ix), (1, 1), \ |
---|
[ac2b835] | 2904 | wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 5) |
---|
| 2905 | ix += 1 |
---|
[f56bf29] | 2906 | self.text2_2 = wx.StaticText(self, -1, 'Value') |
---|
[ac2b835] | 2907 | sizer.Add(self.text2_2, (iy, ix), (1, 1), \ |
---|
| 2908 | wx.EXPAND | wx.ADJUST_MINSIZE, 0) |
---|
| 2909 | ix += 2 |
---|
[f56bf29] | 2910 | self.text2_3 = wx.StaticText(self, -1, 'Error') |
---|
[ac2b835] | 2911 | sizer.Add(self.text2_3, (iy, ix), (1, 1), \ |
---|
| 2912 | wx.EXPAND | wx.ADJUST_MINSIZE, 0) |
---|
[3821f64] | 2913 | if not self.is_mac: |
---|
| 2914 | self.text2_3.Hide() |
---|
[ac2b835] | 2915 | ix += 1 |
---|
[c77d859] | 2916 | self.text2_min = wx.StaticText(self, -1, 'Min') |
---|
[ac2b835] | 2917 | sizer.Add(self.text2_min, (iy, ix), (1, 1), \ |
---|
| 2918 | wx.EXPAND | wx.ADJUST_MINSIZE, 0) |
---|
[2296316] | 2919 | #self.text2_min.Hide() |
---|
[ac2b835] | 2920 | ix += 1 |
---|
[c77d859] | 2921 | self.text2_max = wx.StaticText(self, -1, 'Max') |
---|
[ac2b835] | 2922 | sizer.Add(self.text2_max, (iy, ix), (1, 1), \ |
---|
| 2923 | wx.EXPAND | wx.ADJUST_MINSIZE, 0) |
---|
[2296316] | 2924 | #self.text2_max.Hide() |
---|
[6fdfc8f] | 2925 | ix += 1 |
---|
| 2926 | self.text2_4 = wx.StaticText(self, -1, '[Units]') |
---|
[ac2b835] | 2927 | sizer.Add(self.text2_4, (iy, ix), (1, 1), \ |
---|
| 2928 | wx.EXPAND | wx.ADJUST_MINSIZE, 0) |
---|
[6fdfc8f] | 2929 | self.text2_4.Hide() |
---|
[2f4b430] | 2930 | |
---|
[934cfc03] | 2931 | CHECK_STATE = self.cb1.GetValue() |
---|
[c77d859] | 2932 | for item in keys: |
---|
[2f4b430] | 2933 | |
---|
[d7b7156] | 2934 | if not item in self.disp_list and not item in \ |
---|
| 2935 | self.model.orientation_params: |
---|
[2f4b430] | 2936 | |
---|
[b421b1a] | 2937 | ##prepare a spot to store errors |
---|
[ac2b835] | 2938 | if not item in self.model.details: |
---|
| 2939 | self.model.details[item] = ["", None, None] |
---|
[2f4b430] | 2940 | |
---|
[c77d859] | 2941 | iy += 1 |
---|
| 2942 | ix = 0 |
---|
[8960479] | 2943 | if (self.model.__class__ in \ |
---|
| 2944 | self.model_list_box["Multi-Functions"] or \ |
---|
| 2945 | self.temp_multi_functional)\ |
---|
| 2946 | and (item in self.model.non_fittable): |
---|
[ac2b835] | 2947 | non_fittable_name = wx.StaticText(self, -1, item) |
---|
| 2948 | sizer.Add(non_fittable_name, (iy, ix), (1, 1), \ |
---|
| 2949 | wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 21) |
---|
[fb59ed9] | 2950 | ## add parameter value |
---|
| 2951 | ix += 1 |
---|
[ac2b835] | 2952 | value = self.model.getParam(item) |
---|
[fb59ed9] | 2953 | if len(self.model.fun_list) > 0: |
---|
[ac2b835] | 2954 | #num = item.split('_')[1][5:7] |
---|
| 2955 | fun_box = wx.ComboBox(self, -1, size=(100, -1), |
---|
| 2956 | style=wx.CB_READONLY, name='%s' % item) |
---|
[fb59ed9] | 2957 | self._set_fun_box_list(fun_box) |
---|
| 2958 | fun_box.SetSelection(0) |
---|
[ac2b835] | 2959 | #self.fun_box.SetToolTipString("A function |
---|
[d7b7156] | 2960 | # describing the interface") |
---|
[ac2b835] | 2961 | wx.EVT_COMBOBOX(fun_box, -1, self._on_fun_box) |
---|
[fb59ed9] | 2962 | else: |
---|
[ac2b835] | 2963 | fun_box = self.ModelTextCtrl(self, -1, |
---|
| 2964 | size=(_BOX_WIDTH, 20), |
---|
| 2965 | style=wx.TE_PROCESS_ENTER, name='%s' % item) |
---|
[6721b75] | 2966 | fun_box.SetToolTipString(\ |
---|
| 2967 | "Hit 'Enter' after typing to update the plot.") |
---|
[2296316] | 2968 | fun_box.SetValue(format_number(value, True)) |
---|
[ac2b835] | 2969 | sizer.Add(fun_box, (iy, ix), (1, 1), wx.EXPAND) |
---|
| 2970 | self.str_parameters.append([None, item, fun_box, |
---|
| 2971 | None, None, None, |
---|
[2296316] | 2972 | None, None]) |
---|
[7975f2b] | 2973 | else: |
---|
[fb59ed9] | 2974 | ## add parameters name with checkbox for selecting to fit |
---|
[ac2b835] | 2975 | cb = wx.CheckBox(self, -1, item) |
---|
| 2976 | cb.SetValue(CHECK_STATE) |
---|
[2296316] | 2977 | cb.SetToolTipString(" Check mark to fit.") |
---|
[fb59ed9] | 2978 | #cb.SetValue(True) |
---|
| 2979 | wx.EVT_CHECKBOX(self, cb.GetId(), self.select_param) |
---|
[2f4b430] | 2980 | |
---|
[ac2b835] | 2981 | sizer.Add(cb, (iy, ix), (1, 1), |
---|
| 2982 | wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 5) |
---|
[fb59ed9] | 2983 | |
---|
| 2984 | ## add parameter value |
---|
| 2985 | ix += 1 |
---|
[ac2b835] | 2986 | value = self.model.getParam(item) |
---|
| 2987 | ctl1 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH, 20), |
---|
[fb59ed9] | 2988 | style=wx.TE_PROCESS_ENTER) |
---|
[6721b75] | 2989 | ctl1.SetToolTipString(\ |
---|
| 2990 | "Hit 'Enter' after typing to update the plot.") |
---|
[2296316] | 2991 | ctl1.SetValue(format_number(value, True)) |
---|
[ac2b835] | 2992 | sizer.Add(ctl1, (iy, ix), (1, 1), wx.EXPAND) |
---|
[fb59ed9] | 2993 | ## text to show error sign |
---|
| 2994 | ix += 1 |
---|
[ac2b835] | 2995 | text2 = wx.StaticText(self, -1, '+/-') |
---|
| 2996 | sizer.Add(text2, (iy, ix), (1, 1), \ |
---|
| 2997 | wx.EXPAND | wx.ADJUST_MINSIZE, 0) |
---|
[ce92ded] | 2998 | if not self.is_mac: |
---|
[ac2b835] | 2999 | text2.Hide() |
---|
[fb59ed9] | 3000 | ix += 1 |
---|
[ac2b835] | 3001 | ctl2 = wx.TextCtrl(self, -1, |
---|
| 3002 | size=(_BOX_WIDTH / 1.2, 20), style=0) |
---|
| 3003 | sizer.Add(ctl2, (iy, ix), (1, 1), |
---|
| 3004 | wx.EXPAND | wx.ADJUST_MINSIZE, 0) |
---|
[ce92ded] | 3005 | if not self.is_mac: |
---|
| 3006 | ctl2.Hide() |
---|
[22ae2f7] | 3007 | |
---|
[fb59ed9] | 3008 | ix += 1 |
---|
[ac2b835] | 3009 | ctl3 = self.ModelTextCtrl(self, -1, |
---|
| 3010 | size=(_BOX_WIDTH / 1.9, 20), |
---|
| 3011 | style=wx.TE_PROCESS_ENTER, |
---|
| 3012 | text_enter_callback=self._onparamRangeEnter) |
---|
[22ae2f7] | 3013 | min_bound = self.model.details[item][1] |
---|
| 3014 | if min_bound is not None: |
---|
| 3015 | ctl3.SetValue(format_number(min_bound, True)) |
---|
| 3016 | |
---|
[ac2b835] | 3017 | sizer.Add(ctl3, (iy, ix), (1, 1), |
---|
| 3018 | wx.EXPAND | wx.ADJUST_MINSIZE, 0) |
---|
[2f4b430] | 3019 | |
---|
[fb59ed9] | 3020 | ix += 1 |
---|
[ac2b835] | 3021 | ctl4 = self.ModelTextCtrl(self, -1, |
---|
| 3022 | size=(_BOX_WIDTH / 1.9, 20), |
---|
| 3023 | style=wx.TE_PROCESS_ENTER, |
---|
| 3024 | text_enter_callback=self._onparamRangeEnter) |
---|
[22ae2f7] | 3025 | max_bound = self.model.details[item][2] |
---|
| 3026 | if max_bound is not None: |
---|
| 3027 | ctl4.SetValue(format_number(max_bound, True)) |
---|
[ac2b835] | 3028 | sizer.Add(ctl4, (iy, ix), (1, 1), |
---|
| 3029 | wx.EXPAND | wx.FIXED_MINSIZE, 0) |
---|
[2f4b430] | 3030 | |
---|
[ac2b835] | 3031 | ix += 1 |
---|
[fb59ed9] | 3032 | # Units |
---|
[ac2b835] | 3033 | if item in self.model.details: |
---|
| 3034 | units = wx.StaticText(self, -1, |
---|
[d7b7156] | 3035 | self.model.details[item][0], style=wx.ALIGN_LEFT) |
---|
[fb59ed9] | 3036 | else: |
---|
[ac2b835] | 3037 | units = wx.StaticText(self, -1, "", |
---|
| 3038 | style=wx.ALIGN_LEFT) |
---|
| 3039 | sizer.Add(units, (iy, ix), (1, 1), |
---|
| 3040 | wx.EXPAND | wx.ADJUST_MINSIZE, 0) |
---|
[2f4b430] | 3041 | |
---|
[ac2b835] | 3042 | self.parameters.append([cb, item, ctl1, |
---|
| 3043 | text2, ctl2, ctl3, ctl4, units]) |
---|
[2f4b430] | 3044 | |
---|
[ac2b835] | 3045 | iy += 1 |
---|
| 3046 | sizer.Add((10, 10), (iy, ix), (1, 1), |
---|
| 3047 | wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) |
---|
[2f4b430] | 3048 | |
---|
[f20767b] | 3049 | # type can be either Guassian or Array |
---|
[ac2b835] | 3050 | if len(self.model.dispersion.values()) > 0: |
---|
| 3051 | type = self.model.dispersion.values()[0]["type"] |
---|
[5b53a5c] | 3052 | else: |
---|
| 3053 | type = "Gaussian" |
---|
[2f4b430] | 3054 | |
---|
[6dc9ad8] | 3055 | iy += 1 |
---|
| 3056 | ix = 0 |
---|
| 3057 | #Add tile for orientational angle |
---|
| 3058 | for item in keys: |
---|
[ac2b835] | 3059 | if item in self.model.orientation_params: |
---|
[6dc9ad8] | 3060 | orient_angle = wx.StaticText(self, -1, '[For 2D only]:') |
---|
[2f4b430] | 3061 | mag_on_button = wx.Button(self, -1, "Magnetic ON") |
---|
[318b5bbb] | 3062 | mag_on_button.Bind(wx.EVT_BUTTON, self._on_mag_on) |
---|
[2f4b430] | 3063 | mag_help_button = wx.Button(self, -1, "Magnetic angles?") |
---|
| 3064 | mag_help_button.Bind(wx.EVT_BUTTON, self._on_mag_help) |
---|
[ac2b835] | 3065 | sizer.Add(orient_angle, (iy, ix), (1, 1), |
---|
| 3066 | wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) |
---|
[318b5bbb] | 3067 | iy += 1 |
---|
[2f4b430] | 3068 | sizer.Add(mag_on_button, (iy, ix), (1, 1), |
---|
| 3069 | wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) |
---|
| 3070 | sizer.Add(mag_help_button, (iy, ix + 1), (1, 1), |
---|
| 3071 | wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) |
---|
| 3072 | |
---|
[318b5bbb] | 3073 | #handle the magnetic buttons |
---|
| 3074 | if not self._has_magnetic: |
---|
| 3075 | mag_on_button.Show(False) |
---|
| 3076 | elif not self.data.__class__.__name__ == "Data2D": |
---|
| 3077 | mag_on_button.Show(False) |
---|
| 3078 | else: |
---|
| 3079 | mag_on_button.Show(True) |
---|
| 3080 | mag_help_button.Show(False) |
---|
| 3081 | if mag_on_button.IsShown(): |
---|
| 3082 | if self.magnetic_on: |
---|
| 3083 | mag_on_button.SetLabel("Magnetic OFF") |
---|
[2f4b430] | 3084 | mag_help_button.Show(True) |
---|
[318b5bbb] | 3085 | else: |
---|
| 3086 | mag_on_button.SetLabel("Magnetic ON") |
---|
| 3087 | mag_help_button.Show(False) |
---|
[2f4b430] | 3088 | |
---|
[ba1f0b2] | 3089 | if not self.data.__class__.__name__ == "Data2D" and \ |
---|
| 3090 | not self.enable2D: |
---|
[6dc9ad8] | 3091 | orient_angle.Hide() |
---|
| 3092 | else: |
---|
| 3093 | orient_angle.Show(True) |
---|
| 3094 | break |
---|
[2f4b430] | 3095 | |
---|
[f20767b] | 3096 | #For Gaussian only |
---|
| 3097 | if type.lower() != "array": |
---|
| 3098 | for item in self.model.orientation_params: |
---|
[318b5bbb] | 3099 | if not self.magnetic_on: |
---|
| 3100 | if item in self.model.magnetic_params: |
---|
| 3101 | continue |
---|
[f20767b] | 3102 | if not item in self.disp_list: |
---|
[c13b8cc] | 3103 | ##prepare a spot to store min max |
---|
[ac2b835] | 3104 | if not item in self.model.details: |
---|
| 3105 | self.model.details[item] = ["", None, None] |
---|
[2f4b430] | 3106 | |
---|
[f20767b] | 3107 | iy += 1 |
---|
| 3108 | ix = 0 |
---|
| 3109 | ## add parameters name with checkbox for selecting to fit |
---|
[ac2b835] | 3110 | cb = wx.CheckBox(self, -1, item) |
---|
[934cfc03] | 3111 | cb.SetValue(CHECK_STATE) |
---|
[2296316] | 3112 | cb.SetToolTipString("Check mark to fit") |
---|
[f20767b] | 3113 | wx.EVT_CHECKBOX(self, cb.GetId(), self.select_param) |
---|
[ba1f0b2] | 3114 | if self.data.__class__.__name__ == "Data2D" or \ |
---|
| 3115 | self.enable2D: |
---|
[6dc9ad8] | 3116 | cb.Show(True) |
---|
[f20767b] | 3117 | else: |
---|
[6dc9ad8] | 3118 | cb.Hide() |
---|
[ac2b835] | 3119 | sizer.Add(cb, (iy, ix), (1, 1), |
---|
| 3120 | wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 5) |
---|
[2f4b430] | 3121 | |
---|
[f20767b] | 3122 | ## add parameter value |
---|
| 3123 | ix += 1 |
---|
[ac2b835] | 3124 | value = self.model.getParam(item) |
---|
| 3125 | ctl1 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH, 20), |
---|
[f20767b] | 3126 | style=wx.TE_PROCESS_ENTER) |
---|
[6721b75] | 3127 | ctl1.SetToolTipString(\ |
---|
| 3128 | "Hit 'Enter' after typing to update the plot.") |
---|
[2296316] | 3129 | ctl1.SetValue(format_number(value, True)) |
---|
[ba1f0b2] | 3130 | if self.data.__class__.__name__ == "Data2D" or \ |
---|
| 3131 | self.enable2D: |
---|
[c5cd3b9] | 3132 | ctl1.Show(True) |
---|
[f20767b] | 3133 | else: |
---|
[c5cd3b9] | 3134 | ctl1.Hide() |
---|
[ac2b835] | 3135 | sizer.Add(ctl1, (iy, ix), (1, 1), wx.EXPAND) |
---|
[f20767b] | 3136 | ## text to show error sign |
---|
| 3137 | ix += 1 |
---|
[ac2b835] | 3138 | text2 = wx.StaticText(self, -1, '+/-') |
---|
| 3139 | sizer.Add(text2, (iy, ix), (1, 1), \ |
---|
| 3140 | wx.EXPAND | wx.ADJUST_MINSIZE, 0) |
---|
[e792aee] | 3141 | |
---|
[ac2b835] | 3142 | text2.Hide() |
---|
[f20767b] | 3143 | ix += 1 |
---|
[ac2b835] | 3144 | ctl2 = wx.TextCtrl(self, -1, |
---|
| 3145 | size=(_BOX_WIDTH / 1.2, 20), style=0) |
---|
| 3146 | sizer.Add(ctl2, (iy, ix), (1, 1), |
---|
| 3147 | wx.EXPAND | wx.ADJUST_MINSIZE, 0) |
---|
[e792aee] | 3148 | |
---|
| 3149 | ctl2.Hide() |
---|
[2f4b430] | 3150 | |
---|
[f20767b] | 3151 | ix += 1 |
---|
[ac2b835] | 3152 | ctl3 = self.ModelTextCtrl(self, -1, |
---|
| 3153 | size=(_BOX_WIDTH / 1.8, 20), |
---|
[d7b7156] | 3154 | style=wx.TE_PROCESS_ENTER, |
---|
[ac2b835] | 3155 | text_enter_callback=self._onparamRangeEnter) |
---|
[2f4b430] | 3156 | |
---|
[ac2b835] | 3157 | sizer.Add(ctl3, (iy, ix), (1, 1), |
---|
| 3158 | wx.EXPAND | wx.ADJUST_MINSIZE, 0) |
---|
[f20767b] | 3159 | ctl3.Hide() |
---|
[2f4b430] | 3160 | |
---|
[f20767b] | 3161 | ix += 1 |
---|
[ac2b835] | 3162 | ctl4 = self.ModelTextCtrl(self, -1, |
---|
| 3163 | size=(_BOX_WIDTH / 1.8, 20), |
---|
| 3164 | style=wx.TE_PROCESS_ENTER, |
---|
| 3165 | text_enter_callback=self._onparamRangeEnter) |
---|
| 3166 | sizer.Add(ctl4, (iy, ix), (1, 1), |
---|
| 3167 | wx.EXPAND | wx.ADJUST_MINSIZE, 0) |
---|
[2f4b430] | 3168 | |
---|
[f20767b] | 3169 | ctl4.Hide() |
---|
[2f4b430] | 3170 | |
---|
[ba1f0b2] | 3171 | if self.data.__class__.__name__ == "Data2D" or \ |
---|
[ac2b835] | 3172 | self.enable2D: |
---|
| 3173 | if self.is_mac: |
---|
[1180528] | 3174 | text2.Show(True) |
---|
[ac2b835] | 3175 | ctl2.Show(True) |
---|
[f20767b] | 3176 | ctl3.Show(True) |
---|
| 3177 | ctl4.Show(True) |
---|
[2f4b430] | 3178 | |
---|
[ac2b835] | 3179 | ix += 1 |
---|
[f20767b] | 3180 | # Units |
---|
[ac2b835] | 3181 | if item in self.model.details: |
---|
| 3182 | units = wx.StaticText(self, -1, |
---|
| 3183 | self.model.details[item][0], |
---|
[d7b7156] | 3184 | style=wx.ALIGN_LEFT) |
---|
[7975f2b] | 3185 | else: |
---|
[ac2b835] | 3186 | units = wx.StaticText(self, -1, "", |
---|
| 3187 | style=wx.ALIGN_LEFT) |
---|
[ba1f0b2] | 3188 | if self.data.__class__.__name__ == "Data2D" or \ |
---|
| 3189 | self.enable2D: |
---|
[6dc9ad8] | 3190 | units.Show(True) |
---|
[f20767b] | 3191 | else: |
---|
[6dc9ad8] | 3192 | units.Hide() |
---|
[2f4b430] | 3193 | |
---|
[ac2b835] | 3194 | sizer.Add(units, (iy, ix), (1, 1), |
---|
| 3195 | wx.EXPAND | wx.ADJUST_MINSIZE, 0) |
---|
[2f4b430] | 3196 | |
---|
[ac2b835] | 3197 | self.parameters.append([cb, item, ctl1, |
---|
| 3198 | text2, ctl2, ctl3, ctl4, units]) |
---|
| 3199 | self.orientation_params.append([cb, item, ctl1, |
---|
| 3200 | text2, ctl2, ctl3, ctl4, units]) |
---|
[2f4b430] | 3201 | |
---|
[ac2b835] | 3202 | iy += 1 |
---|
[abba643] | 3203 | box_description.SetForegroundColour(wx.BLUE) |
---|
[c77d859] | 3204 | #Display units text on panel |
---|
[ac2b835] | 3205 | for item in keys: |
---|
| 3206 | if item in self.model.details: |
---|
[c77d859] | 3207 | self.text2_4.Show() |
---|
[b324aa9] | 3208 | #Fill the list of fittable parameters |
---|
[934cfc03] | 3209 | self.get_all_checked_params() |
---|
[52cac46] | 3210 | self.save_current_state_fit() |
---|
[240b9966] | 3211 | boxsizer1.Add(sizer) |
---|
[ac2b835] | 3212 | self.sizer3.Add(boxsizer1, 0, wx.EXPAND | wx.ALL, 10) |
---|
[c77d859] | 3213 | self.sizer3.Layout() |
---|
[330573d] | 3214 | self.Layout() |
---|
[70468a5] | 3215 | |
---|
[2296316] | 3216 | def on_right_down(self, event): |
---|
| 3217 | """ |
---|
| 3218 | Get key stroke event |
---|
| 3219 | """ |
---|
| 3220 | if self.data == None: |
---|
| 3221 | return |
---|
| 3222 | # Figuring out key combo: Cmd for copy, Alt for paste |
---|
| 3223 | if event.AltDown() and event.ShiftDown(): |
---|
| 3224 | flag = True |
---|
[1b1bbf9] | 3225 | elif event.AltDown() or event.ShiftDown(): |
---|
[2296316] | 3226 | flag = False |
---|
[1b1bbf9] | 3227 | else: |
---|
| 3228 | return |
---|
[2296316] | 3229 | # make event free |
---|
| 3230 | event.Skip() |
---|
| 3231 | # messages depending on the flag |
---|
| 3232 | if not flag: |
---|
| 3233 | infor = 'warning' |
---|
| 3234 | # inform msg to wx |
---|
[ae84427] | 3235 | wx.PostEvent(self._manager.parent, |
---|
[ac2b835] | 3236 | StatusEvent(status=msg, info=infor)) |
---|
[2f4b430] | 3237 | |
---|
[8b6f489] | 3238 | def _onModel2D(self, event): |
---|
| 3239 | """ |
---|
| 3240 | toggle view of model from 1D to 2D or 2D from 1D |
---|
| 3241 | """ |
---|
[2c60cb69] | 3242 | if self.model_view.GetLabelText() == "Show 2D": |
---|
| 3243 | self.model_view.SetLabel("Show 1D") |
---|
[8b6f489] | 3244 | self.enable2D = True |
---|
[2f4b430] | 3245 | |
---|
[8b6f489] | 3246 | else: |
---|
[2c60cb69] | 3247 | self.model_view.SetLabel("Show 2D") |
---|
[8b6f489] | 3248 | self.enable2D = False |
---|
[e947cd4] | 3249 | self.Show(False) |
---|
[6ff97c5] | 3250 | self.create_default_data() |
---|
[3fb5e68] | 3251 | self._manager.store_data(self.uid, data_list=[self.data]) |
---|
| 3252 | |
---|
[ba1f0b2] | 3253 | self.set_model_param_sizer(self.model) |
---|
[ac2b835] | 3254 | self._set_sizer_dispersion() |
---|
| 3255 | self._set_weight(is_2D=self.enable2D) |
---|
[2c60cb69] | 3256 | self._set_smear_buttons() |
---|
[e947cd4] | 3257 | self.Show(True) |
---|
[8247523] | 3258 | self.SetupScrolling() |
---|
[ba1f0b2] | 3259 | self._draw_model() |
---|
[2f4b430] | 3260 | |
---|
[ac2b835] | 3261 | self.state.enable2D = copy.deepcopy(self.enable2D) |
---|
[2f4b430] | 3262 | |
---|
[2c60cb69] | 3263 | def _set_smear_buttons(self): |
---|
| 3264 | """ |
---|
[ac2b835] | 3265 | Set semarer radio buttons |
---|
[2c60cb69] | 3266 | """ |
---|
| 3267 | # more disables for 2D |
---|
[ac2b835] | 3268 | if self.data.__class__.__name__ == "Data2D" or \ |
---|
[2c60cb69] | 3269 | self.enable2D: |
---|
| 3270 | self.slit_smearer.Disable() |
---|
[ac2b835] | 3271 | self.pinhole_smearer.Enable(True) |
---|
[2c60cb69] | 3272 | self.default_mask = copy.deepcopy(self.data.mask) |
---|
| 3273 | else: |
---|
[ac2b835] | 3274 | self.slit_smearer.Enable(True) |
---|
| 3275 | self.pinhole_smearer.Enable(True) |
---|
[2f4b430] | 3276 | |
---|
| 3277 | |
---|
[7609f1a] | 3278 | class BGTextCtrl(wx.TextCtrl): |
---|
| 3279 | """ |
---|
[5062bbf] | 3280 | Text control used to display outputs. |
---|
[ac2b835] | 3281 | No editing allowed. The background is |
---|
[5062bbf] | 3282 | grayed out. User can't select text. |
---|
[7609f1a] | 3283 | """ |
---|
| 3284 | def __init__(self, *args, **kwds): |
---|
| 3285 | wx.TextCtrl.__init__(self, *args, **kwds) |
---|
| 3286 | self.SetEditable(False) |
---|
[59b8c74] | 3287 | self.SetBackgroundColour(self.GetParent().parent.GetBackgroundColour()) |
---|
[2f4b430] | 3288 | |
---|
[7609f1a] | 3289 | # Bind to mouse event to avoid text highlighting |
---|
| 3290 | # The event will be skipped once the call-back |
---|
| 3291 | # is called. |
---|
| 3292 | self.Bind(wx.EVT_MOUSE_EVENTS, self._click) |
---|
[2f4b430] | 3293 | |
---|
[7609f1a] | 3294 | def _click(self, event): |
---|
| 3295 | """ |
---|
[5062bbf] | 3296 | Prevent further handling of the mouse event |
---|
| 3297 | by not calling Skip(). |
---|
[ac2b835] | 3298 | """ |
---|
[7609f1a] | 3299 | pass |
---|