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