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