[d1e0473] | 1 | |
---|
| 2 | |
---|
[c77d859] | 3 | import sys |
---|
| 4 | import wx |
---|
| 5 | import wx.lib.newevent |
---|
| 6 | import numpy |
---|
| 7 | import copy |
---|
| 8 | import math |
---|
[7975f2b] | 9 | import time |
---|
[c77d859] | 10 | from sans.models.dispersion_models import ArrayDispersion, GaussianDispersion |
---|
[7609f1a] | 11 | from DataLoader.data_info import Data1D |
---|
[c4397785] | 12 | from sans.guiframe.events import StatusEvent |
---|
[85b3971] | 13 | from sans.guiframe.utils import format_number,check_float |
---|
[7609f1a] | 14 | |
---|
[0b12abb5] | 15 | |
---|
[b787e68c] | 16 | |
---|
| 17 | ## event to know the selected fit engine |
---|
[77e23a2] | 18 | (FitterTypeEvent, EVT_FITTER_TYPE) = wx.lib.newevent.NewEvent() |
---|
[34a0c17] | 19 | (FitStopEvent, EVT_FIT_STOP) = wx.lib.newevent.NewEvent() |
---|
[f72333f] | 20 | (Chi2UpdateEvent, EVT_CHI2_UPDATE) = wx.lib.newevent.NewEvent() |
---|
[eda428b] | 21 | _BOX_WIDTH = 76 |
---|
[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: |
---|
[f867cd9] | 58 | self.smearer = smear_selection(self.data, self.model) |
---|
[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 |
---|
[f867cd9] | 342 | self.current_smearer= smear_selection( self.data, self.model ) |
---|
[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 |
---|
[d7b7156] | 442 | self._set_model_sizer(sizer=sizer, box_sizer=boxsizer1, |
---|
| 443 | title="Model",object=self.model_help ) |
---|
[5062bbf] | 444 | |
---|
[30d103a] | 445 | def _set_sizer_dispersion(self, dispersity): |
---|
[c77d859] | 446 | """ |
---|
[5062bbf] | 447 | draw sizer with gaussian dispersity parameters |
---|
[c77d859] | 448 | """ |
---|
| 449 | self.fittable_param=[] |
---|
| 450 | self.fixed_param=[] |
---|
[60132ef] | 451 | self.orientation_params_disp=[] |
---|
[920a6e5] | 452 | |
---|
[c77d859] | 453 | self.sizer4_4.Clear(True) |
---|
| 454 | if self.model==None: |
---|
| 455 | ##no model is selected |
---|
| 456 | return |
---|
| 457 | if not self.enable_disp.GetValue(): |
---|
| 458 | ## the user didn't select dispersity display |
---|
| 459 | return |
---|
[b421b1a] | 460 | |
---|
[376916c] | 461 | self._reset_dispersity() |
---|
[b421b1a] | 462 | |
---|
[376916c] | 463 | # Create the dispersion objects |
---|
| 464 | for item in self.model.dispersion.keys(): |
---|
[30d103a] | 465 | #disp_model = GaussianDispersion() |
---|
| 466 | disp_model = dispersity() |
---|
[376916c] | 467 | self._disp_obj_dict[item] = disp_model |
---|
| 468 | self.model.set_dispersion(item, disp_model) |
---|
[c477b31] | 469 | self.state._disp_obj_dict[item]= disp_model |
---|
[376916c] | 470 | |
---|
[b421b1a] | 471 | |
---|
[c77d859] | 472 | ix=0 |
---|
| 473 | iy=1 |
---|
[52efcc5] | 474 | disp = wx.StaticText(self, -1, ' ') |
---|
[c77d859] | 475 | self.sizer4_4.Add(disp,( iy, ix),(1,1), |
---|
| 476 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 477 | ix += 1 |
---|
[d7b7156] | 478 | values = wx.StaticText(self, -1, 'Sigma [A]') |
---|
| 479 | values.SetToolTipString(\ |
---|
| 480 | "Sigma(STD) in the A unit; the standard deviation from the mean value.") |
---|
| 481 | |
---|
| 482 | self.sizer4_4.Add(values,( iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, |
---|
| 483 | 0) |
---|
[c77d859] | 484 | ix +=2 |
---|
[920a6e5] | 485 | self.text_disp_1 = wx.StaticText(self, -1, '') |
---|
[c77d859] | 486 | self.sizer4_4.Add( self.text_disp_1,(iy, ix),(1,1),\ |
---|
| 487 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 488 | self.text_disp_1.Hide() |
---|
[920a6e5] | 489 | |
---|
| 490 | |
---|
| 491 | ix +=1 |
---|
| 492 | self.text_disp_min = wx.StaticText(self, -1, 'Min') |
---|
| 493 | self.sizer4_4.Add(self.text_disp_min,(iy, ix),(1,1),\ |
---|
| 494 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 495 | self.text_disp_min.Hide() |
---|
| 496 | ix +=1 |
---|
| 497 | self.text_disp_max = wx.StaticText(self, -1, 'Max') |
---|
| 498 | self.sizer4_4.Add(self.text_disp_max,(iy, ix),(1,1),\ |
---|
| 499 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 500 | self.text_disp_max.Hide() |
---|
| 501 | |
---|
| 502 | |
---|
[c77d859] | 503 | ix += 1 |
---|
| 504 | npts = wx.StaticText(self, -1, 'Npts') |
---|
[d7b7156] | 505 | npts.SetToolTipString("Number of sampling points for the numerical\n\ |
---|
| 506 | integration over the distribution function.") |
---|
[c77d859] | 507 | self.sizer4_4.Add(npts,( iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 508 | ix += 1 |
---|
| 509 | nsigmas = wx.StaticText(self, -1, 'Nsigmas') |
---|
[d7b7156] | 510 | nsigmas.SetToolTipString(" Number of sigmas between which the range\n\ |
---|
| 511 | of the distribution function will be used for weighting. \n\ |
---|
| 512 | The value '3' covers 99.5% for Gaussian distribution \n\ |
---|
| 513 | function.") |
---|
| 514 | self.sizer4_4.Add(nsigmas,( iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, |
---|
| 515 | 0) |
---|
[920a6e5] | 516 | |
---|
| 517 | if self.engine_type=="park": |
---|
| 518 | self.text_disp_max.Show(True) |
---|
| 519 | self.text_disp_min.Show(True) |
---|
[6dc9ad8] | 520 | |
---|
[c77d859] | 521 | for item in self.model.dispersion.keys(): |
---|
[780d095] | 522 | if not item in self.model.orientation_params: |
---|
[edd166b] | 523 | if not self.disp_cb_dict.has_key(item): |
---|
| 524 | self.disp_cb_dict[item]= None |
---|
[d7b7156] | 525 | name0="Distribution of " + item |
---|
[780d095] | 526 | name1=item+".width" |
---|
| 527 | name2=item+".npts" |
---|
| 528 | name3=item+".nsigmas" |
---|
[c99a6c5] | 529 | if not self.model.details.has_key(name1): |
---|
[b421b1a] | 530 | self.model.details [name1] = ["",None,None] |
---|
[c99a6c5] | 531 | |
---|
[780d095] | 532 | iy += 1 |
---|
| 533 | for p in self.model.dispersion[item].keys(): |
---|
| 534 | |
---|
| 535 | if p=="width": |
---|
| 536 | ix = 0 |
---|
[d7b7156] | 537 | cb = wx.CheckBox(self, -1, name0, (10, 10)) |
---|
[b9405cd] | 538 | cb.SetToolTipString("Check for fitting") |
---|
[780d095] | 539 | wx.EVT_CHECKBOX(self, cb.GetId(), self.select_param) |
---|
| 540 | self.sizer4_4.Add( cb,( iy, ix),(1,1), |
---|
[d7b7156] | 541 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, |
---|
| 542 | 15) |
---|
[780d095] | 543 | ix = 1 |
---|
| 544 | value= self.model.getParam(name1) |
---|
[d7b7156] | 545 | ctl1 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH,20) |
---|
| 546 | ,style=wx.TE_PROCESS_ENTER) |
---|
| 547 | ctl1.SetToolTipString("Absolute Sigma: \n\ |
---|
| 548 | 1) It is the STD (ratio*mean) of '%s' distribution.\n \ |
---|
| 549 | 2) It should not exceed Mean/(2*Nsigmas)." %item) |
---|
[780d095] | 550 | ctl1.SetValue(str (format_number(value))) |
---|
| 551 | self.sizer4_4.Add(ctl1, (iy,ix),(1,1),wx.EXPAND) |
---|
| 552 | ## text to show error sign |
---|
| 553 | ix = 2 |
---|
| 554 | text2=wx.StaticText(self, -1, '+/-') |
---|
| 555 | self.sizer4_4.Add(text2,(iy, ix),(1,1), |
---|
| 556 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 557 | text2.Hide() |
---|
[b421b1a] | 558 | |
---|
[780d095] | 559 | ix = 3 |
---|
[d7b7156] | 560 | ctl2 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), |
---|
| 561 | style=0) |
---|
[eacf1d66] | 562 | |
---|
[d7b7156] | 563 | self.sizer4_4.Add(ctl2, (iy,ix),(1,1), |
---|
| 564 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[eacf1d66] | 565 | |
---|
[b421b1a] | 566 | ctl2.Hide() |
---|
[eacf1d66] | 567 | |
---|
[920a6e5] | 568 | ix = 4 |
---|
[d7b7156] | 569 | ctl3 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/2, |
---|
| 570 | 20), style=wx.TE_PROCESS_ENTER, |
---|
| 571 | text_enter_callback = self._onparamRangeEnter) |
---|
[b9405cd] | 572 | |
---|
[d7b7156] | 573 | self.sizer4_4.Add(ctl3, (iy,ix),(1,1), |
---|
| 574 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[920a6e5] | 575 | ctl3.Hide() |
---|
| 576 | |
---|
| 577 | ix = 5 |
---|
[d7b7156] | 578 | ctl4 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/2, |
---|
| 579 | 20), style=wx.TE_PROCESS_ENTER, |
---|
| 580 | text_enter_callback = self._onparamRangeEnter) |
---|
[b9405cd] | 581 | |
---|
[d7b7156] | 582 | self.sizer4_4.Add(ctl4, (iy,ix),(1,1), |
---|
| 583 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[eacf1d66] | 584 | |
---|
[920a6e5] | 585 | ctl4.Hide() |
---|
| 586 | |
---|
| 587 | if self.engine_type=="park": |
---|
| 588 | ctl3.Show(True) |
---|
| 589 | ctl4.Show(True) |
---|
| 590 | |
---|
[780d095] | 591 | self.fittable_param.append([cb,name1,ctl1,text2, |
---|
[c99a6c5] | 592 | ctl2, ctl3, ctl4,None]) |
---|
[920a6e5] | 593 | |
---|
[780d095] | 594 | elif p=="npts": |
---|
[920a6e5] | 595 | ix = 6 |
---|
[780d095] | 596 | value= self.model.getParam(name2) |
---|
[d7b7156] | 597 | Tctl = self.ModelTextCtrl(self, -1, |
---|
| 598 | size=(_BOX_WIDTH/2,20), |
---|
[780d095] | 599 | style=wx.TE_PROCESS_ENTER) |
---|
[1a94c36] | 600 | |
---|
[780d095] | 601 | Tctl.SetValue(str (format_number(value))) |
---|
| 602 | self.sizer4_4.Add(Tctl, (iy,ix),(1,1), |
---|
| 603 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 604 | self.fixed_param.append([None,name2, Tctl,None,None, |
---|
| 605 | None, None,None]) |
---|
| 606 | elif p=="nsigmas": |
---|
[920a6e5] | 607 | ix = 7 |
---|
[780d095] | 608 | value= self.model.getParam(name3) |
---|
[d7b7156] | 609 | Tct2 = self.ModelTextCtrl(self, -1, |
---|
| 610 | size=(_BOX_WIDTH/2,20), |
---|
[780d095] | 611 | style=wx.TE_PROCESS_ENTER) |
---|
[1a94c36] | 612 | |
---|
[c985bef] | 613 | Tct2.SetValue(str (format_number(value))) |
---|
| 614 | self.sizer4_4.Add(Tct2, (iy,ix),(1,1), |
---|
[780d095] | 615 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 616 | ix +=1 |
---|
| 617 | self.sizer4_4.Add((20,20), (iy,ix),(1,1), |
---|
| 618 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 619 | |
---|
[c985bef] | 620 | self.fixed_param.append([None,name3, Tct2 |
---|
[d7b7156] | 621 | ,None,None,None, |
---|
| 622 | None,None]) |
---|
[920a6e5] | 623 | |
---|
[780d095] | 624 | ix =0 |
---|
| 625 | iy +=1 |
---|
[d7b7156] | 626 | self.sizer4_4.Add((20,20),(iy,ix),(1,1), |
---|
| 627 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 628 | first_orient = True |
---|
[780d095] | 629 | for item in self.model.dispersion.keys(): |
---|
| 630 | if item in self.model.orientation_params: |
---|
[edd166b] | 631 | if not self.disp_cb_dict.has_key(item): |
---|
| 632 | self.disp_cb_dict[item]= None |
---|
[d7b7156] | 633 | name0="Distribution of " + item |
---|
[780d095] | 634 | name1=item+".width" |
---|
| 635 | name2=item+".npts" |
---|
| 636 | name3=item+".nsigmas" |
---|
[d7b7156] | 637 | |
---|
[c99a6c5] | 638 | if not self.model.details.has_key(name1): |
---|
[b421b1a] | 639 | self.model.details [name1] = ["",None,None] |
---|
| 640 | |
---|
| 641 | |
---|
[780d095] | 642 | iy += 1 |
---|
| 643 | for p in self.model.dispersion[item].keys(): |
---|
| 644 | |
---|
| 645 | if p=="width": |
---|
| 646 | ix = 0 |
---|
[d7b7156] | 647 | cb = wx.CheckBox(self, -1, name0, (10, 10)) |
---|
[b9405cd] | 648 | cb.SetToolTipString("Check for fitting") |
---|
[780d095] | 649 | wx.EVT_CHECKBOX(self, cb.GetId(), self.select_param) |
---|
| 650 | self.sizer4_4.Add( cb,( iy, ix),(1,1), |
---|
[d7b7156] | 651 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, |
---|
| 652 | 15) |
---|
[780d095] | 653 | if self.data.__class__.__name__ =="Data2D": |
---|
[6dc9ad8] | 654 | cb.Show(True) |
---|
[c99a6c5] | 655 | elif cb.IsShown(): |
---|
[6dc9ad8] | 656 | cb.Hide() |
---|
[780d095] | 657 | ix = 1 |
---|
| 658 | value= self.model.getParam(name1) |
---|
[d7b7156] | 659 | ctl1 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH, |
---|
| 660 | 20),style=wx.TE_PROCESS_ENTER) |
---|
| 661 | ctl1.SetToolTipString("Absolute Sigma: \n\ |
---|
| 662 | 1) It is the STD (ratio*mean) of '%s' distribution."% \ |
---|
| 663 | item) |
---|
[780d095] | 664 | ctl1.SetValue(str (format_number(value))) |
---|
| 665 | if self.data.__class__.__name__ =="Data2D": |
---|
[d7b7156] | 666 | if first_orient: |
---|
| 667 | values.SetLabel('Sigma [A (or deg)]') |
---|
| 668 | values.SetToolTipString(\ |
---|
| 669 | "Sigma(STD) in the A or deg(for angles) unit;\n\ |
---|
| 670 | the standard deviation from the mean value.") |
---|
| 671 | first_orient = False |
---|
[6dc9ad8] | 672 | ctl1.Show(True) |
---|
[c99a6c5] | 673 | elif ctl1.IsShown(): |
---|
[6dc9ad8] | 674 | ctl1.Hide() |
---|
[d7b7156] | 675 | |
---|
[780d095] | 676 | self.sizer4_4.Add(ctl1, (iy,ix),(1,1),wx.EXPAND) |
---|
| 677 | ## text to show error sign |
---|
| 678 | ix = 2 |
---|
| 679 | text2=wx.StaticText(self, -1, '+/-') |
---|
| 680 | self.sizer4_4.Add(text2,(iy, ix),(1,1), |
---|
| 681 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 682 | text2.Hide() |
---|
[b421b1a] | 683 | |
---|
[780d095] | 684 | ix = 3 |
---|
[d7b7156] | 685 | ctl2 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), |
---|
| 686 | style=0) |
---|
[b421b1a] | 687 | |
---|
[d7b7156] | 688 | self.sizer4_4.Add(ctl2, (iy,ix),(1,1), |
---|
| 689 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[b421b1a] | 690 | ctl2.Hide() |
---|
[920a6e5] | 691 | |
---|
| 692 | ix = 4 |
---|
[d7b7156] | 693 | ctl3 = self.ModelTextCtrl(self, -1, |
---|
| 694 | size=(_BOX_WIDTH/2,20), |
---|
| 695 | style=wx.TE_PROCESS_ENTER, |
---|
| 696 | text_enter_callback = self._onparamRangeEnter) |
---|
[eacf1d66] | 697 | |
---|
[d7b7156] | 698 | self.sizer4_4.Add(ctl3, (iy,ix),(1,1), |
---|
| 699 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[c99a6c5] | 700 | |
---|
[920a6e5] | 701 | ctl3.Hide() |
---|
| 702 | |
---|
| 703 | ix = 5 |
---|
[d7b7156] | 704 | ctl4 = self.ModelTextCtrl(self, -1, |
---|
| 705 | size=(_BOX_WIDTH/2,20), style=wx.TE_PROCESS_ENTER, |
---|
| 706 | text_enter_callback = self._onparamRangeEnter) |
---|
| 707 | self.sizer4_4.Add(ctl4, (iy,ix),(1,1), |
---|
| 708 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[920a6e5] | 709 | ctl4.Hide() |
---|
[c99a6c5] | 710 | #if self.data.__class__.__name__ =="Data2D": |
---|
| 711 | #ctl4.Enable(True) |
---|
| 712 | #elif ctl4.Shown(): |
---|
| 713 | #ctl4.Hide() |
---|
[920a6e5] | 714 | |
---|
[d7b7156] | 715 | if self.engine_type=="park" and \ |
---|
| 716 | self.data.__class__.__name__ =="Data2D": |
---|
[920a6e5] | 717 | ctl3.Show(True) |
---|
[c99a6c5] | 718 | ctl4.Show(True) |
---|
[920a6e5] | 719 | |
---|
| 720 | |
---|
| 721 | |
---|
| 722 | |
---|
[780d095] | 723 | self.fittable_param.append([cb,name1,ctl1,text2, |
---|
[920a6e5] | 724 | ctl2, ctl3, ctl4,None]) |
---|
[d7b7156] | 725 | self.orientation_params_disp.append([cb,name1,ctl1, |
---|
| 726 | text2, ctl2, ctl3, ctl4,None]) |
---|
[780d095] | 727 | elif p=="npts": |
---|
[920a6e5] | 728 | ix = 6 |
---|
[780d095] | 729 | value= self.model.getParam(name2) |
---|
[d7b7156] | 730 | Tctl = self.ModelTextCtrl(self, -1, |
---|
| 731 | size=(_BOX_WIDTH/2,20), |
---|
[780d095] | 732 | style=wx.TE_PROCESS_ENTER) |
---|
[1a94c36] | 733 | |
---|
[780d095] | 734 | Tctl.SetValue(str (format_number(value))) |
---|
| 735 | if self.data.__class__.__name__ =="Data2D": |
---|
[6dc9ad8] | 736 | Tctl.Show(True) |
---|
[780d095] | 737 | else: |
---|
[6dc9ad8] | 738 | Tctl.Hide() |
---|
[780d095] | 739 | self.sizer4_4.Add(Tctl, (iy,ix),(1,1), |
---|
| 740 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 741 | self.fixed_param.append([None,name2, Tctl,None,None, |
---|
| 742 | None, None,None]) |
---|
[d7b7156] | 743 | self.orientation_params_disp.append([None,name2, |
---|
| 744 | Tctl,None,None, |
---|
[780d095] | 745 | None, None,None]) |
---|
| 746 | elif p=="nsigmas": |
---|
[920a6e5] | 747 | ix = 7 |
---|
[780d095] | 748 | value= self.model.getParam(name3) |
---|
[d7b7156] | 749 | Tct2 = self.ModelTextCtrl(self, -1, |
---|
| 750 | size=(_BOX_WIDTH/2,20), |
---|
[780d095] | 751 | style=wx.TE_PROCESS_ENTER) |
---|
[1a94c36] | 752 | |
---|
[c985bef] | 753 | Tct2.SetValue(str (format_number(value))) |
---|
[780d095] | 754 | if self.data.__class__.__name__ =="Data2D": |
---|
[c985bef] | 755 | Tct2.Show(True) |
---|
[780d095] | 756 | else: |
---|
[c985bef] | 757 | Tct2.Hide() |
---|
| 758 | self.sizer4_4.Add(Tct2, (iy,ix),(1,1), |
---|
[780d095] | 759 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 760 | ix +=1 |
---|
[7975f2b] | 761 | |
---|
[c985bef] | 762 | self.fixed_param.append([None,name3, Tct2 |
---|
[d7b7156] | 763 | ,None,None, None, None,None]) |
---|
[920a6e5] | 764 | |
---|
[d7b7156] | 765 | self.orientation_params_disp.append([None,name3, |
---|
| 766 | Tct2 ,None,None, None, None,None]) |
---|
| 767 | |
---|
[b421b1a] | 768 | self.state.disp_cb_dict = copy.deepcopy(self.disp_cb_dict) |
---|
| 769 | |
---|
[71f0373] | 770 | self.state.model = self.model.clone() |
---|
[240b9966] | 771 | ## save state into |
---|
[4043c96] | 772 | self.state.cb1 = self.cb1.GetValue() |
---|
[920a6e5] | 773 | self._copy_parameters_state(self.parameters, self.state.parameters) |
---|
[240b9966] | 774 | self._copy_parameters_state(self.orientation_params_disp, |
---|
| 775 | self.state.orientation_params_disp) |
---|
[d7b7156] | 776 | self._copy_parameters_state(self.fittable_param, |
---|
| 777 | self.state.fittable_param) |
---|
[240b9966] | 778 | self._copy_parameters_state(self.fixed_param, self.state.fixed_param) |
---|
[d40a9cd] | 779 | |
---|
| 780 | |
---|
[c77d859] | 781 | wx.PostEvent(self.parent, StatusEvent(status=\ |
---|
| 782 | " Selected Distribution: Gaussian")) |
---|
[b324aa9] | 783 | #Fill the list of fittable parameters |
---|
| 784 | self.select_all_param(event=None) |
---|
| 785 | |
---|
[71f0373] | 786 | self.Layout() |
---|
[7975f2b] | 787 | |
---|
[c77d859] | 788 | def _onFit(self, event): |
---|
| 789 | """ |
---|
[5062bbf] | 790 | Allow to fit |
---|
[c77d859] | 791 | """ |
---|
[c13b8cc] | 792 | #make sure all parameter values are updated. |
---|
[ffa69b6] | 793 | if self.check_invalid_panel(): |
---|
| 794 | return |
---|
[4470b10] | 795 | if self.model ==None: |
---|
| 796 | msg="Please select a Model first..." |
---|
| 797 | wx.MessageBox(msg, 'Info') |
---|
| 798 | wx.PostEvent(self.manager.parent, StatusEvent(status=\ |
---|
| 799 | "Fit: %s"%msg)) |
---|
| 800 | return |
---|
| 801 | |
---|
[85b3971] | 802 | flag = self._update_paramv_on_fit() |
---|
[acd0bda3] | 803 | |
---|
[c77d859] | 804 | if not flag: |
---|
[7609f1a] | 805 | msg= "Fitting range or parameters are invalid" |
---|
[c77d859] | 806 | wx.PostEvent(self.parent.parent, StatusEvent(status= msg )) |
---|
| 807 | return |
---|
| 808 | |
---|
| 809 | if len(self.param_toFit) <= 0: |
---|
| 810 | msg= "Select at least one parameter to fit" |
---|
| 811 | wx.PostEvent(self.parent.parent, StatusEvent(status= msg )) |
---|
| 812 | return |
---|
[7975f2b] | 813 | |
---|
| 814 | self.select_param(event =None) |
---|
[acd0bda3] | 815 | |
---|
[c99a6c5] | 816 | #Clear errors if exist from previous fitting |
---|
[edd166b] | 817 | #self._clear_Err_on_Fit() |
---|
[d0ce2c30] | 818 | |
---|
[d7b7156] | 819 | # Remove or do not allow fitting on the Q=0 point, especially |
---|
| 820 | # when y(q=0)=None at x[0]. |
---|
[1c1436d] | 821 | self.qmin_x = float(self.qmin.GetValue()) |
---|
[c13b8cc] | 822 | self.qmax_x = float( self.qmax.GetValue()) |
---|
[6f023e8] | 823 | self.manager._reset_schedule_problem( value=0) |
---|
[ca7a626] | 824 | self.manager.schedule_for_fit( value=1,page=self,fitproblem =None) |
---|
[d7b7156] | 825 | self.manager.set_fit_range(page= self,qmin= self.qmin_x, |
---|
| 826 | qmax= self.qmax_x) |
---|
[ad6dd4c] | 827 | |
---|
[c77d859] | 828 | #single fit |
---|
[ca7a626] | 829 | self.manager.onFit() |
---|
[ad6dd4c] | 830 | ## allow stopping the fit |
---|
[34a0c17] | 831 | #if self.engine_type=="scipy": |
---|
| 832 | # self.btFit.SetLabel("Stop") |
---|
| 833 | # self.btFit.Unbind(event=wx.EVT_BUTTON, id= self.btFit.GetId()) |
---|
[d7b7156] | 834 | # self.btFit.Bind(event= wx.EVT_BUTTON, |
---|
| 835 | # handler=self._StopFit, id=self.btFit.GetId()) |
---|
[34a0c17] | 836 | #else: |
---|
| 837 | # self.btFit.SetLabel("Fit") |
---|
[d7b7156] | 838 | # self.btFit.Bind(event= wx.EVT_BUTTON, |
---|
| 839 | # handler=self._onFit, id=self.btFit.GetId()) |
---|
[7975f2b] | 840 | |
---|
[ad6dd4c] | 841 | def _StopFit(self, event): |
---|
| 842 | """ |
---|
[5062bbf] | 843 | Stop fit |
---|
[ad6dd4c] | 844 | """ |
---|
| 845 | self.btFit.SetLabel("Fit") |
---|
| 846 | if self.engine_type=="scipy": |
---|
| 847 | self.manager.stop_fit() |
---|
[34a0c17] | 848 | self.btFit.Unbind(event=wx.EVT_BUTTON, id=self.btFit.GetId()) |
---|
[d7b7156] | 849 | self.btFit.Bind(event=wx.EVT_BUTTON, handler=self._onFit, |
---|
| 850 | id=self.btFit.GetId()) |
---|
[7975f2b] | 851 | |
---|
[ad6dd4c] | 852 | |
---|
[0b12abb5] | 853 | def _on_select_model(self, event=None): |
---|
[c77d859] | 854 | """ |
---|
[5062bbf] | 855 | call back for model selection |
---|
[6747217] | 856 | """ |
---|
[59a7f2d] | 857 | self._on_select_model_helper() |
---|
[70c57ebf] | 858 | self.set_model_param_sizer(self.model) |
---|
[b421b1a] | 859 | |
---|
[3b605bb] | 860 | self.enable_disp.SetValue(False) |
---|
| 861 | self.disable_disp.SetValue(True) |
---|
[4043c96] | 862 | try: |
---|
| 863 | self.set_dispers_sizer() |
---|
| 864 | except: |
---|
| 865 | pass |
---|
[6747217] | 866 | self.btFit.SetFocus() |
---|
| 867 | self.state.enable_disp = self.enable_disp.GetValue() |
---|
| 868 | self.state.disable_disp = self.disable_disp.GetValue() |
---|
| 869 | self.state.pinhole_smearer = self.pinhole_smearer.GetValue() |
---|
| 870 | self.state.slit_smearer = self.slit_smearer.GetValue() |
---|
| 871 | |
---|
| 872 | self.state.structurecombobox = self.structurebox.GetCurrentSelection() |
---|
| 873 | self.state.formfactorcombobox = self.formfactorbox.GetCurrentSelection() |
---|
| 874 | |
---|
[9237df4] | 875 | if self.model != None: |
---|
[64bda1e] | 876 | # Reset smearer, model and data |
---|
| 877 | self.set_data(self.data) |
---|
| 878 | # update smearer sizer |
---|
| 879 | self.onSmear(None) |
---|
[70c57ebf] | 880 | try: |
---|
[64bda1e] | 881 | temp_smear = None |
---|
[70c57ebf] | 882 | if self.enable_smearer.GetValue(): |
---|
[64bda1e] | 883 | # Set the smearer environments |
---|
[70c57ebf] | 884 | temp_smear= self.smearer |
---|
[f72333f] | 885 | #self.compute_chisqr(temp_smear) |
---|
[70c57ebf] | 886 | except: |
---|
| 887 | ## error occured on chisqr computation |
---|
| 888 | pass |
---|
[0b12abb5] | 889 | ## event to post model to fit to fitting plugins |
---|
| 890 | (ModelEventbox, EVT_MODEL_BOX) = wx.lib.newevent.NewEvent() |
---|
[d7b7156] | 891 | if self.data is not None and \ |
---|
| 892 | self.data.__class__.__name__ !="Data2D": |
---|
| 893 | ## set smearing value whether or not |
---|
| 894 | # the data contain the smearing info |
---|
[64bda1e] | 895 | evt = ModelEventbox(model = self.model, |
---|
| 896 | smearer = temp_smear, |
---|
| 897 | qmin = float(self.qmin_x), |
---|
| 898 | qmax = float(self.qmax_x)) |
---|
[6747217] | 899 | else: |
---|
[64bda1e] | 900 | evt = ModelEventbox(model = self.model) |
---|
[0b12abb5] | 901 | |
---|
[64bda1e] | 902 | self.manager._on_model_panel(evt = evt) |
---|
[0b12abb5] | 903 | self.state.model = self.model.clone() |
---|
| 904 | self.state.model.name = self.model.name |
---|
| 905 | if event is not None: |
---|
| 906 | self._draw_model() |
---|
[3595309d] | 907 | if event !=None: |
---|
[3a37fe0] | 908 | #self._undo.Enable(True) |
---|
[3595309d] | 909 | ## post state to fit panel |
---|
| 910 | event = PageInfoEvent(page = self) |
---|
| 911 | wx.PostEvent(self.parent, event) |
---|
[5062bbf] | 912 | |
---|
[0b12abb5] | 913 | |
---|
[dd5949d] | 914 | def _onparamEnter(self,event): |
---|
| 915 | """ |
---|
[5062bbf] | 916 | when enter value on panel redraw model according to changed |
---|
[dd5949d] | 917 | """ |
---|
[4470b10] | 918 | if self.model ==None: |
---|
| 919 | msg="Please select a Model first..." |
---|
| 920 | wx.MessageBox(msg, 'Info') |
---|
| 921 | #wx.PostEvent(self.manager.parent, StatusEvent(status=\ |
---|
| 922 | # "Parameters: %s"%msg)) |
---|
| 923 | return |
---|
| 924 | |
---|
[51a71a3] | 925 | #default flag |
---|
[7975f2b] | 926 | flag = False |
---|
[51a71a3] | 927 | self.fitrange = True |
---|
| 928 | #get event object |
---|
[69bee6d] | 929 | tcrtl= event.GetEventObject() |
---|
[4fbc93e] | 930 | wx.PostEvent(self.manager.parent, StatusEvent(status=" \ |
---|
| 931 | updating ... ",type="update")) |
---|
[edd166b] | 932 | #Clear msg if previously shown. |
---|
| 933 | msg= "" |
---|
| 934 | wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) |
---|
[c99a6c5] | 935 | |
---|
[7975f2b] | 936 | if check_float(tcrtl): |
---|
[2012eae] | 937 | flag = self._onparamEnter_helper() |
---|
| 938 | self.set_npts2fit() |
---|
[51a71a3] | 939 | if self.fitrange: |
---|
| 940 | temp_smearer = None |
---|
| 941 | if not self.disable_smearer.GetValue(): |
---|
| 942 | temp_smearer= self.current_smearer |
---|
[d7b7156] | 943 | ## set smearing value whether or not |
---|
| 944 | # the data contain the smearing info |
---|
[51a71a3] | 945 | if self.slit_smearer.GetValue(): |
---|
| 946 | flag1 = self.update_slit_smear() |
---|
| 947 | flag = flag or flag1 |
---|
| 948 | elif self.pinhole_smearer.GetValue(): |
---|
| 949 | flag1 = self.update_pinhole_smear() |
---|
| 950 | flag = flag or flag1 |
---|
| 951 | elif self.data.__class__.__name__ !="Data2D": |
---|
[d7b7156] | 952 | self.manager.set_smearer(smearer=temp_smearer, |
---|
| 953 | qmin= float(self.qmin_x), |
---|
| 954 | qmax= float(self.qmax_x)) |
---|
[51a71a3] | 955 | if flag: |
---|
[f72333f] | 956 | #self.compute_chisqr(smearer= temp_smearer) |
---|
[51a71a3] | 957 | |
---|
| 958 | ## new state posted |
---|
| 959 | if self.state_change: |
---|
| 960 | #self._undo.Enable(True) |
---|
| 961 | event = PageInfoEvent(page = self) |
---|
| 962 | wx.PostEvent(self.parent, event) |
---|
| 963 | self.state_change= False |
---|
| 964 | else: |
---|
[d7b7156] | 965 | # invalid fit range: do nothing here: |
---|
| 966 | # msg already displayed in validate |
---|
| 967 | return |
---|
[69bee6d] | 968 | else: |
---|
[7975f2b] | 969 | self.save_current_state() |
---|
[69bee6d] | 970 | msg= "Cannot Plot :Must enter a number!!! " |
---|
| 971 | wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) |
---|
[7609f1a] | 972 | |
---|
| 973 | self.save_current_state() |
---|
| 974 | return |
---|
| 975 | |
---|
[e2f7b92] | 976 | def _onparamRangeEnter(self, event): |
---|
[920a6e5] | 977 | """ |
---|
[5062bbf] | 978 | Check validity of value enter in the parameters range field |
---|
[920a6e5] | 979 | """ |
---|
[ffa69b6] | 980 | if self.check_invalid_panel(): |
---|
| 981 | return |
---|
[920a6e5] | 982 | tcrtl= event.GetEventObject() |
---|
[edd166b] | 983 | #Clear msg if previously shown. |
---|
| 984 | msg= "" |
---|
| 985 | wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) |
---|
| 986 | # Flag to register when a parameter has changed. |
---|
| 987 | is_modified = False |
---|
[920a6e5] | 988 | if tcrtl.GetValue().lstrip().rstrip()!="": |
---|
| 989 | try: |
---|
| 990 | value = float(tcrtl.GetValue()) |
---|
| 991 | tcrtl.SetBackgroundColour(wx.WHITE) |
---|
[edd166b] | 992 | self._check_value_enter(self.fittable_param ,is_modified) |
---|
| 993 | self._check_value_enter(self.parameters ,is_modified) |
---|
[920a6e5] | 994 | except: |
---|
| 995 | tcrtl.SetBackgroundColour("pink") |
---|
[edd166b] | 996 | msg= "Model Error:wrong value entered : %s"% sys.exc_value |
---|
| 997 | wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) |
---|
| 998 | return |
---|
[920a6e5] | 999 | else: |
---|
| 1000 | tcrtl.SetBackgroundColour(wx.WHITE) |
---|
[e2f7b92] | 1001 | |
---|
[edd166b] | 1002 | #self._undo.Enable(True) |
---|
| 1003 | self.save_current_state() |
---|
| 1004 | event = PageInfoEvent(page = self) |
---|
| 1005 | wx.PostEvent(self.parent, event) |
---|
| 1006 | self.state_change= False |
---|
[c69b6d5] | 1007 | |
---|
[12eac73] | 1008 | |
---|
| 1009 | def _onQrangeEnter(self, event): |
---|
| 1010 | """ |
---|
[5062bbf] | 1011 | Check validity of value enter in the Q range field |
---|
[12eac73] | 1012 | """ |
---|
[ffa69b6] | 1013 | if self.check_invalid_panel(): |
---|
| 1014 | return |
---|
[12eac73] | 1015 | tcrtl= event.GetEventObject() |
---|
| 1016 | #Clear msg if previously shown. |
---|
| 1017 | msg= "" |
---|
| 1018 | wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) |
---|
| 1019 | # Flag to register when a parameter has changed. |
---|
| 1020 | is_modified = False |
---|
| 1021 | if tcrtl.GetValue().lstrip().rstrip()!="": |
---|
| 1022 | try: |
---|
| 1023 | value = float(tcrtl.GetValue()) |
---|
| 1024 | tcrtl.SetBackgroundColour(wx.WHITE) |
---|
| 1025 | |
---|
| 1026 | # If qmin and qmax have been modified, update qmin and qmax |
---|
[85b3971] | 1027 | if self._validate_qrange( self.qmin, self.qmax): |
---|
[12eac73] | 1028 | tempmin = float(self.qmin.GetValue()) |
---|
| 1029 | if tempmin != self.qmin_x: |
---|
| 1030 | self.qmin_x = tempmin |
---|
| 1031 | tempmax = float(self.qmax.GetValue()) |
---|
| 1032 | if tempmax != self.qmax_x: |
---|
| 1033 | self.qmax_x = tempmax |
---|
| 1034 | else: |
---|
| 1035 | tcrtl.SetBackgroundColour("pink") |
---|
| 1036 | msg= "Model Error:wrong value entered : %s"% sys.exc_value |
---|
| 1037 | wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) |
---|
| 1038 | return |
---|
| 1039 | |
---|
| 1040 | except: |
---|
| 1041 | tcrtl.SetBackgroundColour("pink") |
---|
| 1042 | msg= "Model Error:wrong value entered : %s"% sys.exc_value |
---|
| 1043 | wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) |
---|
| 1044 | return |
---|
| 1045 | #Check if # of points for theory model are valid(>0). |
---|
[51a71a3] | 1046 | # check for 2d |
---|
| 1047 | if self.data.__class__.__name__ =="Data2D": |
---|
| 1048 | # set mask |
---|
[d7b7156] | 1049 | radius= numpy.sqrt( self.data.qx_data*self.data.qx_data + |
---|
| 1050 | self.data.qy_data*self.data.qy_data ) |
---|
[3f6508f] | 1051 | index_data = ((self.qmin_x <= radius)& \ |
---|
| 1052 | (radius<= self.qmax_x)) |
---|
[51a71a3] | 1053 | index_data = (index_data)&(self.data.mask) |
---|
| 1054 | index_data = (index_data)&(numpy.isfinite(self.data.data)) |
---|
| 1055 | if len(index_data[index_data]) < 10: |
---|
[3f6508f] | 1056 | msg = "Cannot Plot :No or too little npts in" |
---|
| 1057 | msg += " that data range!!! " |
---|
[12eac73] | 1058 | wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) |
---|
[51a71a3] | 1059 | return |
---|
| 1060 | else: |
---|
| 1061 | self.data.mask = index_data |
---|
[3f6508f] | 1062 | #self.Npts_fit.SetValue(str(len(self.data.mask))) |
---|
| 1063 | self.set_npts2fit() |
---|
[51a71a3] | 1064 | else: |
---|
[13913ec] | 1065 | index_data = ((self.qmin_x <= self.data.x)& \ |
---|
| 1066 | (self.data.x <= self.qmax_x)) |
---|
| 1067 | self.Npts_fit.SetValue(str(len(self.data.x[index_data]))) |
---|
| 1068 | |
---|
[12eac73] | 1069 | |
---|
| 1070 | else: |
---|
| 1071 | tcrtl.SetBackgroundColour("pink") |
---|
| 1072 | msg= "Model Error:wrong value entered!!!" |
---|
| 1073 | wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) |
---|
| 1074 | |
---|
[f72333f] | 1075 | self._draw_model() |
---|
| 1076 | ##update chi2 |
---|
| 1077 | #self.compute_chisqr(smearer= temp_smearer) |
---|
[12eac73] | 1078 | #self._undo.Enable(True) |
---|
| 1079 | self.save_current_state() |
---|
| 1080 | event = PageInfoEvent(page = self) |
---|
| 1081 | wx.PostEvent(self.parent, event) |
---|
| 1082 | self.state_change= False |
---|
[51a71a3] | 1083 | return |
---|
[5062bbf] | 1084 | |
---|
[edd166b] | 1085 | def _clear_Err_on_Fit(self): |
---|
| 1086 | """ |
---|
[5062bbf] | 1087 | hide the error text control shown |
---|
| 1088 | after fitting |
---|
[edd166b] | 1089 | """ |
---|
| 1090 | |
---|
| 1091 | if hasattr(self,"text2_3"): |
---|
| 1092 | self.text2_3.Hide() |
---|
| 1093 | |
---|
| 1094 | if len(self.parameters)>0: |
---|
| 1095 | for item in self.parameters: |
---|
| 1096 | #Skip t ifhe angle parameters if 1D data |
---|
| 1097 | if self.data.__class__.__name__ !="Data2D": |
---|
| 1098 | if item in self.orientation_params: |
---|
| 1099 | continue |
---|
| 1100 | if item in self.param_toFit: |
---|
| 1101 | continue |
---|
| 1102 | ## hide statictext +/- |
---|
| 1103 | if item[3]!=None and item[3].IsShown(): |
---|
| 1104 | item[3].Hide() |
---|
| 1105 | ## hide textcrtl for error after fit |
---|
| 1106 | if item[4]!=None and item[4].IsShown(): |
---|
| 1107 | item[4].Hide() |
---|
[7975f2b] | 1108 | |
---|
[edd166b] | 1109 | if len(self.fittable_param)>0: |
---|
| 1110 | for item in self.fittable_param: |
---|
| 1111 | #Skip t ifhe angle parameters if 1D data |
---|
| 1112 | if self.data.__class__.__name__ !="Data2D": |
---|
| 1113 | if item in self.orientation_params: |
---|
| 1114 | continue |
---|
| 1115 | if item in self.param_toFit: |
---|
| 1116 | continue |
---|
| 1117 | ## hide statictext +/- |
---|
| 1118 | if item[3]!=None and item[3].IsShown(): |
---|
| 1119 | item[3].Hide() |
---|
| 1120 | ## hide textcrtl for error after fit |
---|
| 1121 | if item[4]!=None and item[4].IsShown(): |
---|
| 1122 | item[4].Hide() |
---|
| 1123 | return |
---|
[920a6e5] | 1124 | |
---|
[7609f1a] | 1125 | def _get_defult_custom_smear(self): |
---|
| 1126 | """ |
---|
[5062bbf] | 1127 | Get the defult values for custum smearing. |
---|
[7609f1a] | 1128 | """ |
---|
| 1129 | # get the default values |
---|
| 1130 | if self.dxl == None: self.dxl = 0.0 |
---|
| 1131 | if self.dxw == None: self.dxw = "" |
---|
| 1132 | if self.dx_min == None: self.dx_min = SMEAR_SIZE_L |
---|
| 1133 | if self.dx_max == None: self.dx_max = SMEAR_SIZE_H |
---|
| 1134 | |
---|
| 1135 | def _get_smear_info(self): |
---|
| 1136 | """ |
---|
[5062bbf] | 1137 | Get the smear info from data. |
---|
| 1138 | |
---|
| 1139 | :return: self.smear_type, self.dq_l and self.dq_r, |
---|
[d7b7156] | 1140 | respectively the type of the smear, dq_min and |
---|
| 1141 | dq_max for pinhole smear data |
---|
[7609f1a] | 1142 | while dxl and dxw for slit smear |
---|
[5062bbf] | 1143 | |
---|
[7609f1a] | 1144 | """ |
---|
| 1145 | |
---|
| 1146 | # default |
---|
| 1147 | self.smear_type = None |
---|
| 1148 | self.dq_l = None |
---|
| 1149 | self.dq_r = None |
---|
[f72333f] | 1150 | data = self.data |
---|
| 1151 | if self.data is None: |
---|
[7609f1a] | 1152 | return |
---|
[f72333f] | 1153 | elif self.data.__class__.__name__ == 'Data2D': |
---|
| 1154 | if data.dqx_data == None or data.dqy_data ==None: |
---|
| 1155 | return |
---|
[d7b7156] | 1156 | elif self.smearer != None and (data.dqx_data.any()!=0) and \ |
---|
| 1157 | (data.dqx_data.any()!=0): |
---|
[f72333f] | 1158 | self.smear_type = "Pinhole2d" |
---|
| 1159 | self.dq_l = format_number(numpy.average(data.dqx_data)) |
---|
| 1160 | self.dq_r = format_number(numpy.average(data.dqy_data)) |
---|
| 1161 | return |
---|
| 1162 | else: |
---|
| 1163 | return |
---|
[7609f1a] | 1164 | # check if it is pinhole smear and get min max if it is. |
---|
| 1165 | if data.dx != None and all(data.dx !=0): |
---|
| 1166 | self.smear_type = "Pinhole" |
---|
[f72333f] | 1167 | self.dq_l = data.dx[0] |
---|
| 1168 | self.dq_r = data.dx[-1] |
---|
[7609f1a] | 1169 | |
---|
| 1170 | # check if it is slit smear and get min max if it is. |
---|
| 1171 | elif data.dxl != None or data.dxw != None: |
---|
| 1172 | self.smear_type = "Slit" |
---|
| 1173 | if data.dxl != None and all(data.dxl !=0): |
---|
| 1174 | self.dq_l = data.dxl[0] |
---|
| 1175 | if data.dxw != None and all(data.dxw !=0): |
---|
[5062bbf] | 1176 | self.dq_r = data.dxw[0] |
---|
[7609f1a] | 1177 | #return self.smear_type,self.dq_l,self.dq_r |
---|
| 1178 | |
---|
| 1179 | def _show_smear_sizer(self): |
---|
| 1180 | """ |
---|
[5062bbf] | 1181 | Show only the sizers depending on smear selection |
---|
[7609f1a] | 1182 | """ |
---|
[f72333f] | 1183 | # smear disabled |
---|
[7609f1a] | 1184 | if self.disable_smearer.GetValue(): |
---|
| 1185 | self.smear_description_none.Show(True) |
---|
[f72333f] | 1186 | # 2Dsmear |
---|
| 1187 | elif self._is_2D(): |
---|
| 1188 | self.smear_description_accuracy_type.Show(True) |
---|
| 1189 | self.smear_accuracy.Show(True) |
---|
| 1190 | self.smear_description_accuracy_type.Show(True) |
---|
| 1191 | self.smear_description_2d.Show(True) |
---|
| 1192 | self.smear_description_2d_x.Show(True) |
---|
| 1193 | self.smear_description_2d_y.Show(True) |
---|
| 1194 | if self.pinhole_smearer.GetValue(): |
---|
| 1195 | self.smear_pinhole_min.Show(True) |
---|
| 1196 | self.smear_pinhole_max.Show(True) |
---|
| 1197 | # smear from data |
---|
[7609f1a] | 1198 | elif self.enable_smearer.GetValue(): |
---|
[f72333f] | 1199 | |
---|
[7609f1a] | 1200 | self.smear_description_dqdata.Show(True) |
---|
| 1201 | if self.smear_type != None: |
---|
| 1202 | self.smear_description_smear_type.Show(True) |
---|
| 1203 | if self.smear_type == 'Slit': |
---|
| 1204 | self.smear_description_slit_height.Show(True) |
---|
[f72333f] | 1205 | self.smear_description_slit_width.Show(True) |
---|
[7609f1a] | 1206 | elif self.smear_type == 'Pinhole': |
---|
| 1207 | self.smear_description_pin_min.Show(True) |
---|
| 1208 | self.smear_description_pin_max.Show(True) |
---|
[f72333f] | 1209 | self.smear_description_smear_type.Show(True) |
---|
| 1210 | self.smear_description_type.Show(True) |
---|
[7609f1a] | 1211 | self.smear_data_left.Show(True) |
---|
| 1212 | self.smear_data_right.Show(True) |
---|
[f72333f] | 1213 | # custom pinhole smear |
---|
[7609f1a] | 1214 | elif self.pinhole_smearer.GetValue(): |
---|
[f72333f] | 1215 | if self.smear_type == 'Pinhole': |
---|
| 1216 | self.smear_message_new_p.Show(True) |
---|
| 1217 | self.smear_description_pin_min.Show(True) |
---|
| 1218 | self.smear_description_pin_max.Show(True) |
---|
| 1219 | |
---|
[7609f1a] | 1220 | self.smear_pinhole_min.Show(True) |
---|
| 1221 | self.smear_pinhole_max.Show(True) |
---|
[f72333f] | 1222 | # custom slit smear |
---|
[7609f1a] | 1223 | elif self.slit_smearer.GetValue(): |
---|
| 1224 | self.smear_message_new_s.Show(True) |
---|
| 1225 | self.smear_description_slit_height.Show(True) |
---|
| 1226 | self.smear_slit_height.Show(True) |
---|
| 1227 | self.smear_description_slit_width.Show(True) |
---|
| 1228 | self.smear_slit_width.Show(True) |
---|
| 1229 | |
---|
| 1230 | def _hide_all_smear_info(self): |
---|
| 1231 | """ |
---|
[5062bbf] | 1232 | Hide all smearing messages in the set_smearer sizer |
---|
[7609f1a] | 1233 | """ |
---|
| 1234 | self.smear_description_none.Hide() |
---|
| 1235 | self.smear_description_dqdata.Hide() |
---|
| 1236 | self.smear_description_type.Hide() |
---|
| 1237 | self.smear_description_smear_type.Hide() |
---|
[f72333f] | 1238 | self.smear_description_accuracy_type.Hide() |
---|
| 1239 | self.smear_description_2d_x.Hide() |
---|
| 1240 | self.smear_description_2d_y.Hide() |
---|
[7609f1a] | 1241 | self.smear_description_2d.Hide() |
---|
[f72333f] | 1242 | |
---|
| 1243 | self.smear_accuracy.Hide() |
---|
[7609f1a] | 1244 | self.smear_data_left.Hide() |
---|
| 1245 | self.smear_data_right.Hide() |
---|
| 1246 | self.smear_description_pin_min.Hide() |
---|
| 1247 | self.smear_pinhole_min.Hide() |
---|
| 1248 | self.smear_description_pin_max.Hide() |
---|
| 1249 | self.smear_pinhole_max.Hide() |
---|
| 1250 | self.smear_description_slit_height.Hide() |
---|
| 1251 | self.smear_slit_height.Hide() |
---|
| 1252 | self.smear_description_slit_width.Hide() |
---|
| 1253 | self.smear_slit_width.Hide() |
---|
| 1254 | self.smear_message_new_p.Hide() |
---|
| 1255 | self.smear_message_new_s.Hide() |
---|
| 1256 | |
---|
[f72333f] | 1257 | def _set_accuracy_list(self): |
---|
| 1258 | """ |
---|
[5062bbf] | 1259 | Set the list of an accuracy in 2D custum smear: Xhigh, High, Med, or Low |
---|
[f72333f] | 1260 | """ |
---|
| 1261 | # list of accuracy choices |
---|
| 1262 | list = ['Low','Med','High','Xhigh'] |
---|
| 1263 | for idx in range(len(list)): |
---|
| 1264 | self.smear_accuracy.Append(list[idx],idx) |
---|
| 1265 | |
---|
[fb59ed9] | 1266 | def _set_fun_box_list(self,fun_box): |
---|
| 1267 | """ |
---|
| 1268 | Set the list of func for multifunctional models |
---|
| 1269 | """ |
---|
| 1270 | # Check if it is multi_functional model |
---|
| 1271 | if self.model.__class__ not in self.model_list_box["Multi-Functions"]: |
---|
| 1272 | return None |
---|
| 1273 | # Get the func name list |
---|
| 1274 | list = self.model.fun_list |
---|
| 1275 | if len(list) == 0: |
---|
| 1276 | return None |
---|
| 1277 | # build function (combo)box |
---|
| 1278 | ind = 0 |
---|
| 1279 | while(ind < len(list)): |
---|
| 1280 | for key, val in list.iteritems(): |
---|
| 1281 | if (val == ind): |
---|
| 1282 | fun_box.Append(key,val) |
---|
| 1283 | break |
---|
| 1284 | ind += 1 |
---|
| 1285 | |
---|
[f72333f] | 1286 | def _on_select_accuracy(self,event): |
---|
| 1287 | """ |
---|
[5062bbf] | 1288 | Select an accuracy in 2D custom smear: Xhigh, High, Med, or Low |
---|
[f72333f] | 1289 | """ |
---|
| 1290 | #event.Skip() |
---|
[4fbc93e] | 1291 | # Check if the accuracy is same as before |
---|
| 1292 | #self.smear2d_accuracy = event.GetEventObject().GetValue() |
---|
| 1293 | self.smear2d_accuracy = self.smear_accuracy.GetValue() |
---|
[f72333f] | 1294 | if self.pinhole_smearer.GetValue(): |
---|
| 1295 | self.onPinholeSmear(event=None) |
---|
[4fbc93e] | 1296 | else: |
---|
| 1297 | self.onSmear(event=None) |
---|
| 1298 | if self.current_smearer != None: |
---|
[d7b7156] | 1299 | self.current_smearer.set_accuracy(accuracy = |
---|
| 1300 | self.smear2d_accuracy) |
---|
[f72333f] | 1301 | event.Skip() |
---|
[fb59ed9] | 1302 | |
---|
| 1303 | def _on_fun_box(self,event): |
---|
| 1304 | """ |
---|
| 1305 | Select an func: Erf,Rparabola,LParabola |
---|
| 1306 | """ |
---|
| 1307 | fun_val = None |
---|
| 1308 | fun_box = event.GetEventObject() |
---|
| 1309 | name = fun_box.Name |
---|
| 1310 | value = fun_box.GetValue() |
---|
| 1311 | if self.model.fun_list.has_key(value): |
---|
| 1312 | fun_val = self.model.fun_list[value] |
---|
| 1313 | |
---|
| 1314 | self.model.setParam(name,fun_val) |
---|
| 1315 | # save state |
---|
[d7b7156] | 1316 | self._copy_parameters_state(self.str_parameters, |
---|
| 1317 | self.state.str_parameters) |
---|
[fb59ed9] | 1318 | # update params |
---|
| 1319 | self._update_paramv_on_fit() |
---|
| 1320 | # draw |
---|
| 1321 | self._draw_model() |
---|
| 1322 | self.Refresh() |
---|
| 1323 | # get ready for new event |
---|
| 1324 | event.Skip() |
---|
[4fbc93e] | 1325 | |
---|
[51a71a3] | 1326 | def _onMask(self, event): |
---|
| 1327 | """ |
---|
[5062bbf] | 1328 | Build a panel to allow to edit Mask |
---|
[51a71a3] | 1329 | """ |
---|
| 1330 | |
---|
[d7b7156] | 1331 | from sans.guiframe.local_perspectives.plotting.masking \ |
---|
| 1332 | import MaskPanel as MaskDialog |
---|
[51a71a3] | 1333 | |
---|
| 1334 | self.panel = MaskDialog(self, data=self.data,id =-1 ) |
---|
| 1335 | self.panel.Bind(wx.EVT_CLOSE, self._draw_masked_model) |
---|
| 1336 | self.panel.ShowModal() |
---|
| 1337 | #wx.PostEvent(self.parent, event) |
---|
| 1338 | |
---|
| 1339 | def _draw_masked_model(self,event): |
---|
[f72333f] | 1340 | """ |
---|
| 1341 | Draw model image w/mask |
---|
| 1342 | """ |
---|
[51a71a3] | 1343 | event.Skip() |
---|
| 1344 | |
---|
| 1345 | is_valid_qrange = self._update_paramv_on_fit() |
---|
[247cb58] | 1346 | |
---|
[51a71a3] | 1347 | if is_valid_qrange: |
---|
[247cb58] | 1348 | # try re draw the model plot if it exists |
---|
[51a71a3] | 1349 | self._draw_model() |
---|
| 1350 | self.panel.Destroy() # frame |
---|
| 1351 | self.set_npts2fit() |
---|
[247cb58] | 1352 | elif self.model == None: |
---|
| 1353 | self.panel.Destroy() |
---|
| 1354 | self.set_npts2fit() |
---|
| 1355 | msg= "No model is found on updating MASK in the model plot... " |
---|
| 1356 | wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) |
---|
[51a71a3] | 1357 | else: |
---|
[247cb58] | 1358 | msg = ' Please consider your Q range, too.' |
---|
[51a71a3] | 1359 | self.panel.ShowMessage(msg) |
---|
[882a912] | 1360 | |
---|
[9237df4] | 1361 | def set_data(self, data): |
---|
[882a912] | 1362 | """ |
---|
[5062bbf] | 1363 | reset the current data |
---|
[882a912] | 1364 | """ |
---|
[9237df4] | 1365 | self.data = data |
---|
| 1366 | if self.data is None: |
---|
| 1367 | data_min = "" |
---|
| 1368 | data_max = "" |
---|
| 1369 | data_name = "" |
---|
[ffa69b6] | 1370 | self.formfactorbox.Disable() |
---|
| 1371 | self.structurebox.Disable() |
---|
[9237df4] | 1372 | else: |
---|
[f867cd9] | 1373 | self.smearer = smear_selection(self.data, self.model) |
---|
[d493f66] | 1374 | self.disable_smearer.SetValue(True) |
---|
[00e8df8] | 1375 | if self.smearer == None: |
---|
| 1376 | self.enable_smearer.Disable() |
---|
| 1377 | else: |
---|
| 1378 | self.enable_smearer.Enable() |
---|
[51a71a3] | 1379 | |
---|
[7609f1a] | 1380 | # more disables for 2D |
---|
| 1381 | if self.data.__class__.__name__ =="Data2D": |
---|
| 1382 | self.slit_smearer.Disable() |
---|
[51a71a3] | 1383 | self.default_mask = copy.deepcopy(self.data.mask) |
---|
[00e8df8] | 1384 | |
---|
[ffa69b6] | 1385 | self.formfactorbox.Enable() |
---|
| 1386 | self.structurebox.Enable() |
---|
[9237df4] | 1387 | data_name = self.data.name |
---|
| 1388 | #set maximum range for x in linear scale |
---|
| 1389 | if not hasattr(self.data,"data"): #Display only for 1D data fit |
---|
| 1390 | # Minimum value of data |
---|
| 1391 | data_min = min(self.data.x) |
---|
| 1392 | # Maximum value of data |
---|
| 1393 | data_max = max(self.data.x) |
---|
[51a71a3] | 1394 | #number of total data points |
---|
| 1395 | self.Npts_total.SetValue(str(len(self.data.x))) |
---|
| 1396 | #default:number of data points selected to fit |
---|
| 1397 | self.Npts_fit.SetValue(str(len(self.data.x))) |
---|
[19403da] | 1398 | self.btEditMask.Disable() |
---|
| 1399 | self.EditMask_title.Disable() |
---|
[9237df4] | 1400 | else: |
---|
| 1401 | ## Minimum value of data |
---|
| 1402 | data_min = 0 |
---|
| 1403 | x = max(math.fabs(self.data.xmin), math.fabs(self.data.xmax)) |
---|
| 1404 | y = max(math.fabs(self.data.ymin), math.fabs(self.data.ymax)) |
---|
| 1405 | ## Maximum value of data |
---|
| 1406 | data_max = math.sqrt(x*x + y*y) |
---|
[51a71a3] | 1407 | #number of total data points |
---|
| 1408 | self.Npts_total.SetValue(str(len(self.data.data))) |
---|
| 1409 | #default:number of data points selected to fit |
---|
| 1410 | self.Npts_fit.SetValue(str(len(self.data.data))) |
---|
[19403da] | 1411 | self.btEditMask.Enable() |
---|
| 1412 | self.EditMask_title.Enable() |
---|
[9237df4] | 1413 | self.dataSource.SetValue(data_name) |
---|
| 1414 | self.qmin_x = data_min |
---|
| 1415 | self.qmax_x = data_max |
---|
[ffa69b6] | 1416 | self.minimum_q.SetValue(str(data_min)) |
---|
| 1417 | self.maximum_q.SetValue(str(data_max)) |
---|
| 1418 | self.qmin.SetValue(str(data_min)) |
---|
| 1419 | self.qmax.SetValue(str(data_max)) |
---|
| 1420 | self.qmin.SetBackgroundColour("white") |
---|
| 1421 | self.qmax.SetBackgroundColour("white") |
---|
| 1422 | self.state.data = data |
---|
| 1423 | self.state.qmin = self.qmin_x |
---|
| 1424 | self.state.qmax = self.qmax_x |
---|
| 1425 | |
---|
[240b9966] | 1426 | def reset_page(self, state,first=False): |
---|
[a074145] | 1427 | """ |
---|
[5062bbf] | 1428 | reset the state |
---|
[a074145] | 1429 | """ |
---|
| 1430 | self.reset_page_helper(state) |
---|
[0b12abb5] | 1431 | #import sans.guiframe.gui_manager |
---|
| 1432 | #evt = ModelEventbox(model=state.model) |
---|
| 1433 | #wx.PostEvent(self.event_owner, evt) |
---|
[edd166b] | 1434 | |
---|
| 1435 | if self.engine_type != None: |
---|
| 1436 | self.manager._on_change_engine(engine=self.engine_type) |
---|
[7975f2b] | 1437 | |
---|
[edd166b] | 1438 | self.select_param(event = None) |
---|
| 1439 | #Save state_fit |
---|
[c985bef] | 1440 | self.save_current_state_fit() |
---|
[7975f2b] | 1441 | self._lay_out() |
---|
[c985bef] | 1442 | self.Refresh() |
---|
[edd166b] | 1443 | |
---|
[2140e68] | 1444 | def get_range(self): |
---|
| 1445 | """ |
---|
[5062bbf] | 1446 | return the fitting range |
---|
[2140e68] | 1447 | """ |
---|
[c9a4377] | 1448 | return float(self.qmin_x) , float(self.qmax_x) |
---|
[7975f2b] | 1449 | |
---|
| 1450 | def get_npts2fit(self): |
---|
| 1451 | """ |
---|
[5062bbf] | 1452 | return numbers of data points within qrange |
---|
| 1453 | |
---|
| 1454 | :Note: This is for Park where chi2 is not normalized by Npts of fit |
---|
| 1455 | |
---|
[7975f2b] | 1456 | """ |
---|
| 1457 | npts2fit = 0 |
---|
| 1458 | qmin,qmax = self.get_range() |
---|
[51a71a3] | 1459 | if self.data.__class__.__name__ =="Data2D": |
---|
[d7b7156] | 1460 | radius= numpy.sqrt( self.data.qx_data*self.data.qx_data + |
---|
| 1461 | self.data.qy_data*self.data.qy_data ) |
---|
[51a71a3] | 1462 | index_data = (self.qmin_x <= radius)&(radius<= self.qmax_x) |
---|
| 1463 | index_data= (index_data)&(self.data.mask) |
---|
| 1464 | index_data = (index_data)&(numpy.isfinite(self.data.data)) |
---|
| 1465 | npts2fit = len(self.data.data[index_data]) |
---|
[7975f2b] | 1466 | else: |
---|
| 1467 | for qx in self.data.x: |
---|
| 1468 | if qx >= qmin and qx <= qmax: |
---|
| 1469 | npts2fit += 1 |
---|
| 1470 | return npts2fit |
---|
| 1471 | |
---|
[51a71a3] | 1472 | def set_npts2fit(self): |
---|
| 1473 | """ |
---|
[5062bbf] | 1474 | setValue Npts for fitting |
---|
[51a71a3] | 1475 | """ |
---|
| 1476 | self.Npts_fit.SetValue(str(self.get_npts2fit())) |
---|
| 1477 | |
---|
[c69b6d5] | 1478 | def get_chi2(self): |
---|
| 1479 | """ |
---|
[5062bbf] | 1480 | return the current chi2 |
---|
[c69b6d5] | 1481 | """ |
---|
[2012eae] | 1482 | return self.tcChi.GetValue() |
---|
[c77d859] | 1483 | |
---|
| 1484 | def get_param_list(self): |
---|
| 1485 | """ |
---|
[5062bbf] | 1486 | :return self.param_toFit: list containing references to TextCtrl |
---|
[c77d859] | 1487 | checked.Theses TextCtrl will allow reference to parameters to fit. |
---|
[5062bbf] | 1488 | |
---|
| 1489 | :raise: if return an empty list of parameter fit will nnote work |
---|
[c77d859] | 1490 | properly so raise ValueError,"missing parameter to fit" |
---|
| 1491 | """ |
---|
| 1492 | if self.param_toFit !=[]: |
---|
| 1493 | return self.param_toFit |
---|
| 1494 | else: |
---|
| 1495 | raise ValueError,"missing parameter to fit" |
---|
| 1496 | |
---|
[6d91073] | 1497 | def onsetValues(self,chisqr,p_name, out,cov): |
---|
[c77d859] | 1498 | """ |
---|
[5062bbf] | 1499 | Build the panel from the fit result |
---|
| 1500 | |
---|
| 1501 | :param chisqr: Value of the goodness of fit metric |
---|
| 1502 | :param p_name: the name of parameters |
---|
| 1503 | :param out: list of parameter with the best value found during fitting |
---|
| 1504 | :param cov: Covariance matrix |
---|
| 1505 | |
---|
[c77d859] | 1506 | """ |
---|
[edd166b] | 1507 | if out == None or not numpy.isfinite(chisqr): |
---|
| 1508 | raise ValueError,"Fit error occured..." |
---|
| 1509 | |
---|
| 1510 | is_modified = False |
---|
| 1511 | has_error = False |
---|
[7975f2b] | 1512 | |
---|
| 1513 | #Hide textctrl boxes of errors. |
---|
[edd166b] | 1514 | self._clear_Err_on_Fit() |
---|
[7975f2b] | 1515 | |
---|
| 1516 | #Check if chi2 is finite |
---|
| 1517 | if chisqr != None or numpy.isfinite(chisqr): |
---|
[e575db9] | 1518 | #format chi2 |
---|
[7609f1a] | 1519 | if self.engine_type == "park": |
---|
[e575db9] | 1520 | npt_fit = float(self.get_npts2fit()) |
---|
[7609f1a] | 1521 | if npt_fit > 0: |
---|
| 1522 | chisqr =chisqr/npt_fit |
---|
[7975f2b] | 1523 | chi2 = format_number(chisqr) |
---|
[2012eae] | 1524 | self.tcChi.SetValue(chi2) |
---|
[7975f2b] | 1525 | self.tcChi.Refresh() |
---|
| 1526 | else: |
---|
[2012eae] | 1527 | self.tcChi.SetValue("-") |
---|
[c13b8cc] | 1528 | |
---|
[edd166b] | 1529 | #Hide error title |
---|
| 1530 | if self.text2_3.IsShown(): |
---|
| 1531 | self.text2_3.Hide() |
---|
| 1532 | |
---|
[e473e4f5] | 1533 | try: |
---|
| 1534 | n = self.disp_box.GetCurrentSelection() |
---|
| 1535 | dispersity= self.disp_box.GetClientData(n) |
---|
[7975f2b] | 1536 | if dispersity !=None and self.enable_disp.GetValue(): |
---|
| 1537 | name= dispersity.__name__ |
---|
| 1538 | if name == "GaussianDispersion": |
---|
| 1539 | if hasattr(self,"text_disp_1" ): |
---|
| 1540 | if self.text_disp_1 !=None: |
---|
| 1541 | self.text_disp_1.Hide() |
---|
[e473e4f5] | 1542 | except: |
---|
[7975f2b] | 1543 | dispersty = None |
---|
[e473e4f5] | 1544 | pass |
---|
[c77d859] | 1545 | #set the panel when fit result are float not list |
---|
[c99a6c5] | 1546 | if out.__class__== numpy.float64: |
---|
[c77d859] | 1547 | self.param_toFit[0][2].SetValue(format_number(out)) |
---|
[0a518e4c] | 1548 | |
---|
[c69b6d5] | 1549 | if self.param_toFit[0][4].IsShown: |
---|
| 1550 | self.param_toFit[0][4].Hide() |
---|
[c77d859] | 1551 | if cov !=None : |
---|
| 1552 | self.text2_3.Show(True) |
---|
[e473e4f5] | 1553 | try: |
---|
[7975f2b] | 1554 | if dispersity !=None: |
---|
| 1555 | name= dispersity.__name__ |
---|
[d7b7156] | 1556 | if name == "GaussianDispersion" and \ |
---|
| 1557 | self.enable_disp.GetValue(): |
---|
[7975f2b] | 1558 | if hasattr(self,"text_disp_1" ): |
---|
| 1559 | if self.text_disp_1 !=None: |
---|
| 1560 | self.text_disp_1.Show(True) |
---|
[e473e4f5] | 1561 | except: |
---|
| 1562 | pass |
---|
[c99a6c5] | 1563 | |
---|
[ad6dd4c] | 1564 | if cov[0]==None or not numpy.isfinite(cov[0]): |
---|
[c69b6d5] | 1565 | if self.param_toFit[0][3].IsShown: |
---|
| 1566 | self.param_toFit[0][3].Hide() |
---|
[7975f2b] | 1567 | else: |
---|
| 1568 | self.param_toFit[0][3].Show(True) |
---|
[69bee6d] | 1569 | self.param_toFit[0][4].Show(True) |
---|
[c69b6d5] | 1570 | self.param_toFit[0][4].SetValue(format_number(cov[0])) |
---|
[ffb838f] | 1571 | has_error = True |
---|
[c77d859] | 1572 | else: |
---|
[edd166b] | 1573 | |
---|
[c69b6d5] | 1574 | i = 0 |
---|
[c77d859] | 1575 | #Set the panel when fit result are list |
---|
[7975f2b] | 1576 | for item in self.param_toFit: |
---|
[edd166b] | 1577 | if len(item)>5 and item != None: |
---|
| 1578 | ## reset error value to initial state |
---|
[7975f2b] | 1579 | item[3].Hide() |
---|
| 1580 | item[4].Hide() |
---|
| 1581 | |
---|
[edd166b] | 1582 | for ind in range(len(out)): |
---|
| 1583 | |
---|
| 1584 | if item[1] == p_name[ind]: |
---|
| 1585 | break |
---|
[7975f2b] | 1586 | if len(out)<=len(self.param_toFit) and out[ind] !=None: |
---|
| 1587 | val_out = format_number(out[ind]) |
---|
| 1588 | item[2].SetValue(val_out) |
---|
[c99a6c5] | 1589 | |
---|
[7975f2b] | 1590 | if(cov !=None): |
---|
[edd166b] | 1591 | |
---|
| 1592 | try: |
---|
[7975f2b] | 1593 | if dispersity !=None: |
---|
| 1594 | name= dispersity.__name__ |
---|
[d7b7156] | 1595 | if name == "GaussianDispersion" and \ |
---|
| 1596 | self.enable_disp.GetValue(): |
---|
[7975f2b] | 1597 | if hasattr(self,"text_disp_1" ): |
---|
| 1598 | if self.text_disp_1!=None: |
---|
| 1599 | if not self.text_disp_1.IsShown(): |
---|
| 1600 | self.text_disp_1.Show(True) |
---|
[edd166b] | 1601 | except: |
---|
| 1602 | pass |
---|
| 1603 | |
---|
[7975f2b] | 1604 | if cov[ind]!=None : |
---|
| 1605 | if numpy.isfinite(float(cov[ind])): |
---|
| 1606 | val_err = format_number(cov[ind]) |
---|
| 1607 | item[3].Show(True) |
---|
| 1608 | item[4].Show(True) |
---|
| 1609 | item[4].SetValue(val_err) |
---|
| 1610 | |
---|
| 1611 | has_error = True |
---|
[e575db9] | 1612 | i += 1 |
---|
[c99a6c5] | 1613 | #Show error title when any errors displayed |
---|
[b421b1a] | 1614 | if has_error: |
---|
[c99a6c5] | 1615 | if not self.text2_3.IsShown(): |
---|
[edd166b] | 1616 | self.text2_3.Show(True) |
---|
[7975f2b] | 1617 | |
---|
| 1618 | ## save current state |
---|
| 1619 | self.save_current_state() |
---|
| 1620 | #plot model |
---|
| 1621 | self._draw_model() |
---|
| 1622 | self._lay_out() |
---|
| 1623 | #PostStatusEvent |
---|
[9237df4] | 1624 | msg = "Fit completed! " |
---|
[7975f2b] | 1625 | wx.PostEvent(self.manager.parent, StatusEvent(status=msg)) |
---|
[c69b6d5] | 1626 | |
---|
[7609f1a] | 1627 | def onPinholeSmear(self, event): |
---|
| 1628 | """ |
---|
[5062bbf] | 1629 | Create a custom pinhole smear object that will change the way residuals |
---|
| 1630 | are compute when fitting |
---|
| 1631 | |
---|
| 1632 | :Note: accuracy is given by strings'High','Med', 'Low' FOR 2d, |
---|
| 1633 | None for 1D |
---|
| 1634 | |
---|
[7609f1a] | 1635 | """ |
---|
| 1636 | |
---|
| 1637 | if self.check_invalid_panel(): |
---|
| 1638 | return |
---|
| 1639 | if self.model ==None: |
---|
[4470b10] | 1640 | self.disable_smearer.SetValue(True) |
---|
| 1641 | msg="Please select a Model first..." |
---|
| 1642 | wx.MessageBox(msg, 'Info') |
---|
[7609f1a] | 1643 | wx.PostEvent(self.manager.parent, StatusEvent(status=\ |
---|
| 1644 | "Smear: %s"%msg)) |
---|
| 1645 | return |
---|
[4470b10] | 1646 | |
---|
[2d409fa] | 1647 | # Need update param values |
---|
[f72333f] | 1648 | self._update_paramv_on_fit() |
---|
| 1649 | |
---|
[7609f1a] | 1650 | # msg default |
---|
| 1651 | msg = None |
---|
| 1652 | if event != None: |
---|
| 1653 | tcrtl= event.GetEventObject() |
---|
| 1654 | # event case of radio button |
---|
| 1655 | if tcrtl.GetValue()== True: |
---|
| 1656 | self.dx_min = 0.0 |
---|
| 1657 | self.dx_max = 0.0 |
---|
| 1658 | is_new_pinhole = True |
---|
| 1659 | else: |
---|
| 1660 | is_new_pinhole = self._is_changed_pinhole() |
---|
[d493f66] | 1661 | else: |
---|
[1da28b8] | 1662 | is_new_pinhole = True |
---|
[7609f1a] | 1663 | # if any value is changed |
---|
| 1664 | if is_new_pinhole: |
---|
| 1665 | msg = self._set_pinhole_smear() |
---|
| 1666 | # hide all silt sizer |
---|
| 1667 | self._hide_all_smear_info() |
---|
[f72333f] | 1668 | |
---|
[7609f1a] | 1669 | ##Calculate chi2 |
---|
[f72333f] | 1670 | temp_smearer = self.current_smearer |
---|
| 1671 | #self.compute_chisqr(smearer= temp_smearer) |
---|
| 1672 | |
---|
[7609f1a] | 1673 | # show relevant slit sizers |
---|
| 1674 | self._show_smear_sizer() |
---|
[f72333f] | 1675 | |
---|
[7609f1a] | 1676 | self.sizer_set_smearer.Layout() |
---|
| 1677 | self.Layout() |
---|
| 1678 | |
---|
| 1679 | if event != None: |
---|
| 1680 | event.Skip() |
---|
| 1681 | #self._undo.Enable(True) |
---|
| 1682 | self.save_current_state() |
---|
| 1683 | event = PageInfoEvent(page = self) |
---|
| 1684 | wx.PostEvent(self.parent, event) |
---|
| 1685 | |
---|
| 1686 | def _is_changed_pinhole(self): |
---|
| 1687 | """ |
---|
[5062bbf] | 1688 | check if any of pinhole smear is changed |
---|
| 1689 | |
---|
| 1690 | :return: True or False |
---|
| 1691 | |
---|
[7609f1a] | 1692 | """ |
---|
| 1693 | # get the values |
---|
| 1694 | pin_min = self.smear_pinhole_min.GetValue() |
---|
| 1695 | pin_max = self.smear_pinhole_max.GetValue() |
---|
| 1696 | |
---|
| 1697 | # Check changes in slit width |
---|
| 1698 | try: |
---|
| 1699 | dx_min = float(pin_min) |
---|
| 1700 | except: |
---|
| 1701 | return True |
---|
| 1702 | if self.dx_min != dx_min: |
---|
| 1703 | return True |
---|
| 1704 | |
---|
| 1705 | # Check changes in slit heigth |
---|
| 1706 | try: |
---|
| 1707 | dx_max = float(pin_max) |
---|
| 1708 | except: |
---|
| 1709 | return True |
---|
| 1710 | if self.dx_max != dx_max: |
---|
| 1711 | return True |
---|
| 1712 | return False |
---|
| 1713 | |
---|
| 1714 | def _set_pinhole_smear(self): |
---|
| 1715 | """ |
---|
[5062bbf] | 1716 | Set custom pinhole smear |
---|
| 1717 | |
---|
| 1718 | :return: msg |
---|
| 1719 | |
---|
[7609f1a] | 1720 | """ |
---|
| 1721 | # copy data |
---|
| 1722 | data = copy.deepcopy(self.data) |
---|
[f72333f] | 1723 | if self._is_2D(): |
---|
| 1724 | self.smear_type = 'Pinhole2d' |
---|
| 1725 | len_data = len(data.data) |
---|
| 1726 | data.dqx_data = numpy.zeros(len_data) |
---|
| 1727 | data.dqy_data = numpy.zeros(len_data) |
---|
| 1728 | else: |
---|
| 1729 | self.smear_type = 'Pinhole' |
---|
| 1730 | len_data = len(data.x) |
---|
| 1731 | data.dx = numpy.zeros(len_data) |
---|
| 1732 | data.dxl = None |
---|
| 1733 | data.dxw = None |
---|
[7609f1a] | 1734 | msg = None |
---|
| 1735 | |
---|
| 1736 | get_pin_min = self.smear_pinhole_min |
---|
| 1737 | get_pin_max = self.smear_pinhole_max |
---|
| 1738 | |
---|
[f72333f] | 1739 | if not check_float(get_pin_min): |
---|
| 1740 | get_pin_min.SetBackgroundColour("pink") |
---|
| 1741 | msg= "Model Error:wrong value entered!!!" |
---|
| 1742 | elif not check_float(get_pin_max ): |
---|
| 1743 | get_pin_max.SetBackgroundColour("pink") |
---|
| 1744 | msg= "Model Error:wrong value entered!!!" |
---|
| 1745 | else: |
---|
[7609f1a] | 1746 | if len_data < 2: len_data = 2 |
---|
| 1747 | self.dx_min = float(get_pin_min.GetValue()) |
---|
| 1748 | self.dx_max = float(get_pin_max.GetValue()) |
---|
[f72333f] | 1749 | if self.dx_min < 0: |
---|
| 1750 | get_pin_min.SetBackgroundColour("pink") |
---|
| 1751 | msg= "Model Error:This value can not be negative!!!" |
---|
| 1752 | elif self.dx_max <0: |
---|
| 1753 | get_pin_max.SetBackgroundColour("pink") |
---|
| 1754 | msg= "Model Error:This value can not be negative!!!" |
---|
| 1755 | elif self.dx_min != None and self.dx_max != None: |
---|
| 1756 | if self._is_2D(): |
---|
| 1757 | data.dqx_data[data.dqx_data==0] = self.dx_min |
---|
| 1758 | data.dqy_data[data.dqy_data==0] = self.dx_max |
---|
| 1759 | elif self.dx_min == self.dx_max: |
---|
[7609f1a] | 1760 | data.dx[data.dx==0] = self.dx_min |
---|
| 1761 | else: |
---|
[f72333f] | 1762 | step = (self.dx_max - self.dx_min)/(len_data-1) |
---|
[d7b7156] | 1763 | data.dx = numpy.arange(self.dx_min,self.dx_max+step/1.1, |
---|
| 1764 | step) |
---|
[7609f1a] | 1765 | elif self.dx_min != None: |
---|
[f72333f] | 1766 | if self._is_2D(): data.dqx_data[data.dqx_data==0] = self.dx_min |
---|
| 1767 | else: data.dx[data.dx==0] = self.dx_min |
---|
[7609f1a] | 1768 | elif self.dx_max != None: |
---|
[f72333f] | 1769 | if self._is_2D(): data.dqy_data[data.dqy_data==0] = self.dx_max |
---|
| 1770 | else: data.dx[data.dx==0] = self.dx_max |
---|
[f867cd9] | 1771 | self.current_smearer = smear_selection(data, self.model) |
---|
[4fbc93e] | 1772 | # 2D need to set accuracy |
---|
| 1773 | if self._is_2D(): |
---|
[d7b7156] | 1774 | self.current_smearer.set_accuracy(accuracy = \ |
---|
| 1775 | self.smear2d_accuracy) |
---|
[7609f1a] | 1776 | |
---|
[f72333f] | 1777 | if msg != None: |
---|
[7609f1a] | 1778 | wx.PostEvent(self.manager.parent, StatusEvent(status = msg )) |
---|
[f72333f] | 1779 | else: |
---|
| 1780 | get_pin_min.SetBackgroundColour("white") |
---|
| 1781 | get_pin_max.SetBackgroundColour("white") |
---|
[7609f1a] | 1782 | ## set smearing value whether or not the data contain the smearing info |
---|
[d7b7156] | 1783 | self.manager.set_smearer(smearer=self.current_smearer, qmin= \ |
---|
| 1784 | float(self.qmin_x),qmax= float(self.qmax_x)) |
---|
[7609f1a] | 1785 | return msg |
---|
| 1786 | |
---|
| 1787 | def update_pinhole_smear(self): |
---|
| 1788 | """ |
---|
[5062bbf] | 1789 | called by kill_focus on pinhole TextCntrl |
---|
| 1790 | to update the changes |
---|
| 1791 | |
---|
| 1792 | :return: False when wrong value was entered |
---|
| 1793 | |
---|
[7609f1a] | 1794 | """ |
---|
| 1795 | # msg default |
---|
| 1796 | msg = None |
---|
| 1797 | # check if any value is changed |
---|
| 1798 | if self._is_changed_pinhole(): |
---|
| 1799 | msg = self._set_pinhole_smear() |
---|
| 1800 | #self._undo.Enable(True) |
---|
| 1801 | self.save_current_state() |
---|
| 1802 | |
---|
| 1803 | if msg != None: |
---|
| 1804 | return False |
---|
| 1805 | else: |
---|
| 1806 | return True |
---|
| 1807 | |
---|
| 1808 | def onSlitSmear(self, event): |
---|
| 1809 | """ |
---|
[5062bbf] | 1810 | Create a custom slit smear object that will change the way residuals |
---|
| 1811 | are compute when fitting |
---|
[7609f1a] | 1812 | """ |
---|
[4470b10] | 1813 | |
---|
[7609f1a] | 1814 | if self.check_invalid_panel(): |
---|
| 1815 | return |
---|
[4470b10] | 1816 | |
---|
[7609f1a] | 1817 | if self.model ==None: |
---|
[4470b10] | 1818 | self.disable_smearer.SetValue(True) |
---|
| 1819 | |
---|
| 1820 | msg="Please select a Model first..." |
---|
| 1821 | wx.MessageBox(msg, 'Info') |
---|
[7609f1a] | 1822 | wx.PostEvent(self.manager.parent, StatusEvent(status=\ |
---|
| 1823 | "Smear: %s"%msg)) |
---|
| 1824 | return |
---|
[4470b10] | 1825 | |
---|
[2d409fa] | 1826 | # Need update param values |
---|
| 1827 | self._update_paramv_on_fit() |
---|
[f72333f] | 1828 | |
---|
[7609f1a] | 1829 | # msg default |
---|
| 1830 | msg = None |
---|
| 1831 | # for event given |
---|
| 1832 | if event != None: |
---|
| 1833 | tcrtl= event.GetEventObject() |
---|
| 1834 | # event case of radio button |
---|
| 1835 | if tcrtl.GetValue(): |
---|
| 1836 | self.dxl = 0.0 |
---|
| 1837 | self.dxw = 0.0 |
---|
| 1838 | is_new_slit = True |
---|
| 1839 | else: |
---|
| 1840 | is_new_slit = self._is_changed_slit() |
---|
[d493f66] | 1841 | else: |
---|
[1da28b8] | 1842 | is_new_slit = True |
---|
[4470b10] | 1843 | |
---|
[7609f1a] | 1844 | # if any value is changed |
---|
| 1845 | if is_new_slit: |
---|
| 1846 | msg = self._set_slit_smear() |
---|
[4470b10] | 1847 | |
---|
[7609f1a] | 1848 | # hide all silt sizer |
---|
| 1849 | self._hide_all_smear_info() |
---|
| 1850 | ##Calculate chi2 |
---|
[f72333f] | 1851 | #self.compute_chisqr(smearer= self.current_smearer) |
---|
[7609f1a] | 1852 | # show relevant slit sizers |
---|
| 1853 | self._show_smear_sizer() |
---|
| 1854 | self.sizer_set_smearer.Layout() |
---|
| 1855 | self.Layout() |
---|
[4470b10] | 1856 | |
---|
[7609f1a] | 1857 | if event != None: |
---|
| 1858 | event.Skip() |
---|
| 1859 | #self._undo.Enable(True) |
---|
| 1860 | self.save_current_state() |
---|
| 1861 | event = PageInfoEvent(page = self) |
---|
| 1862 | wx.PostEvent(self.parent, event) |
---|
| 1863 | if msg != None: |
---|
| 1864 | wx.PostEvent(self.manager.parent, StatusEvent(status = msg)) |
---|
| 1865 | |
---|
| 1866 | def _is_changed_slit(self): |
---|
| 1867 | """ |
---|
[5062bbf] | 1868 | check if any of slit lengths is changed |
---|
| 1869 | |
---|
| 1870 | :return: True or False |
---|
[4470b10] | 1871 | |
---|
[5062bbf] | 1872 | """ |
---|
[7609f1a] | 1873 | # get the values |
---|
| 1874 | width = self.smear_slit_width.GetValue() |
---|
| 1875 | height = self.smear_slit_height.GetValue() |
---|
| 1876 | |
---|
[d7b7156] | 1877 | # check and change the box bg color if it was pink |
---|
| 1878 | # but it should be white now |
---|
[7609f1a] | 1879 | # because this is the case that _set_slit_smear() will not handle |
---|
| 1880 | if height.lstrip().rstrip()=="": |
---|
| 1881 | self.smear_slit_height.SetBackgroundColour(wx.WHITE) |
---|
| 1882 | if width.lstrip().rstrip()=="": |
---|
| 1883 | self.smear_slit_width.SetBackgroundColour(wx.WHITE) |
---|
| 1884 | |
---|
| 1885 | # Check changes in slit width |
---|
| 1886 | if width == "": |
---|
| 1887 | dxw = 0.0 |
---|
| 1888 | else: |
---|
| 1889 | try: |
---|
| 1890 | dxw = float(width) |
---|
| 1891 | except: |
---|
| 1892 | return True |
---|
| 1893 | if self.dxw != dxw: |
---|
| 1894 | return True |
---|
| 1895 | |
---|
| 1896 | # Check changes in slit heigth |
---|
| 1897 | if height == "": |
---|
| 1898 | dxl = 0.0 |
---|
| 1899 | else: |
---|
| 1900 | try: |
---|
| 1901 | dxl = float(height) |
---|
| 1902 | except: |
---|
| 1903 | return True |
---|
| 1904 | if self.dxl != dxl: |
---|
| 1905 | return True |
---|
[4470b10] | 1906 | |
---|
[7609f1a] | 1907 | return False |
---|
| 1908 | |
---|
| 1909 | def _set_slit_smear(self): |
---|
| 1910 | """ |
---|
[5062bbf] | 1911 | Set custom slit smear |
---|
| 1912 | |
---|
| 1913 | :return: message to inform the user about the validity |
---|
| 1914 | of the values entered for slit smear |
---|
[7609f1a] | 1915 | """ |
---|
[0b12abb5] | 1916 | if self.data.__class__.__name__ == "Data2D": |
---|
| 1917 | return |
---|
[7609f1a] | 1918 | temp_smearer = None |
---|
| 1919 | # make sure once more if it is smearer |
---|
| 1920 | data = copy.deepcopy(self.data) |
---|
| 1921 | data_len = len(data.x) |
---|
| 1922 | data.dx = None |
---|
| 1923 | data.dxl = None |
---|
| 1924 | data.dxw = None |
---|
| 1925 | msg = None |
---|
| 1926 | |
---|
| 1927 | try: |
---|
| 1928 | self.dxl = float(self.smear_slit_height.GetValue()) |
---|
| 1929 | data.dxl = self.dxl* numpy.ones(data_len) |
---|
| 1930 | self.smear_slit_height.SetBackgroundColour(wx.WHITE) |
---|
| 1931 | except: |
---|
| 1932 | data.dxl = numpy.zeros(data_len) |
---|
| 1933 | if self.smear_slit_height.GetValue().lstrip().rstrip()!="": |
---|
| 1934 | self.smear_slit_height.SetBackgroundColour("pink") |
---|
| 1935 | msg = "Wrong value entered... " |
---|
| 1936 | else: |
---|
| 1937 | self.smear_slit_height.SetBackgroundColour(wx.WHITE) |
---|
| 1938 | try: |
---|
| 1939 | self.dxw = float(self.smear_slit_width.GetValue()) |
---|
| 1940 | self.smear_slit_width.SetBackgroundColour(wx.WHITE) |
---|
| 1941 | data.dxw = self.dxw* numpy.ones(data_len) |
---|
| 1942 | except: |
---|
| 1943 | data.dxw = numpy.zeros(data_len) |
---|
| 1944 | if self.smear_slit_width.GetValue().lstrip().rstrip()!="": |
---|
| 1945 | self.smear_slit_width.SetBackgroundColour("pink") |
---|
| 1946 | msg = "Wrong Fit value entered... " |
---|
| 1947 | else: |
---|
| 1948 | self.smear_slit_width.SetBackgroundColour(wx.WHITE) |
---|
[4470b10] | 1949 | |
---|
[f867cd9] | 1950 | self.current_smearer = smear_selection(data, self.model) |
---|
[7609f1a] | 1951 | #temp_smearer = self.current_smearer |
---|
| 1952 | ## set smearing value whether or not the data contain the smearing info |
---|
[d7b7156] | 1953 | self.manager.set_smearer(smearer=self.current_smearer, qmin= \ |
---|
| 1954 | float(self.qmin_x), qmax= float(self.qmax_x)) |
---|
[7609f1a] | 1955 | return msg |
---|
| 1956 | |
---|
| 1957 | def update_slit_smear(self): |
---|
| 1958 | """ |
---|
[5062bbf] | 1959 | called by kill_focus on pinhole TextCntrl |
---|
| 1960 | to update the changes |
---|
| 1961 | |
---|
| 1962 | :return: False when wrong value was entered |
---|
| 1963 | |
---|
[7609f1a] | 1964 | """ |
---|
| 1965 | # msg default |
---|
| 1966 | msg = None |
---|
| 1967 | # check if any value is changed |
---|
| 1968 | if self._is_changed_slit(): |
---|
| 1969 | msg = self._set_slit_smear() |
---|
| 1970 | #self._undo.Enable(True) |
---|
| 1971 | self.save_current_state() |
---|
| 1972 | |
---|
| 1973 | if msg != None: |
---|
| 1974 | return False |
---|
| 1975 | else: |
---|
| 1976 | return True |
---|
| 1977 | |
---|
[c77d859] | 1978 | def onSmear(self, event): |
---|
| 1979 | """ |
---|
[5062bbf] | 1980 | Create a smear object that will change the way residuals |
---|
| 1981 | are compute when fitting |
---|
[c77d859] | 1982 | """ |
---|
[f72333f] | 1983 | if event != None: |
---|
| 1984 | event.Skip() |
---|
[ffa69b6] | 1985 | if self.check_invalid_panel(): |
---|
| 1986 | return |
---|
[64bda1e] | 1987 | if self.model == None: |
---|
[4470b10] | 1988 | self.disable_smearer.SetValue(True) |
---|
| 1989 | msg="Please select a Model first..." |
---|
| 1990 | wx.MessageBox(msg, 'Info') |
---|
[2a2af47] | 1991 | wx.PostEvent(self.manager.parent, StatusEvent(status=\ |
---|
| 1992 | "Smear: %s"%msg)) |
---|
| 1993 | return |
---|
[f72333f] | 1994 | |
---|
[2d409fa] | 1995 | # Need update param values |
---|
| 1996 | self._update_paramv_on_fit() |
---|
[f72333f] | 1997 | |
---|
[3370922] | 1998 | temp_smearer = None |
---|
[7609f1a] | 1999 | self._get_smear_info() |
---|
| 2000 | |
---|
| 2001 | #renew smear sizer |
---|
| 2002 | if self.smear_type != None: |
---|
| 2003 | self.smear_description_smear_type.SetValue(str(self.smear_type)) |
---|
| 2004 | self.smear_data_left.SetValue(str(self.dq_l)) |
---|
| 2005 | self.smear_data_right.SetValue(str(self.dq_r)) |
---|
[f72333f] | 2006 | |
---|
[7609f1a] | 2007 | self._hide_all_smear_info() |
---|
| 2008 | |
---|
| 2009 | data = copy.deepcopy(self.data) |
---|
| 2010 | # make sure once more if it is smearer |
---|
[f867cd9] | 2011 | self.current_smearer = smear_selection(data, self.model) |
---|
[f72333f] | 2012 | |
---|
[c77d859] | 2013 | if self.enable_smearer.GetValue(): |
---|
| 2014 | if hasattr(self.data,"dxl"): |
---|
[7609f1a] | 2015 | |
---|
[c77d859] | 2016 | msg= ": Resolution smearing parameters" |
---|
| 2017 | if hasattr(self.data,"dxw"): |
---|
| 2018 | msg= ": Slit smearing parameters" |
---|
[997131a] | 2019 | if self.smearer ==None: |
---|
[c77d859] | 2020 | wx.PostEvent(self.manager.parent, StatusEvent(status=\ |
---|
| 2021 | "Data contains no smearing information")) |
---|
| 2022 | else: |
---|
| 2023 | wx.PostEvent(self.manager.parent, StatusEvent(status=\ |
---|
[f72333f] | 2024 | "Data contains smearing information")) |
---|
| 2025 | |
---|
| 2026 | #self.smear_description_dqdata.Show(True) |
---|
[7609f1a] | 2027 | self.smear_data_left.Show(True) |
---|
| 2028 | self.smear_data_right.Show(True) |
---|
[f72333f] | 2029 | temp_smearer= self.current_smearer |
---|
[7609f1a] | 2030 | elif self.disable_smearer.GetValue(): |
---|
| 2031 | self.smear_description_none.Show(True) |
---|
| 2032 | |
---|
| 2033 | self._show_smear_sizer() |
---|
[f72333f] | 2034 | |
---|
[7609f1a] | 2035 | self.sizer_set_smearer.Layout() |
---|
| 2036 | self.Layout() |
---|
[fb8daaaf] | 2037 | ## set smearing value whether or not the data contain the smearing info |
---|
[3370922] | 2038 | self.manager.set_smearer(smearer=temp_smearer, qmin= float(self.qmin_x), |
---|
[2b63df0] | 2039 | qmax= float(self.qmax_x)) |
---|
[f72333f] | 2040 | |
---|
[875f1a2] | 2041 | ##Calculate chi2 |
---|
[f72333f] | 2042 | #self.compute_chisqr(smearer= temp_smearer) |
---|
[5582a9f1] | 2043 | |
---|
| 2044 | self.state.enable_smearer= self.enable_smearer.GetValue() |
---|
| 2045 | self.state.disable_smearer=self.disable_smearer.GetValue() |
---|
[7609f1a] | 2046 | self.state.pinhole_smearer = self.pinhole_smearer.GetValue() |
---|
| 2047 | self.state.slit_smearer = self.slit_smearer.GetValue() |
---|
[f72333f] | 2048 | |
---|
| 2049 | def on_complete_chisqr(self, event): |
---|
| 2050 | """ |
---|
[5062bbf] | 2051 | print result chisqr |
---|
| 2052 | |
---|
| 2053 | :event: activated by fitting/ complete after draw |
---|
| 2054 | |
---|
[f72333f] | 2055 | """ |
---|
| 2056 | try: |
---|
| 2057 | if event ==None: |
---|
| 2058 | output= "-" |
---|
| 2059 | else: |
---|
| 2060 | output = event.output |
---|
| 2061 | self.tcChi.SetValue(str(format_number(output))) |
---|
| 2062 | |
---|
[3c44c66] | 2063 | self.state.tcChi = self.tcChi.GetValue() |
---|
[f72333f] | 2064 | except: |
---|
| 2065 | pass |
---|
[c77d859] | 2066 | |
---|
[5062bbf] | 2067 | |
---|
[c77d859] | 2068 | def select_all_param(self,event): |
---|
| 2069 | """ |
---|
[5062bbf] | 2070 | set to true or false all checkBox given the main checkbox value cb1 |
---|
[d1e0473] | 2071 | """ |
---|
[c77d859] | 2072 | self.param_toFit=[] |
---|
| 2073 | if self.parameters !=[]: |
---|
[998b6b8] | 2074 | if self.cb1.GetValue(): |
---|
[c77d859] | 2075 | for item in self.parameters: |
---|
[3fef0a8] | 2076 | ## for data2D select all to fit |
---|
| 2077 | if self.data.__class__.__name__=="Data2D": |
---|
[c77d859] | 2078 | item[0].SetValue(True) |
---|
| 2079 | self.param_toFit.append(item ) |
---|
[3fef0a8] | 2080 | else: |
---|
| 2081 | ## for 1D all parameters except orientation |
---|
| 2082 | if not item in self.orientation_params: |
---|
| 2083 | item[0].SetValue(True) |
---|
| 2084 | self.param_toFit.append(item ) |
---|
[b324aa9] | 2085 | #if len(self.fittable_param)>0: |
---|
| 2086 | for item in self.fittable_param: |
---|
| 2087 | if self.data.__class__.__name__=="Data2D": |
---|
| 2088 | item[0].SetValue(True) |
---|
| 2089 | self.param_toFit.append(item ) |
---|
| 2090 | else: |
---|
| 2091 | ## for 1D all parameters except orientation |
---|
| 2092 | if not item in self.orientation_params_disp: |
---|
[3fef0a8] | 2093 | item[0].SetValue(True) |
---|
| 2094 | self.param_toFit.append(item ) |
---|
[c77d859] | 2095 | else: |
---|
| 2096 | for item in self.parameters: |
---|
| 2097 | item[0].SetValue(False) |
---|
| 2098 | for item in self.fittable_param: |
---|
| 2099 | item[0].SetValue(False) |
---|
| 2100 | self.param_toFit=[] |
---|
[330573d] | 2101 | |
---|
[52cac46] | 2102 | self.save_current_state_fit() |
---|
[b324aa9] | 2103 | |
---|
[3595309d] | 2104 | if event !=None: |
---|
[3a37fe0] | 2105 | #self._undo.Enable(True) |
---|
[3595309d] | 2106 | ## post state to fit panel |
---|
| 2107 | event = PageInfoEvent(page = self) |
---|
| 2108 | wx.PostEvent(self.parent, event) |
---|
| 2109 | |
---|
[c77d859] | 2110 | def select_param(self,event): |
---|
| 2111 | """ |
---|
[5062bbf] | 2112 | Select TextCtrl checked for fitting purpose and stores them |
---|
| 2113 | in self.param_toFit=[] list |
---|
[c77d859] | 2114 | """ |
---|
| 2115 | self.param_toFit=[] |
---|
| 2116 | for item in self.parameters: |
---|
[edd166b] | 2117 | #Skip t ifhe angle parameters if 1D data |
---|
| 2118 | if self.data.__class__.__name__ !="Data2D": |
---|
| 2119 | if item in self.orientation_params: |
---|
| 2120 | continue |
---|
[c77d859] | 2121 | #Select parameters to fit for list of primary parameters |
---|
[998b6b8] | 2122 | if item[0].GetValue(): |
---|
[c77d859] | 2123 | if not (item in self.param_toFit): |
---|
| 2124 | self.param_toFit.append(item ) |
---|
| 2125 | else: |
---|
| 2126 | #remove parameters from the fitting list |
---|
| 2127 | if item in self.param_toFit: |
---|
| 2128 | self.param_toFit.remove(item) |
---|
[edd166b] | 2129 | |
---|
[d7b7156] | 2130 | #Select parameters to fit for list of fittable parameters |
---|
| 2131 | # with dispersion |
---|
[c77d859] | 2132 | for item in self.fittable_param: |
---|
[edd166b] | 2133 | #Skip t ifhe angle parameters if 1D data |
---|
| 2134 | if self.data.__class__.__name__ !="Data2D": |
---|
| 2135 | if item in self.orientation_params: |
---|
| 2136 | continue |
---|
[998b6b8] | 2137 | if item[0].GetValue(): |
---|
[c77d859] | 2138 | if not (item in self.param_toFit): |
---|
| 2139 | self.param_toFit.append(item) |
---|
| 2140 | else: |
---|
| 2141 | #remove parameters from the fitting list |
---|
| 2142 | if item in self.param_toFit: |
---|
[edd166b] | 2143 | self.param_toFit.remove(item) |
---|
| 2144 | |
---|
| 2145 | #Calculate num. of angle parameters |
---|
| 2146 | if self.data.__class__.__name__ =="Data2D": |
---|
| 2147 | len_orient_para = 0 |
---|
| 2148 | else: |
---|
| 2149 | len_orient_para = len(self.orientation_params) #assume even len |
---|
| 2150 | #Total num. of angle parameters |
---|
| 2151 | if len(self.fittable_param) > 0: |
---|
| 2152 | len_orient_para *= 2 |
---|
[c77d859] | 2153 | #Set the value of checkbox that selected every checkbox or not |
---|
[d7b7156] | 2154 | if len(self.parameters)+len(self.fittable_param)-len_orient_para ==\ |
---|
| 2155 | len(self.param_toFit): |
---|
[c77d859] | 2156 | self.cb1.SetValue(True) |
---|
| 2157 | else: |
---|
| 2158 | self.cb1.SetValue(False) |
---|
[52cac46] | 2159 | self.save_current_state_fit() |
---|
[3595309d] | 2160 | if event !=None: |
---|
[3a37fe0] | 2161 | #self._undo.Enable(True) |
---|
[3595309d] | 2162 | ## post state to fit panel |
---|
| 2163 | event = PageInfoEvent(page = self) |
---|
| 2164 | wx.PostEvent(self.parent, event) |
---|
[c77d859] | 2165 | |
---|
[77e23a2] | 2166 | def set_model_param_sizer(self, model): |
---|
[c77d859] | 2167 | """ |
---|
[5062bbf] | 2168 | Build the panel from the model content |
---|
| 2169 | |
---|
| 2170 | :param model: the model selected in combo box for fitting purpose |
---|
| 2171 | |
---|
[c77d859] | 2172 | """ |
---|
| 2173 | self.sizer3.Clear(True) |
---|
| 2174 | self.parameters = [] |
---|
[fb59ed9] | 2175 | self.str_parameters = [] |
---|
[c77d859] | 2176 | self.param_toFit=[] |
---|
| 2177 | self.fittable_param=[] |
---|
| 2178 | self.fixed_param=[] |
---|
[780d095] | 2179 | self.orientation_params=[] |
---|
[60132ef] | 2180 | self.orientation_params_disp=[] |
---|
[c77d859] | 2181 | |
---|
| 2182 | if model ==None: |
---|
| 2183 | self.sizer3.Layout() |
---|
[015d109] | 2184 | self.SetupScrolling() |
---|
[c77d859] | 2185 | return |
---|
[707436d] | 2186 | ## the panel is drawn using the current value of the fit engine |
---|
| 2187 | if self.engine_type==None and self.manager !=None: |
---|
| 2188 | self.engine_type= self.manager._return_engine_type() |
---|
[c99a6c5] | 2189 | |
---|
[c77d859] | 2190 | box_description= wx.StaticBox(self, -1,str("Model Parameters")) |
---|
| 2191 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
| 2192 | sizer = wx.GridBagSizer(5,5) |
---|
| 2193 | ## save the current model |
---|
| 2194 | self.model = model |
---|
| 2195 | |
---|
| 2196 | keys = self.model.getParamList() |
---|
| 2197 | #list of dispersion paramaters |
---|
| 2198 | self.disp_list=self.model.getDispParamList() |
---|
[b421b1a] | 2199 | |
---|
[db08737] | 2200 | def custom_compare(a,b): |
---|
| 2201 | """ |
---|
| 2202 | Custom compare to order, first by alphabets then second by number. |
---|
| 2203 | """ |
---|
[fb59ed9] | 2204 | # number at the last digit |
---|
[db08737] | 2205 | a_last = a[len(a)-1] |
---|
| 2206 | b_last = b[len(b)-1] |
---|
[fb59ed9] | 2207 | # default |
---|
[db08737] | 2208 | num_a = None |
---|
| 2209 | num_b = None |
---|
[fb59ed9] | 2210 | # split the names |
---|
| 2211 | a2 = a.lower().split('_') |
---|
| 2212 | b2 = b.lower().split('_') |
---|
| 2213 | # check length of a2, b2 |
---|
| 2214 | len_a2 = len(a2) |
---|
| 2215 | len_b2 = len(b2) |
---|
[db08737] | 2216 | # check if it contains a int number(<10) |
---|
| 2217 | try: |
---|
| 2218 | num_a = int(a_last) |
---|
| 2219 | except: pass |
---|
| 2220 | try: |
---|
| 2221 | num_b = int(b_last) |
---|
| 2222 | except: pass |
---|
[fb59ed9] | 2223 | # Put 'scale' near the top; happens |
---|
| 2224 | # when numbered param name exists |
---|
| 2225 | if a == 'scale': |
---|
| 2226 | return -1 |
---|
[db08737] | 2227 | # both have a number |
---|
| 2228 | if num_a != None and num_b != None: |
---|
[fb59ed9] | 2229 | if num_a > num_b: return -1 |
---|
| 2230 | # same number |
---|
[db08737] | 2231 | elif num_a == num_b: |
---|
[fb59ed9] | 2232 | # different last names |
---|
| 2233 | if a2[len_a2-1] != b2[len_b2-1] and num_a != 0: |
---|
| 2234 | return -cmp(a2[len_a2-1], b2[len_b2-1]) |
---|
| 2235 | else: |
---|
| 2236 | return cmp(a, b) |
---|
| 2237 | else: return 1 |
---|
[db08737] | 2238 | # one of them has a number |
---|
[20905a0] | 2239 | elif num_a != None: return 1 |
---|
| 2240 | elif num_b != None: return -1 |
---|
[fb59ed9] | 2241 | # no numbers |
---|
[20905a0] | 2242 | else: return cmp(a.lower(), b.lower()) |
---|
[fb59ed9] | 2243 | |
---|
[20905a0] | 2244 | |
---|
[db08737] | 2245 | keys.sort(custom_compare) |
---|
[c77d859] | 2246 | |
---|
[6dc9ad8] | 2247 | iy = 0 |
---|
[c77d859] | 2248 | ix = 0 |
---|
[2f6c260] | 2249 | select_text = "Select All" |
---|
[b324aa9] | 2250 | self.cb1 = wx.CheckBox(self, -1,str(select_text), (10, 10)) |
---|
[c77d859] | 2251 | wx.EVT_CHECKBOX(self, self.cb1.GetId(), self.select_all_param) |
---|
[2f6c260] | 2252 | self.cb1.SetToolTipString("To check/uncheck all the boxes below.") |
---|
| 2253 | #self.cb1.SetValue(True) |
---|
[c77d859] | 2254 | |
---|
| 2255 | sizer.Add(self.cb1,(iy, ix),(1,1),\ |
---|
[eda428b] | 2256 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 5) |
---|
[c77d859] | 2257 | ix +=1 |
---|
| 2258 | self.text2_2 = wx.StaticText(self, -1, 'Values') |
---|
| 2259 | sizer.Add(self.text2_2,(iy, ix),(1,1),\ |
---|
| 2260 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 2261 | ix +=2 |
---|
| 2262 | self.text2_3 = wx.StaticText(self, -1, 'Errors') |
---|
| 2263 | sizer.Add(self.text2_3,(iy, ix),(1,1),\ |
---|
| 2264 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 2265 | self.text2_3.Hide() |
---|
| 2266 | ix +=1 |
---|
| 2267 | self.text2_min = wx.StaticText(self, -1, 'Min') |
---|
| 2268 | sizer.Add(self.text2_min,(iy, ix),(1,1),\ |
---|
| 2269 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 2270 | self.text2_min.Hide() |
---|
| 2271 | ix +=1 |
---|
| 2272 | self.text2_max = wx.StaticText(self, -1, 'Max') |
---|
| 2273 | sizer.Add(self.text2_max,(iy, ix),(1,1),\ |
---|
| 2274 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 2275 | self.text2_max.Hide() |
---|
[6fdfc8f] | 2276 | ix += 1 |
---|
| 2277 | self.text2_4 = wx.StaticText(self, -1, '[Units]') |
---|
| 2278 | sizer.Add(self.text2_4,(iy, ix),(1,1),\ |
---|
| 2279 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 2280 | self.text2_4.Hide() |
---|
[dcf29d7] | 2281 | if self.engine_type=="park": |
---|
| 2282 | self.text2_max.Show(True) |
---|
| 2283 | self.text2_min.Show(True) |
---|
[b421b1a] | 2284 | |
---|
[c77d859] | 2285 | for item in keys: |
---|
[d7b7156] | 2286 | if not item in self.disp_list and not item in \ |
---|
| 2287 | self.model.orientation_params: |
---|
[b421b1a] | 2288 | |
---|
| 2289 | ##prepare a spot to store errors |
---|
| 2290 | if not self.model.details.has_key(item): |
---|
| 2291 | self.model.details [item] = ["",None,None] |
---|
| 2292 | |
---|
[c77d859] | 2293 | iy += 1 |
---|
| 2294 | ix = 0 |
---|
[d7b7156] | 2295 | if self.model.__class__ in \ |
---|
| 2296 | self.model_list_box["Multi-Functions"] \ |
---|
[fb59ed9] | 2297 | and item in self.model.non_fittable: |
---|
| 2298 | non_fittable_name = wx.StaticText(self, -1, item ) |
---|
| 2299 | sizer.Add(non_fittable_name,(iy, ix),(1,1),\ |
---|
| 2300 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 21) |
---|
| 2301 | ## add parameter value |
---|
| 2302 | ix += 1 |
---|
| 2303 | value= self.model.getParam(item) |
---|
| 2304 | if len(self.model.fun_list) > 0: |
---|
| 2305 | num = item.split('_')[1][5:7] |
---|
[d7b7156] | 2306 | fun_box = wx.ComboBox(self, -1,size=(100,-1), |
---|
| 2307 | style=wx.CB_READONLY, name = '%s'% item) |
---|
[fb59ed9] | 2308 | self._set_fun_box_list(fun_box) |
---|
| 2309 | fun_box.SetSelection(0) |
---|
[d7b7156] | 2310 | #self.fun_box.SetToolTipString("A function |
---|
| 2311 | # describing the interface") |
---|
[fb59ed9] | 2312 | wx.EVT_COMBOBOX(fun_box,-1, self._on_fun_box) |
---|
| 2313 | else: |
---|
[d7b7156] | 2314 | fun_box = self.ModelTextCtrl(self, -1, |
---|
| 2315 | size=(_BOX_WIDTH,20), |
---|
| 2316 | style=wx.TE_PROCESS_ENTER, name ='%s'% item) |
---|
[fb59ed9] | 2317 | fun_box.SetToolTipString("Hit 'Enter' after typing.") |
---|
| 2318 | fun_box.SetValue(format_number(value)) |
---|
| 2319 | sizer.Add(fun_box, (iy,ix),(1,1), wx.EXPAND) |
---|
[d7b7156] | 2320 | self.str_parameters.append([None,item, fun_box, |
---|
| 2321 | None,None,None,None,None]) |
---|
[fb59ed9] | 2322 | |
---|
| 2323 | |
---|
[7975f2b] | 2324 | else: |
---|
[fb59ed9] | 2325 | ## add parameters name with checkbox for selecting to fit |
---|
| 2326 | cb = wx.CheckBox(self, -1, item ) |
---|
| 2327 | cb.SetToolTipString(" Check for fitting.") |
---|
| 2328 | #cb.SetValue(True) |
---|
| 2329 | wx.EVT_CHECKBOX(self, cb.GetId(), self.select_param) |
---|
[dcf29d7] | 2330 | |
---|
[fb59ed9] | 2331 | sizer.Add( cb,( iy, ix),(1,1), |
---|
| 2332 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 5) |
---|
| 2333 | |
---|
| 2334 | ## add parameter value |
---|
| 2335 | ix += 1 |
---|
| 2336 | value= self.model.getParam(item) |
---|
| 2337 | ctl1 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH,20), |
---|
| 2338 | style=wx.TE_PROCESS_ENTER) |
---|
| 2339 | ctl1.SetToolTipString("Hit 'Enter' after typing.") |
---|
| 2340 | ctl1.SetValue(format_number(value)) |
---|
| 2341 | sizer.Add(ctl1, (iy,ix),(1,1), wx.EXPAND) |
---|
| 2342 | ## text to show error sign |
---|
| 2343 | ix += 1 |
---|
| 2344 | text2=wx.StaticText(self, -1, '+/-') |
---|
| 2345 | sizer.Add(text2,(iy, ix),(1,1),\ |
---|
| 2346 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 2347 | text2.Hide() |
---|
| 2348 | ix += 1 |
---|
| 2349 | ctl2 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=0) |
---|
[d7b7156] | 2350 | sizer.Add(ctl2, (iy,ix),(1,1), |
---|
| 2351 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[fb59ed9] | 2352 | ctl2.Hide() |
---|
| 2353 | |
---|
| 2354 | ix += 1 |
---|
[d7b7156] | 2355 | ctl3 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/2,20), |
---|
| 2356 | style=wx.TE_PROCESS_ENTER, |
---|
| 2357 | text_enter_callback = self._onparamRangeEnter) |
---|
[fb59ed9] | 2358 | |
---|
[d7b7156] | 2359 | sizer.Add(ctl3, (iy,ix),(1,1), |
---|
| 2360 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[fb59ed9] | 2361 | ctl3.Hide() |
---|
| 2362 | |
---|
| 2363 | ix += 1 |
---|
[d7b7156] | 2364 | ctl4 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/2,20), |
---|
| 2365 | style=wx.TE_PROCESS_ENTER, |
---|
| 2366 | text_enter_callback = self._onparamRangeEnter) |
---|
| 2367 | sizer.Add(ctl4, (iy,ix),(1,1), |
---|
| 2368 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[fb59ed9] | 2369 | |
---|
| 2370 | ctl4.Hide() |
---|
| 2371 | |
---|
| 2372 | if self.engine_type=="park": |
---|
| 2373 | ctl3.Show(True) |
---|
| 2374 | ctl4.Show(True) |
---|
| 2375 | ix +=1 |
---|
| 2376 | # Units |
---|
| 2377 | if self.model.details.has_key(item): |
---|
[d7b7156] | 2378 | units = wx.StaticText(self, -1, |
---|
| 2379 | self.model.details[item][0], style=wx.ALIGN_LEFT) |
---|
[fb59ed9] | 2380 | else: |
---|
| 2381 | units = wx.StaticText(self, -1, "", style=wx.ALIGN_LEFT) |
---|
[d7b7156] | 2382 | sizer.Add(units, (iy,ix),(1,1), |
---|
| 2383 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[fb59ed9] | 2384 | |
---|
| 2385 | ##[cb state, name, value, "+/-", error of fit, min, max , units] |
---|
| 2386 | self.parameters.append([cb,item, ctl1, |
---|
| 2387 | text2,ctl2, ctl3, ctl4,units]) |
---|
| 2388 | |
---|
[c77d859] | 2389 | iy+=1 |
---|
[d7b7156] | 2390 | sizer.Add((10,10),(iy,ix),(1,1), |
---|
| 2391 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
[5af5183] | 2392 | |
---|
[f20767b] | 2393 | # type can be either Guassian or Array |
---|
[5b53a5c] | 2394 | if len(self.model.dispersion.values())>0: |
---|
| 2395 | type= self.model.dispersion.values()[0]["type"] |
---|
| 2396 | else: |
---|
| 2397 | type = "Gaussian" |
---|
[6dc9ad8] | 2398 | |
---|
| 2399 | iy += 1 |
---|
| 2400 | ix = 0 |
---|
| 2401 | #Add tile for orientational angle |
---|
| 2402 | for item in keys: |
---|
| 2403 | if item in self.model.orientation_params: |
---|
| 2404 | orient_angle = wx.StaticText(self, -1, '[For 2D only]:') |
---|
[d7b7156] | 2405 | sizer.Add(orient_angle,(iy, ix),(1,1), |
---|
| 2406 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
[6dc9ad8] | 2407 | if not self.data.__class__.__name__ =="Data2D": |
---|
| 2408 | orient_angle.Hide() |
---|
| 2409 | else: |
---|
| 2410 | orient_angle.Show(True) |
---|
| 2411 | break |
---|
[5b53a5c] | 2412 | |
---|
[f20767b] | 2413 | #For Gaussian only |
---|
| 2414 | if type.lower() != "array": |
---|
| 2415 | for item in self.model.orientation_params: |
---|
| 2416 | if not item in self.disp_list: |
---|
[c13b8cc] | 2417 | ##prepare a spot to store min max |
---|
| 2418 | if not self.model.details.has_key(item): |
---|
| 2419 | self.model.details [item] = ["",None,None] |
---|
| 2420 | |
---|
[f20767b] | 2421 | iy += 1 |
---|
| 2422 | ix = 0 |
---|
| 2423 | ## add parameters name with checkbox for selecting to fit |
---|
| 2424 | cb = wx.CheckBox(self, -1, item ) |
---|
| 2425 | cb.SetValue(False) |
---|
[b9405cd] | 2426 | cb.SetToolTipString("Check for fitting") |
---|
[f20767b] | 2427 | wx.EVT_CHECKBOX(self, cb.GetId(), self.select_param) |
---|
| 2428 | if self.data.__class__.__name__ =="Data2D": |
---|
[6dc9ad8] | 2429 | cb.Show(True) |
---|
[f20767b] | 2430 | else: |
---|
[6dc9ad8] | 2431 | cb.Hide() |
---|
[f20767b] | 2432 | sizer.Add( cb,( iy, ix),(1,1), |
---|
| 2433 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 5) |
---|
| 2434 | |
---|
| 2435 | ## add parameter value |
---|
| 2436 | ix += 1 |
---|
| 2437 | value= self.model.getParam(item) |
---|
[7975f2b] | 2438 | ctl1 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH,20), |
---|
[f20767b] | 2439 | style=wx.TE_PROCESS_ENTER) |
---|
[1a94c36] | 2440 | ctl1.SetToolTipString("Hit 'Enter' after typing.") |
---|
[f20767b] | 2441 | ctl1.SetValue(format_number(value)) |
---|
| 2442 | if self.data.__class__.__name__ =="Data2D": |
---|
[c5cd3b9] | 2443 | ctl1.Show(True) |
---|
[f20767b] | 2444 | else: |
---|
[c5cd3b9] | 2445 | ctl1.Hide() |
---|
[f20767b] | 2446 | sizer.Add(ctl1, (iy,ix),(1,1), wx.EXPAND) |
---|
| 2447 | ## text to show error sign |
---|
| 2448 | ix += 1 |
---|
| 2449 | text2=wx.StaticText(self, -1, '+/-') |
---|
| 2450 | sizer.Add(text2,(iy, ix),(1,1),\ |
---|
| 2451 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 2452 | text2.Hide() |
---|
| 2453 | ix += 1 |
---|
[c13b8cc] | 2454 | ctl2 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=0) |
---|
[d7b7156] | 2455 | sizer.Add(ctl2, (iy,ix),(1,1), |
---|
| 2456 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[f20767b] | 2457 | ctl2.Hide() |
---|
[e2f7b92] | 2458 | |
---|
[c99a6c5] | 2459 | |
---|
[f20767b] | 2460 | ix += 1 |
---|
[d7b7156] | 2461 | ctl3 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/2,20), |
---|
| 2462 | style=wx.TE_PROCESS_ENTER, |
---|
| 2463 | text_enter_callback = self._onparamRangeEnter) |
---|
[b9405cd] | 2464 | |
---|
[d7b7156] | 2465 | sizer.Add(ctl3, (iy,ix),(1,1), |
---|
| 2466 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[f20767b] | 2467 | ctl3.Hide() |
---|
[b324aa9] | 2468 | |
---|
[f20767b] | 2469 | ix += 1 |
---|
[d7b7156] | 2470 | ctl4 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/2,20), |
---|
| 2471 | style=wx.TE_PROCESS_ENTER, |
---|
| 2472 | text_enter_callback = self._onparamRangeEnter) |
---|
| 2473 | sizer.Add(ctl4, (iy,ix),(1,1), |
---|
| 2474 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[eacf1d66] | 2475 | |
---|
[f20767b] | 2476 | ctl4.Hide() |
---|
[edd166b] | 2477 | |
---|
[d7b7156] | 2478 | if self.engine_type =="park" and \ |
---|
| 2479 | self.data.__class__.__name__ =="Data2D": |
---|
[f20767b] | 2480 | ctl3.Show(True) |
---|
| 2481 | ctl4.Show(True) |
---|
[c5cd3b9] | 2482 | |
---|
[f20767b] | 2483 | ix +=1 |
---|
| 2484 | # Units |
---|
[7975f2b] | 2485 | if self.model.details.has_key(item): |
---|
[d7b7156] | 2486 | units = wx.StaticText(self, -1, |
---|
| 2487 | self.model.details[item][0], |
---|
| 2488 | style=wx.ALIGN_LEFT) |
---|
[7975f2b] | 2489 | else: |
---|
[f20767b] | 2490 | units = wx.StaticText(self, -1, "", style=wx.ALIGN_LEFT) |
---|
| 2491 | if self.data.__class__.__name__ =="Data2D": |
---|
[6dc9ad8] | 2492 | units.Show(True) |
---|
[c99a6c5] | 2493 | |
---|
[f20767b] | 2494 | else: |
---|
[6dc9ad8] | 2495 | units.Hide() |
---|
[c99a6c5] | 2496 | |
---|
[d7b7156] | 2497 | sizer.Add(units, (iy,ix),(1,1), |
---|
| 2498 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[7975f2b] | 2499 | |
---|
[d7b7156] | 2500 | ##[cb state, name, value, "+/-", error of fit,min,max,units] |
---|
[f20767b] | 2501 | self.parameters.append([cb,item, ctl1, |
---|
| 2502 | text2,ctl2, ctl3, ctl4,units]) |
---|
| 2503 | self.orientation_params.append([cb,item, ctl1, |
---|
| 2504 | text2,ctl2, ctl3, ctl4,units]) |
---|
[780d095] | 2505 | |
---|
| 2506 | iy+=1 |
---|
[c77d859] | 2507 | |
---|
| 2508 | #Display units text on panel |
---|
| 2509 | for item in keys: |
---|
[7975f2b] | 2510 | if self.model.details.has_key(item): |
---|
[c77d859] | 2511 | self.text2_4.Show() |
---|
[b324aa9] | 2512 | #Fill the list of fittable parameters |
---|
| 2513 | self.select_all_param(event=None) |
---|
[7975f2b] | 2514 | |
---|
[52cac46] | 2515 | self.save_current_state_fit() |
---|
[240b9966] | 2516 | boxsizer1.Add(sizer) |
---|
[c77d859] | 2517 | self.sizer3.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10) |
---|
| 2518 | self.sizer3.Layout() |
---|
[330573d] | 2519 | self.Layout() |
---|
| 2520 | self.Refresh() |
---|
[015d109] | 2521 | self.SetupScrolling() |
---|
[5062bbf] | 2522 | |
---|
[52cac46] | 2523 | |
---|
[7609f1a] | 2524 | class BGTextCtrl(wx.TextCtrl): |
---|
| 2525 | """ |
---|
[5062bbf] | 2526 | Text control used to display outputs. |
---|
| 2527 | No editing allowed. The background is |
---|
| 2528 | grayed out. User can't select text. |
---|
[7609f1a] | 2529 | """ |
---|
| 2530 | def __init__(self, *args, **kwds): |
---|
| 2531 | wx.TextCtrl.__init__(self, *args, **kwds) |
---|
| 2532 | self.SetEditable(False) |
---|
| 2533 | self.SetBackgroundColour(self.GetParent().GetBackgroundColour()) |
---|
| 2534 | |
---|
| 2535 | # Bind to mouse event to avoid text highlighting |
---|
| 2536 | # The event will be skipped once the call-back |
---|
| 2537 | # is called. |
---|
| 2538 | self.Bind(wx.EVT_MOUSE_EVENTS, self._click) |
---|
| 2539 | |
---|
| 2540 | def _click(self, event): |
---|
| 2541 | """ |
---|
[5062bbf] | 2542 | Prevent further handling of the mouse event |
---|
| 2543 | by not calling Skip(). |
---|
[7609f1a] | 2544 | """ |
---|
| 2545 | pass |
---|
[5062bbf] | 2546 | |
---|
| 2547 | """ |
---|
| 2548 | Example: :: |
---|
[c77d859] | 2549 | |
---|
[5062bbf] | 2550 | class HelpWindow(wx.Frame): |
---|
| 2551 | def __init__(self, parent, id, title): |
---|
| 2552 | wx.Frame.__init__(self, parent, id, title, size=(570, 400)) |
---|
| 2553 | |
---|
| 2554 | from sans.models.CylinderModel import CylinderModel |
---|
| 2555 | model = CylinderModel() |
---|
| 2556 | |
---|
| 2557 | from danse.common.plottools.plottables import Data1D |
---|
| 2558 | data= Data1D(x=[1,2], y=[3,4], dy=[0.1, 0,1]) |
---|
[c77d859] | 2559 | |
---|
[5062bbf] | 2560 | from fitpanel import PageInfo |
---|
| 2561 | myinfo = PageInfo(self, model, data=data ) |
---|
| 2562 | |
---|
| 2563 | ## add data |
---|
| 2564 | |
---|
| 2565 | from models import ModelList |
---|
| 2566 | mylist= ModelList() |
---|
| 2567 | |
---|
| 2568 | from sans.models.SphereModel import SphereModel |
---|
| 2569 | from sans.models.SquareWellStructure import SquareWellStructure |
---|
| 2570 | from sans.models.DebyeModel import DebyeModel |
---|
| 2571 | from sans.models.LineModel import LineModel |
---|
| 2572 | name= "shapes" |
---|
| 2573 | list1= [SphereModel] |
---|
| 2574 | mylist.set_list( name, list1) |
---|
| 2575 | |
---|
| 2576 | name= "Shape-independent" |
---|
| 2577 | list1= [DebyeModel] |
---|
| 2578 | mylist.set_list( name, list1) |
---|
| 2579 | |
---|
| 2580 | name= "Structure Factors" |
---|
| 2581 | list1= [SquareWellStructure] |
---|
| 2582 | mylist.set_list( name, list1) |
---|
| 2583 | |
---|
| 2584 | name= "Added models" |
---|
| 2585 | list1= [LineModel] |
---|
| 2586 | mylist.set_list( name, list1) |
---|
| 2587 | |
---|
| 2588 | myinfo.model_list_box = mylist.get_list() |
---|
| 2589 | |
---|
| 2590 | self.page = FitPage(self, myinfo) |
---|
| 2591 | |
---|
| 2592 | self.Centre() |
---|
| 2593 | self.Show(True) |
---|
| 2594 | |
---|
| 2595 | if __name__=="__main__": |
---|
| 2596 | app = wx.App() |
---|
| 2597 | HelpWindow(None, -1, 'HelpWindow') |
---|
| 2598 | app.MainLoop() |
---|
| 2599 | """ |
---|
| 2600 | |
---|