[d1e0473] | 1 | |
---|
| 2 | |
---|
[c77d859] | 3 | import sys |
---|
| 4 | import wx |
---|
| 5 | import wx.lib.newevent |
---|
| 6 | import numpy |
---|
| 7 | import copy |
---|
| 8 | import math |
---|
| 9 | from sans.models.dispersion_models import ArrayDispersion, GaussianDispersion |
---|
| 10 | |
---|
| 11 | from sans.guicomm.events import StatusEvent |
---|
[69bee6d] | 12 | from sans.guiframe.utils import format_number,check_float |
---|
[77e23a2] | 13 | |
---|
[b787e68c] | 14 | ## event to post model to fit to fitting plugins |
---|
[c77d859] | 15 | (ModelEventbox, EVT_MODEL_BOX) = wx.lib.newevent.NewEvent() |
---|
[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() |
---|
[eda428b] | 20 | _BOX_WIDTH = 76 |
---|
[c77d859] | 21 | |
---|
| 22 | import basepage |
---|
| 23 | from basepage import BasicPage |
---|
[b787e68c] | 24 | from basepage import PageInfoEvent |
---|
[997131a] | 25 | from DataLoader.qsmearing import smear_selection |
---|
[c77d859] | 26 | |
---|
| 27 | class FitPage(BasicPage): |
---|
| 28 | """ |
---|
| 29 | FitPanel class contains fields allowing to display results when |
---|
| 30 | fitting a model and one data |
---|
| 31 | @note: For Fit to be performed the user should check at least one parameter |
---|
| 32 | on fit Panel window. |
---|
| 33 | |
---|
| 34 | """ |
---|
[cfc0913] | 35 | def __init__(self,parent, page_info): |
---|
| 36 | BasicPage.__init__(self, parent, page_info) |
---|
[c77d859] | 37 | """ |
---|
| 38 | Initialization of the Panel |
---|
| 39 | """ |
---|
| 40 | ## fit page does not content npts txtcrtl |
---|
| 41 | self.npts=None |
---|
[2b63df0] | 42 | ## thread for compute Chisqr |
---|
| 43 | self.calc_Chisqr=None |
---|
[dcf29d7] | 44 | ## default fitengine type |
---|
[707436d] | 45 | self.engine_type = None |
---|
[b787e68c] | 46 | ## draw sizer |
---|
[c77d859] | 47 | self._fill_datainfo_sizer() |
---|
[da26c1a] | 48 | |
---|
[c77d859] | 49 | self._fill_model_sizer( self.sizer1) |
---|
[cfc0913] | 50 | self._fill_range_sizer() |
---|
[fbf4bf8] | 51 | #self._on_select_model(event=None) |
---|
[997131a] | 52 | if self.data !=None: |
---|
| 53 | self.smearer = smear_selection( self.data ) |
---|
[847091f] | 54 | if self.smearer ==None: |
---|
| 55 | self.enable_smearer.Disable() |
---|
| 56 | self.disable_smearer.Disable() |
---|
[813334e] | 57 | |
---|
[cfc0913] | 58 | ## to update the panel according to the fit engine type selected |
---|
[77e23a2] | 59 | self.Bind(EVT_FITTER_TYPE,self._on_engine_change) |
---|
[34a0c17] | 60 | self.Bind(EVT_FIT_STOP,self._on_fit_complete) |
---|
[77e23a2] | 61 | |
---|
[34a0c17] | 62 | def _on_fit_complete(self, event): |
---|
| 63 | """ |
---|
| 64 | When fit is complete ,reset the fit button label. |
---|
| 65 | """ |
---|
| 66 | #self.btFit.SetLabel("Fit") |
---|
| 67 | #self.btFit.Unbind(event=wx.EVT_BUTTON, id=self.btFit.GetId()) |
---|
| 68 | #self.btFit.Bind(event=wx.EVT_BUTTON, handler=self._onFit,id=self.btFit.GetId()) |
---|
| 69 | pass |
---|
| 70 | |
---|
| 71 | |
---|
[77e23a2] | 72 | def _on_engine_change(self, event): |
---|
| 73 | """ |
---|
| 74 | get an event containing the current name of the fit engine type |
---|
| 75 | @param event: FitterTypeEvent containing the name of the current engine |
---|
| 76 | """ |
---|
[dcf29d7] | 77 | self.engine_type = event.type |
---|
| 78 | |
---|
[77e23a2] | 79 | if len(self.parameters)==0: |
---|
| 80 | return |
---|
[ad6dd4c] | 81 | if event.type =="park": |
---|
| 82 | self.btFit.SetLabel("Fit") |
---|
[77e23a2] | 83 | for item in self.parameters: |
---|
| 84 | if event.type =="scipy": |
---|
[60132ef] | 85 | item[5].SetValue("") |
---|
[77e23a2] | 86 | item[5].Hide() |
---|
[60132ef] | 87 | item[6].SetValue("") |
---|
[77e23a2] | 88 | item[6].Hide() |
---|
| 89 | self.text2_min.Hide() |
---|
| 90 | self.text2_max.Hide() |
---|
| 91 | else: |
---|
| 92 | item[5].Show(True) |
---|
| 93 | item[6].Show(True) |
---|
| 94 | self.text2_min.Show(True) |
---|
| 95 | self.text2_max.Show(True) |
---|
[3fef0a8] | 96 | for item in self.orientation_params: |
---|
| 97 | if event.type =="scipy": |
---|
| 98 | item[5].SetValue("") |
---|
| 99 | item[5].Hide() |
---|
| 100 | item[6].SetValue("") |
---|
| 101 | item[6].Hide() |
---|
| 102 | self.text2_min.Hide() |
---|
| 103 | self.text2_max.Hide() |
---|
| 104 | else: |
---|
| 105 | item[5].Show(True) |
---|
| 106 | item[6].Show(True) |
---|
| 107 | self.text2_min.Show(True) |
---|
| 108 | self.text2_max.Show(True) |
---|
| 109 | |
---|
| 110 | for item in self.orientation_params_disp: |
---|
| 111 | if event.type =="scipy": |
---|
| 112 | item[5].SetValue("") |
---|
| 113 | item[5].Hide() |
---|
| 114 | item[6].SetValue("") |
---|
| 115 | item[6].Hide() |
---|
| 116 | self.text2_min.Hide() |
---|
| 117 | self.text2_max.Hide() |
---|
| 118 | else: |
---|
| 119 | item[5].Show(True) |
---|
| 120 | item[6].Show(True) |
---|
| 121 | self.text2_min.Show(True) |
---|
| 122 | self.text2_max.Show(True) |
---|
[77e23a2] | 123 | |
---|
| 124 | self.sizer3.Layout() |
---|
| 125 | self.SetScrollbars(20,20,200,100) |
---|
[c77d859] | 126 | |
---|
| 127 | |
---|
| 128 | def _fill_range_sizer(self): |
---|
| 129 | """ |
---|
| 130 | Fill the sizer containing the plotting range |
---|
| 131 | add access to npts |
---|
| 132 | """ |
---|
[1ae3fe1] | 133 | sizer_fit = wx.GridSizer(1, 1,0, 0) |
---|
[c77d859] | 134 | |
---|
| 135 | self.btFit = wx.Button(self,wx.NewId(),'Fit') |
---|
| 136 | self.btFit.Bind(wx.EVT_BUTTON, self._onFit,id= self.btFit.GetId()) |
---|
| 137 | self.btFit.SetToolTipString("Perform fit.") |
---|
[2d5f7a1] | 138 | |
---|
[c77d859] | 139 | |
---|
| 140 | sizer_fit.Add((5,5),1, wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 5) |
---|
[1ae3fe1] | 141 | sizer_fit.Add(self.btFit,0, wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 5) |
---|
[c77d859] | 142 | |
---|
| 143 | sizer_smearer = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 144 | #Filling the sizer containing instruments smearing info. |
---|
| 145 | self.disable_smearer = wx.RadioButton(self, -1, 'No', style=wx.RB_GROUP) |
---|
| 146 | self.enable_smearer = wx.RadioButton(self, -1, 'Yes') |
---|
| 147 | self.Bind(wx.EVT_RADIOBUTTON, self.onSmear, id=self.disable_smearer.GetId()) |
---|
| 148 | self.Bind(wx.EVT_RADIOBUTTON, self.onSmear, id=self.enable_smearer.GetId()) |
---|
| 149 | |
---|
| 150 | sizer_smearer.Add(wx.StaticText(self,-1,'Instrument Smearing? ')) |
---|
| 151 | sizer_smearer.Add((10, 10)) |
---|
| 152 | sizer_smearer.Add( self.enable_smearer ) |
---|
| 153 | sizer_smearer.Add((10,10)) |
---|
| 154 | sizer_smearer.Add( self.disable_smearer ) |
---|
| 155 | |
---|
[7b0fd65] | 156 | #Display Chi^2/dof |
---|
[d1e0473] | 157 | sizer_smearer.Add((68,10)) |
---|
[7b0fd65] | 158 | box_description= wx.StaticBox(self, -1,'Chi2/dof') |
---|
| 159 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
[2a5bba7] | 160 | boxsizer1.SetMinSize((60,-1)) |
---|
[2b63df0] | 161 | temp_smearer = None |
---|
| 162 | if self.enable_smearer.GetValue(): |
---|
| 163 | temp_smearer= self.smearer |
---|
| 164 | |
---|
| 165 | self.tcChi = wx.StaticText(self, -1, "-", style=wx.ALIGN_LEFT) |
---|
| 166 | |
---|
[7b0fd65] | 167 | boxsizer1.Add( self.tcChi ) |
---|
| 168 | sizer_smearer.Add( boxsizer1 ) |
---|
| 169 | |
---|
| 170 | #Set sizer for Fitting section |
---|
[330573d] | 171 | self._set_range_sizer( title="Fitting",object1=sizer_smearer, object= sizer_fit) |
---|
[7b0fd65] | 172 | |
---|
[c77d859] | 173 | |
---|
| 174 | def _fill_datainfo_sizer(self): |
---|
| 175 | """ |
---|
| 176 | fill sizer 0 with data info |
---|
| 177 | """ |
---|
| 178 | self.sizer0.Clear(True) |
---|
| 179 | ## no loaded data , don't fill the sizer |
---|
| 180 | if self.data== None: |
---|
| 181 | self.sizer0.Layout() |
---|
| 182 | return |
---|
| 183 | |
---|
[fa58441] | 184 | box_description= wx.StaticBox(self, -1, 'Data') |
---|
[c77d859] | 185 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
| 186 | #---------------------------------------------------------- |
---|
| 187 | sizer_data = wx.GridSizer(3, 3,5, 5) |
---|
| 188 | #Filling the sizer containing data related fields |
---|
| 189 | DataSource =wx.StaticText(self, -1,str(self.data.name)) |
---|
| 190 | |
---|
[fa58441] | 191 | sizer_data.Add(wx.StaticText(self, -1, 'Source Name : ')) |
---|
[c77d859] | 192 | sizer_data.Add(DataSource ) |
---|
[2a5bba7] | 193 | sizer_data.Add( (0,5) ) |
---|
[c77d859] | 194 | |
---|
| 195 | #---------sizer 2 draw-------------------------------- |
---|
| 196 | #set maximum range for x in linear scale |
---|
| 197 | if not hasattr(self.data,"data"): #Display only for 1D data fit |
---|
| 198 | # Minimum value of data |
---|
[813334e] | 199 | data_min = min(self.data.x) |
---|
[c77d859] | 200 | # Maximum value of data |
---|
[813334e] | 201 | data_max = max(self.data.x) |
---|
[7b0fd65] | 202 | text4_3 = wx.StaticText(self, -1, 'Total Q Range (1/A)', |
---|
[c77d859] | 203 | style=wx.ALIGN_LEFT) |
---|
| 204 | sizer_data.Add( text4_3 ) |
---|
[813334e] | 205 | sizer_data.Add(wx.StaticText(self, -1, "Min : %s"%str(data_min))) |
---|
| 206 | sizer_data.Add(wx.StaticText(self, -1, "Max : %s"%str(data_max))) |
---|
[c77d859] | 207 | |
---|
| 208 | else: |
---|
[813334e] | 209 | ## Minimum value of data |
---|
| 210 | data_min= 0 |
---|
| 211 | x= max(math.fabs(self.data.xmin), math.fabs(self.data.xmax)) |
---|
| 212 | y= max(math.fabs(self.data.ymin), math.fabs(self.data.ymax)) |
---|
| 213 | ## Maximum value of data |
---|
| 214 | data_max = math.sqrt(x*x + y*y) |
---|
| 215 | |
---|
[d2d0cfdf] | 216 | #For qmin and qmax, do not use format_number |
---|
| 217 | #.(If do, qmin and max could be different from what is in the data.) |
---|
[d1e0473] | 218 | text4_3 = wx.StaticText(self, -1, "Total Q Range (1/A)", |
---|
[c77d859] | 219 | style=wx.ALIGN_LEFT) |
---|
| 220 | sizer_data.Add( text4_3 ) |
---|
[813334e] | 221 | sizer_data.Add(wx.StaticText(self, -1, "Min : %s"%str(data_min))) |
---|
| 222 | sizer_data.Add(wx.StaticText(self, -1, "Max : %s"%str(data_max))) |
---|
| 223 | ## set q range to plot |
---|
| 224 | self.qmin_x= data_min |
---|
| 225 | self.qmax_x= data_max |
---|
| 226 | |
---|
[c77d859] | 227 | boxsizer1.Add(sizer_data) |
---|
| 228 | #------------------------------------------------------------ |
---|
| 229 | self.sizer0.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10) |
---|
| 230 | self.sizer0.Layout() |
---|
[813334e] | 231 | |
---|
[c77d859] | 232 | |
---|
[7b0fd65] | 233 | |
---|
[c77d859] | 234 | def _fill_model_sizer(self, sizer): |
---|
| 235 | """ |
---|
| 236 | fill sizer containing model info |
---|
| 237 | """ |
---|
[87fbc60] | 238 | |
---|
[c77d859] | 239 | ## class base method to add view 2d button |
---|
[7b0fd65] | 240 | self._set_model_sizer(sizer=sizer, title="Model",object=None ) |
---|
| 241 | |
---|
[c77d859] | 242 | |
---|
| 243 | def _set_sizer_gaussian(self): |
---|
| 244 | """ |
---|
| 245 | draw sizer with gaussian dispersity parameters |
---|
| 246 | """ |
---|
| 247 | self.fittable_param=[] |
---|
| 248 | self.fixed_param=[] |
---|
[60132ef] | 249 | self.orientation_params_disp=[] |
---|
| 250 | |
---|
[c77d859] | 251 | self.sizer4_4.Clear(True) |
---|
| 252 | |
---|
| 253 | if self.model==None: |
---|
| 254 | ##no model is selected |
---|
| 255 | return |
---|
| 256 | if not self.enable_disp.GetValue(): |
---|
| 257 | ## the user didn't select dispersity display |
---|
| 258 | return |
---|
[376916c] | 259 | |
---|
| 260 | self._reset_dispersity() |
---|
| 261 | # Create the dispersion objects |
---|
| 262 | for item in self.model.dispersion.keys(): |
---|
| 263 | disp_model = GaussianDispersion() |
---|
| 264 | self._disp_obj_dict[item] = disp_model |
---|
| 265 | self.model.set_dispersion(item, disp_model) |
---|
[c477b31] | 266 | self.state._disp_obj_dict[item]= disp_model |
---|
[376916c] | 267 | |
---|
[c77d859] | 268 | ix=0 |
---|
| 269 | iy=1 |
---|
| 270 | disp = wx.StaticText(self, -1, 'Names') |
---|
| 271 | self.sizer4_4.Add(disp,( iy, ix),(1,1), |
---|
| 272 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 273 | ix += 1 |
---|
| 274 | values = wx.StaticText(self, -1, 'Values') |
---|
| 275 | self.sizer4_4.Add(values,( iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 276 | ix +=2 |
---|
| 277 | self.text_disp_1 = wx.StaticText(self, -1, 'Errors') |
---|
| 278 | self.sizer4_4.Add( self.text_disp_1,(iy, ix),(1,1),\ |
---|
| 279 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 280 | self.text_disp_1.Hide() |
---|
| 281 | ix += 1 |
---|
| 282 | npts = wx.StaticText(self, -1, 'Npts') |
---|
| 283 | self.sizer4_4.Add(npts,( iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 284 | ix += 1 |
---|
| 285 | nsigmas = wx.StaticText(self, -1, 'Nsigmas') |
---|
| 286 | self.sizer4_4.Add(nsigmas,( iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[6dc9ad8] | 287 | |
---|
[c77d859] | 288 | for item in self.model.dispersion.keys(): |
---|
[780d095] | 289 | if not item in self.model.orientation_params: |
---|
| 290 | self.disp_cb_dict[item]= None |
---|
| 291 | name1=item+".width" |
---|
| 292 | name2=item+".npts" |
---|
| 293 | name3=item+".nsigmas" |
---|
| 294 | iy += 1 |
---|
| 295 | for p in self.model.dispersion[item].keys(): |
---|
| 296 | |
---|
| 297 | if p=="width": |
---|
| 298 | ix = 0 |
---|
| 299 | cb = wx.CheckBox(self, -1, name1, (10, 10)) |
---|
| 300 | wx.EVT_CHECKBOX(self, cb.GetId(), self.select_param) |
---|
| 301 | self.sizer4_4.Add( cb,( iy, ix),(1,1), |
---|
| 302 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 303 | ix = 1 |
---|
| 304 | value= self.model.getParam(name1) |
---|
[6f2c919] | 305 | ctl1 = BasicPage.ModelTextCtrl(self, -1, size=(_BOX_WIDTH,20), |
---|
[c77d859] | 306 | style=wx.TE_PROCESS_ENTER) |
---|
[780d095] | 307 | ctl1.SetValue(str (format_number(value))) |
---|
| 308 | self.sizer4_4.Add(ctl1, (iy,ix),(1,1),wx.EXPAND) |
---|
| 309 | ## text to show error sign |
---|
| 310 | ix = 2 |
---|
| 311 | text2=wx.StaticText(self, -1, '+/-') |
---|
| 312 | self.sizer4_4.Add(text2,(iy, ix),(1,1), |
---|
| 313 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 314 | text2.Hide() |
---|
| 315 | ## txtcrtl to add error from fit |
---|
| 316 | ix = 3 |
---|
| 317 | ctl2 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=wx.TE_PROCESS_ENTER) |
---|
| 318 | self.sizer4_4.Add(ctl2, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 319 | ctl2.Hide() |
---|
| 320 | self.fittable_param.append([cb,name1,ctl1,text2, |
---|
| 321 | ctl2, None, None,None]) |
---|
| 322 | elif p=="npts": |
---|
| 323 | ix = 4 |
---|
| 324 | value= self.model.getParam(name2) |
---|
[6f2c919] | 325 | Tctl = BasicPage.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/2,20), |
---|
[780d095] | 326 | style=wx.TE_PROCESS_ENTER) |
---|
| 327 | |
---|
| 328 | Tctl.SetValue(str (format_number(value))) |
---|
| 329 | self.sizer4_4.Add(Tctl, (iy,ix),(1,1), |
---|
| 330 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 331 | self.fixed_param.append([None,name2, Tctl,None,None, |
---|
| 332 | None, None,None]) |
---|
| 333 | elif p=="nsigmas": |
---|
| 334 | ix = 5 |
---|
| 335 | value= self.model.getParam(name3) |
---|
[6f2c919] | 336 | Tctl = BasicPage.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/2,20), |
---|
[780d095] | 337 | style=wx.TE_PROCESS_ENTER) |
---|
| 338 | Tctl.SetValue(str (format_number(value))) |
---|
| 339 | self.sizer4_4.Add(Tctl, (iy,ix),(1,1), |
---|
| 340 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 341 | ix +=1 |
---|
| 342 | self.sizer4_4.Add((20,20), (iy,ix),(1,1), |
---|
| 343 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 344 | |
---|
| 345 | self.fixed_param.append([None,name3, Tctl |
---|
| 346 | ,None,None, None, None,None]) |
---|
| 347 | ix =0 |
---|
| 348 | iy +=1 |
---|
| 349 | self.sizer4_4.Add((20,20),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 350 | for item in self.model.dispersion.keys(): |
---|
| 351 | if item in self.model.orientation_params: |
---|
| 352 | self.disp_cb_dict[item]= None |
---|
| 353 | name1=item+".width" |
---|
| 354 | name2=item+".npts" |
---|
| 355 | name3=item+".nsigmas" |
---|
| 356 | iy += 1 |
---|
| 357 | for p in self.model.dispersion[item].keys(): |
---|
| 358 | |
---|
| 359 | if p=="width": |
---|
| 360 | ix = 0 |
---|
| 361 | cb = wx.CheckBox(self, -1, name1, (10, 10)) |
---|
| 362 | wx.EVT_CHECKBOX(self, cb.GetId(), self.select_param) |
---|
| 363 | self.sizer4_4.Add( cb,( iy, ix),(1,1), |
---|
| 364 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 365 | if self.data.__class__.__name__ =="Data2D": |
---|
[6dc9ad8] | 366 | cb.Show(True) |
---|
[780d095] | 367 | cb.Enable() |
---|
| 368 | else: |
---|
[6dc9ad8] | 369 | cb.Hide() |
---|
[780d095] | 370 | cb.Disable() |
---|
| 371 | ix = 1 |
---|
| 372 | value= self.model.getParam(name1) |
---|
[6f2c919] | 373 | ctl1 = BasicPage.ModelTextCtrl(self, -1, size=(_BOX_WIDTH,20), |
---|
[c77d859] | 374 | style=wx.TE_PROCESS_ENTER) |
---|
[780d095] | 375 | ctl1.SetValue(str (format_number(value))) |
---|
| 376 | if self.data.__class__.__name__ =="Data2D": |
---|
[6dc9ad8] | 377 | ctl1.Show(True) |
---|
[780d095] | 378 | ctl1.Enable() |
---|
| 379 | else: |
---|
[6dc9ad8] | 380 | ctl1.Hide() |
---|
[780d095] | 381 | ctl1.Disable() |
---|
| 382 | self.sizer4_4.Add(ctl1, (iy,ix),(1,1),wx.EXPAND) |
---|
| 383 | ## text to show error sign |
---|
| 384 | ix = 2 |
---|
| 385 | text2=wx.StaticText(self, -1, '+/-') |
---|
| 386 | self.sizer4_4.Add(text2,(iy, ix),(1,1), |
---|
| 387 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 388 | text2.Hide() |
---|
| 389 | ## txtcrtl to add error from fit |
---|
| 390 | ix = 3 |
---|
| 391 | ctl2 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=wx.TE_PROCESS_ENTER) |
---|
| 392 | self.sizer4_4.Add(ctl2, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 393 | ctl2.Hide() |
---|
| 394 | if self.data.__class__.__name__ =="Data2D": |
---|
[6dc9ad8] | 395 | #ctl2.Show(True) |
---|
[780d095] | 396 | ctl2.Enable() |
---|
| 397 | else: |
---|
[6dc9ad8] | 398 | #ctl2.Hide() |
---|
[780d095] | 399 | ctl2.Disable() |
---|
| 400 | self.fittable_param.append([cb,name1,ctl1,text2, |
---|
| 401 | ctl2, None, None,None]) |
---|
[60132ef] | 402 | self.orientation_params_disp.append([cb,name1,ctl1,text2, |
---|
[780d095] | 403 | ctl2, None, None,None]) |
---|
| 404 | elif p=="npts": |
---|
| 405 | ix = 4 |
---|
| 406 | value= self.model.getParam(name2) |
---|
[6f2c919] | 407 | Tctl = BasicPage.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/2,20), |
---|
[780d095] | 408 | style=wx.TE_PROCESS_ENTER) |
---|
| 409 | |
---|
| 410 | Tctl.SetValue(str (format_number(value))) |
---|
| 411 | if self.data.__class__.__name__ =="Data2D": |
---|
[6dc9ad8] | 412 | Tctl.Show(True) |
---|
[780d095] | 413 | Tctl.Enable() |
---|
| 414 | else: |
---|
[6dc9ad8] | 415 | Tctl.Hide() |
---|
[780d095] | 416 | Tctl.Disable() |
---|
| 417 | self.sizer4_4.Add(Tctl, (iy,ix),(1,1), |
---|
| 418 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 419 | self.fixed_param.append([None,name2, Tctl,None,None, |
---|
| 420 | None, None,None]) |
---|
[60132ef] | 421 | self.orientation_params_disp.append([None,name2, Tctl,None,None, |
---|
[780d095] | 422 | None, None,None]) |
---|
| 423 | elif p=="nsigmas": |
---|
| 424 | ix = 5 |
---|
| 425 | value= self.model.getParam(name3) |
---|
[6f2c919] | 426 | Tctl = BasicPage.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/2,20), |
---|
[780d095] | 427 | style=wx.TE_PROCESS_ENTER) |
---|
| 428 | Tctl.SetValue(str (format_number(value))) |
---|
| 429 | if self.data.__class__.__name__ =="Data2D": |
---|
[6dc9ad8] | 430 | Tctl.Show(True) |
---|
[780d095] | 431 | Tctl.Enable() |
---|
| 432 | else: |
---|
[6dc9ad8] | 433 | Tctl.Hide() |
---|
[780d095] | 434 | Tctl.Disable() |
---|
| 435 | self.sizer4_4.Add(Tctl, (iy,ix),(1,1), |
---|
| 436 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 437 | ix +=1 |
---|
| 438 | self.sizer4_4.Add((20,20), (iy,ix),(1,1), |
---|
| 439 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 440 | self.fixed_param.append([None,name3, Tctl |
---|
| 441 | ,None,None, None, None,None]) |
---|
[60132ef] | 442 | self.orientation_params_disp.append([None,name3, Tctl |
---|
[1c1436d] | 443 | ,None,None, None, None,None]) |
---|
[d2d0cfdf] | 444 | |
---|
[71f0373] | 445 | self.state.disp_cb_dict = copy.deepcopy(self.disp_cb_dict) |
---|
| 446 | self.state.model = self.model.clone() |
---|
[240b9966] | 447 | ## save state into |
---|
| 448 | self._copy_parameters_state(self.orientation_params_disp, |
---|
| 449 | self.state.orientation_params_disp) |
---|
| 450 | self._copy_parameters_state(self.fittable_param, self.state.fittable_param) |
---|
| 451 | self._copy_parameters_state(self.fixed_param, self.state.fixed_param) |
---|
[71f0373] | 452 | |
---|
[c77d859] | 453 | wx.PostEvent(self.parent, StatusEvent(status=\ |
---|
| 454 | " Selected Distribution: Gaussian")) |
---|
| 455 | ix =0 |
---|
| 456 | iy +=1 |
---|
| 457 | self.sizer4_4.Add((20,20),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 458 | self.sizer4_4.Layout() |
---|
| 459 | self.sizer4.Layout() |
---|
[71f0373] | 460 | self.Layout() |
---|
[c77d859] | 461 | self.SetScrollbars(20,20,200,100) |
---|
[71f0373] | 462 | self.Refresh() |
---|
[0a518e4c] | 463 | |
---|
[c77d859] | 464 | |
---|
| 465 | def _onFit(self, event): |
---|
| 466 | """ |
---|
| 467 | Allow to fit |
---|
| 468 | """ |
---|
| 469 | from sans.guiframe.utils import check_value |
---|
| 470 | flag = check_value( self.qmin, self.qmax) |
---|
| 471 | |
---|
| 472 | if not flag: |
---|
| 473 | msg= "Fitting range invalid" |
---|
| 474 | wx.PostEvent(self.parent.parent, StatusEvent(status= msg )) |
---|
| 475 | return |
---|
| 476 | |
---|
| 477 | if len(self.param_toFit) <= 0: |
---|
| 478 | msg= "Select at least one parameter to fit" |
---|
| 479 | wx.PostEvent(self.parent.parent, StatusEvent(status= msg )) |
---|
| 480 | return |
---|
[d0ce2c30] | 481 | |
---|
| 482 | # Remove or do not allow fitting on the Q=0 point, especially when y(q=0)=None at x[0]. |
---|
[ad6dd4c] | 483 | #ToDo: Fix this. |
---|
[1c1436d] | 484 | self.qmin_x = float(self.qmin.GetValue()) |
---|
[c77d859] | 485 | self.qmax_x =float( self.qmax.GetValue()) |
---|
[6f023e8] | 486 | self.manager._reset_schedule_problem( value=0) |
---|
[ca7a626] | 487 | self.manager.schedule_for_fit( value=1,page=self,fitproblem =None) |
---|
| 488 | self.manager.set_fit_range(page= self,qmin= self.qmin_x, qmax= self.qmax_x) |
---|
[ad6dd4c] | 489 | |
---|
[c77d859] | 490 | #single fit |
---|
[ca7a626] | 491 | self.manager.onFit() |
---|
[ad6dd4c] | 492 | ## allow stopping the fit |
---|
[34a0c17] | 493 | #if self.engine_type=="scipy": |
---|
| 494 | # self.btFit.SetLabel("Stop") |
---|
| 495 | # self.btFit.Unbind(event=wx.EVT_BUTTON, id= self.btFit.GetId()) |
---|
| 496 | # self.btFit.Bind(event= wx.EVT_BUTTON, handler=self._StopFit, id=self.btFit.GetId()) |
---|
| 497 | #else: |
---|
| 498 | # self.btFit.SetLabel("Fit") |
---|
| 499 | # self.btFit.Bind(event= wx.EVT_BUTTON, handler=self._onFit, id=self.btFit.GetId()) |
---|
[1c1436d] | 500 | self.btFit.SetFocus() |
---|
[c77d859] | 501 | self.sizer5.Layout() |
---|
| 502 | self.SetScrollbars(20,20,55,40) |
---|
| 503 | |
---|
[ad6dd4c] | 504 | def _StopFit(self, event): |
---|
| 505 | """ |
---|
| 506 | Stop fit |
---|
| 507 | """ |
---|
| 508 | self.btFit.SetLabel("Fit") |
---|
| 509 | if self.engine_type=="scipy": |
---|
| 510 | self.manager.stop_fit() |
---|
[34a0c17] | 511 | self.btFit.Unbind(event=wx.EVT_BUTTON, id=self.btFit.GetId()) |
---|
| 512 | self.btFit.Bind(event=wx.EVT_BUTTON, handler=self._onFit,id=self.btFit.GetId()) |
---|
| 513 | |
---|
| 514 | |
---|
[ad6dd4c] | 515 | self.btFit.SetFocus() |
---|
| 516 | self.sizer5.Layout() |
---|
| 517 | self.SetScrollbars(20,20,55,40) |
---|
| 518 | |
---|
[c77d859] | 519 | def _on_select_model(self, event): |
---|
| 520 | """ |
---|
| 521 | call back for model selection |
---|
| 522 | """ |
---|
[59a7f2d] | 523 | self._on_select_model_helper() |
---|
[70c57ebf] | 524 | self.set_model_param_sizer(self.model) |
---|
| 525 | |
---|
[3b605bb] | 526 | self.enable_disp.SetValue(False) |
---|
| 527 | self.disable_disp.SetValue(True) |
---|
[1c1436d] | 528 | self.set_dispers_sizer() |
---|
[70c57ebf] | 529 | if self.model !=None: |
---|
| 530 | try: |
---|
| 531 | temp_smear= None |
---|
| 532 | if self.enable_smearer.GetValue(): |
---|
| 533 | temp_smear= self.smearer |
---|
| 534 | self.compute_chisqr(temp_smear) |
---|
| 535 | except: |
---|
| 536 | ## error occured on chisqr computation |
---|
| 537 | pass |
---|
| 538 | evt = ModelEventbox(model=self.model) |
---|
| 539 | wx.PostEvent(self.event_owner, evt) |
---|
[848a2ef] | 540 | self.btFit.SetFocus() |
---|
[240b9966] | 541 | self.state.enable_disp = self.enable_disp.GetValue() |
---|
| 542 | self.state.disable_disp = self.disable_disp.GetValue() |
---|
[3b9e023] | 543 | |
---|
| 544 | self.state.structurecombobox = self.structurebox.GetCurrentSelection() |
---|
| 545 | self.state.formfactorcombobox = self.formfactorbox.GetCurrentSelection() |
---|
[077809c] | 546 | |
---|
[3b9e023] | 547 | |
---|
[3595309d] | 548 | if event !=None: |
---|
| 549 | self._undo.Enable(True) |
---|
| 550 | ## post state to fit panel |
---|
| 551 | event = PageInfoEvent(page = self) |
---|
| 552 | wx.PostEvent(self.parent, event) |
---|
[330573d] | 553 | |
---|
[298b762] | 554 | |
---|
| 555 | def _onparamRangeEnter(self, event): |
---|
| 556 | """ |
---|
| 557 | Check validity of value enter in the parameters range field |
---|
| 558 | """ |
---|
| 559 | tcrtl= event.GetEventObject() |
---|
| 560 | if tcrtl.GetValue().lstrip().rstrip()!="": |
---|
| 561 | try: |
---|
| 562 | value = float(tcrtl.GetValue()) |
---|
| 563 | tcrtl.SetBackgroundColour(wx.WHITE) |
---|
| 564 | tcrtl.Refresh() |
---|
| 565 | except: |
---|
| 566 | tcrtl.SetBackgroundColour("pink") |
---|
| 567 | tcrtl.Refresh() |
---|
[0aeabc6] | 568 | return |
---|
[298b762] | 569 | else: |
---|
| 570 | tcrtl.SetBackgroundColour(wx.WHITE) |
---|
| 571 | tcrtl.Refresh() |
---|
[0aeabc6] | 572 | self._onparamEnter_helper() |
---|
| 573 | |
---|
| 574 | ##compute chisqr for range change |
---|
| 575 | temp_smearer = None |
---|
| 576 | if self.enable_smearer.GetValue(): |
---|
| 577 | msg="" |
---|
| 578 | temp_smearer= self.smearer |
---|
| 579 | ##Calculate chi2 |
---|
[077809c] | 580 | |
---|
[0aeabc6] | 581 | self.compute_chisqr(smearer= temp_smearer) |
---|
[240b9966] | 582 | ## new state posted |
---|
| 583 | if self.state_change: |
---|
[3595309d] | 584 | self._undo.Enable(True) |
---|
[240b9966] | 585 | event = PageInfoEvent(page = self) |
---|
| 586 | wx.PostEvent(self.parent, event) |
---|
| 587 | self.state_change= False |
---|
[0aeabc6] | 588 | |
---|
[298b762] | 589 | |
---|
[dd5949d] | 590 | def _onparamEnter(self,event): |
---|
| 591 | """ |
---|
| 592 | when enter value on panel redraw model according to changed |
---|
| 593 | """ |
---|
[69bee6d] | 594 | tcrtl= event.GetEventObject() |
---|
[240b9966] | 595 | |
---|
[69bee6d] | 596 | if check_float(tcrtl): |
---|
| 597 | self._onparamEnter_helper() |
---|
[da26c1a] | 598 | temp_smearer = None |
---|
| 599 | if self.enable_smearer.GetValue(): |
---|
| 600 | temp_smearer= self.smearer |
---|
[077809c] | 601 | |
---|
[da26c1a] | 602 | self.compute_chisqr(smearer= temp_smearer) |
---|
[240b9966] | 603 | ## new state posted |
---|
| 604 | if self.state_change: |
---|
[3595309d] | 605 | self._undo.Enable(True) |
---|
| 606 | event = PageInfoEvent(page = self) |
---|
| 607 | wx.PostEvent(self.parent, event) |
---|
| 608 | self.state_change= False |
---|
[69bee6d] | 609 | else: |
---|
| 610 | msg= "Cannot Plot :Must enter a number!!! " |
---|
| 611 | wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) |
---|
| 612 | return |
---|
[cfc0913] | 613 | |
---|
[882a912] | 614 | |
---|
| 615 | def set_data(self, data ): |
---|
| 616 | """ |
---|
| 617 | reset the current data |
---|
| 618 | """ |
---|
| 619 | if data ==None: |
---|
| 620 | return |
---|
| 621 | self.data =data |
---|
| 622 | self.state.data= data |
---|
| 623 | self._fill_datainfo_sizer() |
---|
| 624 | self.SetScrollbars(20,20,200,100) |
---|
| 625 | self.Layout() |
---|
| 626 | |
---|
[240b9966] | 627 | def reset_page(self, state,first=False): |
---|
[a074145] | 628 | """ |
---|
| 629 | reset the state |
---|
| 630 | """ |
---|
[240b9966] | 631 | if first: |
---|
| 632 | self._undo.Enable(False) |
---|
| 633 | |
---|
[a074145] | 634 | self.reset_page_helper(state) |
---|
[f20767b] | 635 | evt = ModelEventbox(model=state.model) |
---|
[a074145] | 636 | wx.PostEvent(self.event_owner, evt) |
---|
| 637 | |
---|
| 638 | |
---|
[2140e68] | 639 | def get_range(self): |
---|
| 640 | """ |
---|
| 641 | return the fitting range |
---|
| 642 | """ |
---|
[c9a4377] | 643 | return float(self.qmin_x) , float(self.qmax_x) |
---|
[c77d859] | 644 | |
---|
| 645 | def get_param_list(self): |
---|
| 646 | """ |
---|
| 647 | @return self.param_toFit: list containing references to TextCtrl |
---|
| 648 | checked.Theses TextCtrl will allow reference to parameters to fit. |
---|
| 649 | @raise: if return an empty list of parameter fit will nnote work |
---|
| 650 | properly so raise ValueError,"missing parameter to fit" |
---|
| 651 | """ |
---|
| 652 | if self.param_toFit !=[]: |
---|
| 653 | return self.param_toFit |
---|
| 654 | else: |
---|
| 655 | raise ValueError,"missing parameter to fit" |
---|
| 656 | |
---|
| 657 | def onsetValues(self,chisqr, out,cov): |
---|
| 658 | """ |
---|
| 659 | Build the panel from the fit result |
---|
| 660 | @param chisqr:Value of the goodness of fit metric |
---|
| 661 | @param out:list of parameter with the best value found during fitting |
---|
| 662 | @param cov:Covariance matrix |
---|
| 663 | |
---|
| 664 | """ |
---|
| 665 | self.tcChi.SetLabel(format_number(chisqr)) |
---|
| 666 | params = {} |
---|
| 667 | is_modified = False |
---|
| 668 | has_error = False |
---|
[0a518e4c] | 669 | self.text2_3.Hide() |
---|
[e473e4f5] | 670 | try: |
---|
| 671 | n = self.disp_box.GetCurrentSelection() |
---|
| 672 | dispersity= self.disp_box.GetClientData(n) |
---|
| 673 | name= dispersity.__name__ |
---|
| 674 | if name == "GaussianDispersion": |
---|
| 675 | if hasattr(self,"text_disp_1" ): |
---|
| 676 | if self.text_disp_1 !=None: |
---|
| 677 | self.text_disp_1.Hide() |
---|
| 678 | except: |
---|
| 679 | pass |
---|
[c77d859] | 680 | #set the panel when fit result are float not list |
---|
| 681 | if out.__class__==numpy.float64: |
---|
| 682 | self.param_toFit[0][2].SetValue(format_number(out)) |
---|
| 683 | self.param_toFit[0][2].Refresh() |
---|
[0a518e4c] | 684 | |
---|
| 685 | self.param_toFit[0][4].Clear() |
---|
| 686 | self.param_toFit[0][4].Hide() |
---|
[c77d859] | 687 | if cov !=None : |
---|
| 688 | self.text2_3.Show(True) |
---|
[e473e4f5] | 689 | try: |
---|
| 690 | name= dispersity.__name__ |
---|
| 691 | if name == "GaussianDispersion": |
---|
| 692 | if hasattr(self,"text_disp_1" ): |
---|
| 693 | if self.text_disp_1 !=None: |
---|
| 694 | self.text_disp_1.Show(True) |
---|
| 695 | except: |
---|
| 696 | pass |
---|
[ad6dd4c] | 697 | if cov[0]==None or not numpy.isfinite(cov[0]): |
---|
[69bee6d] | 698 | self.param_toFit[0][3].Hide() |
---|
| 699 | self.param_toFit[0][4].Clear() |
---|
| 700 | self.param_toFit[0][4].Hide() |
---|
| 701 | self.param_toFit[0][4].Refresh() |
---|
| 702 | else: |
---|
| 703 | self.param_toFit[0][3].Show(True) |
---|
| 704 | self.param_toFit[0][4].Clear() |
---|
| 705 | self.param_toFit[0][4].SetValue(format_number(cov[0])) |
---|
| 706 | self.param_toFit[0][4].Show(True) |
---|
| 707 | self.param_toFit[0][4].Refresh() |
---|
[c77d859] | 708 | else: |
---|
| 709 | i=0 |
---|
| 710 | j=0 |
---|
| 711 | #Set the panel when fit result are list |
---|
| 712 | for item in self.param_toFit: |
---|
[0a518e4c] | 713 | ## reset error value to initial state |
---|
| 714 | item[4].Clear() |
---|
| 715 | item[4].Hide() |
---|
| 716 | item[4].Refresh() |
---|
[c77d859] | 717 | if( out != None ) and len(out)<=len(self.param_toFit)and i < len(out): |
---|
| 718 | item[2].SetValue(format_number(self.model.getParam(item[1]))) |
---|
| 719 | item[2].Refresh() |
---|
| 720 | if(cov !=None)and len(cov)<=len(self.param_toFit)and i < len(cov): |
---|
| 721 | self.text2_3.Show(True) |
---|
[e473e4f5] | 722 | try: |
---|
| 723 | name= dispersity.__name__ |
---|
| 724 | if name == "GaussianDispersion": |
---|
| 725 | if hasattr(self,"text_disp_1" ): |
---|
| 726 | if self.text_disp_1!=None: |
---|
| 727 | self.text_disp_1.Show(True) |
---|
| 728 | except: |
---|
| 729 | pass |
---|
[c77d859] | 730 | item[3].Show(True) |
---|
| 731 | item[4].Clear() |
---|
| 732 | for j in range(len(out)): |
---|
| 733 | if out[j]==self.model.getParam(item[1]): |
---|
| 734 | break |
---|
[69bee6d] | 735 | ## unable to compare cov[j]==numpy.nan so switch to None |
---|
[ad6dd4c] | 736 | if cov[j]==None or not numpy.isfinite(cov[j]): |
---|
[69bee6d] | 737 | item[3].Hide() |
---|
| 738 | item[4].Refresh() |
---|
| 739 | item[4].Clear() |
---|
| 740 | item[4].Hide() |
---|
| 741 | else: |
---|
| 742 | item[4].SetValue(format_number(cov[j])) |
---|
| 743 | item[4].Refresh() |
---|
| 744 | item[4].Show(True) |
---|
[c77d859] | 745 | i+=1 |
---|
| 746 | |
---|
| 747 | self.sizer3.Layout() |
---|
| 748 | self.sizer4.Layout() |
---|
[2cded48] | 749 | self.Layout() |
---|
[7437880] | 750 | self.Refresh() |
---|
[c77d859] | 751 | self.SetScrollbars(20,20,200,100) |
---|
| 752 | |
---|
| 753 | |
---|
| 754 | def onSmear(self, event): |
---|
| 755 | """ |
---|
| 756 | Create a smear object that will change the way residuals |
---|
| 757 | are compute when fitting |
---|
| 758 | """ |
---|
[3370922] | 759 | temp_smearer = None |
---|
[c77d859] | 760 | if self.enable_smearer.GetValue(): |
---|
[997131a] | 761 | msg="" |
---|
| 762 | temp_smearer= self.smearer |
---|
[c77d859] | 763 | if hasattr(self.data,"dxl"): |
---|
| 764 | msg= ": Resolution smearing parameters" |
---|
| 765 | if hasattr(self.data,"dxw"): |
---|
| 766 | msg= ": Slit smearing parameters" |
---|
[997131a] | 767 | if self.smearer ==None: |
---|
[c77d859] | 768 | wx.PostEvent(self.manager.parent, StatusEvent(status=\ |
---|
| 769 | "Data contains no smearing information")) |
---|
| 770 | else: |
---|
| 771 | wx.PostEvent(self.manager.parent, StatusEvent(status=\ |
---|
| 772 | "Data contains smearing information %s"%msg)) |
---|
[3370922] | 773 | |
---|
[fb8daaaf] | 774 | ## set smearing value whether or not the data contain the smearing info |
---|
[3370922] | 775 | self.manager.set_smearer(smearer=temp_smearer, qmin= float(self.qmin_x), |
---|
[2b63df0] | 776 | qmax= float(self.qmax_x)) |
---|
[875f1a2] | 777 | ##Calculate chi2 |
---|
[997131a] | 778 | self.compute_chisqr(smearer= temp_smearer) |
---|
[cfc0913] | 779 | ## save the state enable smearing |
---|
[330573d] | 780 | self.state.smearer= temp_smearer |
---|
| 781 | #self.save_current_state() |
---|
| 782 | |
---|
[847091f] | 783 | |
---|
[2b63df0] | 784 | def complete_chisqr(self, output, elapsed=None): |
---|
| 785 | """ |
---|
| 786 | print result chisqr |
---|
| 787 | """ |
---|
| 788 | try: |
---|
[077809c] | 789 | if output ==None: |
---|
| 790 | output= "-" |
---|
[ba95543] | 791 | self.tcChi.SetLabel(str(format_number(output))) |
---|
[0aeabc6] | 792 | |
---|
| 793 | self.sizer5.Layout() |
---|
| 794 | self.Layout() |
---|
| 795 | self.Refresh |
---|
| 796 | ## post state to fit panel |
---|
| 797 | self.state.tcChi =output |
---|
[330573d] | 798 | #event = PageInfoEvent(page = self) |
---|
| 799 | #wx.PostEvent(self.parent, event) |
---|
[2b63df0] | 800 | except: |
---|
[0aeabc6] | 801 | pass |
---|
[2b63df0] | 802 | |
---|
| 803 | |
---|
| 804 | def compute_chisqr1D(self, smearer=None): |
---|
| 805 | """ |
---|
| 806 | Compute chisqr for 1D |
---|
| 807 | """ |
---|
| 808 | from sans.guiframe.utils import check_value |
---|
| 809 | flag = check_value( self.qmin, self.qmax) |
---|
| 810 | |
---|
| 811 | if not flag: |
---|
| 812 | return |
---|
| 813 | |
---|
| 814 | try: |
---|
| 815 | self.qmin_x = float(self.qmin.GetValue()) |
---|
| 816 | self.qmax_x = float(self.qmax.GetValue()) |
---|
| 817 | ##return residuals within self.qmin_x and self.qmax_x |
---|
| 818 | from gui_thread import CalcChisqr1D |
---|
| 819 | ## If a thread is already started, stop it |
---|
| 820 | if self.calc_Chisqr!= None and self.calc_Chisqr.isrunning(): |
---|
| 821 | self.calc_Chisqr.stop() |
---|
| 822 | |
---|
[077809c] | 823 | self.calc_Chisqr= CalcChisqr1D( data1d= self.data, |
---|
[2b63df0] | 824 | model= self.model, |
---|
| 825 | smearer=smearer, |
---|
| 826 | qmin=self.qmin_x, |
---|
| 827 | qmax=self.qmax_x, |
---|
| 828 | completefn = self.complete_chisqr, |
---|
| 829 | updatefn = None) |
---|
| 830 | |
---|
| 831 | self.calc_Chisqr.queue() |
---|
| 832 | |
---|
| 833 | except: |
---|
| 834 | raise ValueError," Could not compute Chisqr for %s Model 2D: "%self.model.name |
---|
| 835 | |
---|
| 836 | |
---|
| 837 | |
---|
| 838 | |
---|
[b787e68c] | 839 | |
---|
[c77d859] | 840 | def compute_chisqr2D(self): |
---|
| 841 | """ |
---|
| 842 | compute chi square given a model and data 2D and set the value |
---|
| 843 | to the tcChi txtcrl |
---|
| 844 | """ |
---|
| 845 | from sans.guiframe.utils import check_value |
---|
| 846 | flag = check_value( self.qmin, self.qmax) |
---|
[2b63df0] | 847 | if not flag: |
---|
| 848 | return |
---|
| 849 | |
---|
| 850 | try: |
---|
| 851 | self.qmin_x = float(self.qmin.GetValue()) |
---|
| 852 | self.qmax_x = float(self.qmax.GetValue()) |
---|
| 853 | |
---|
| 854 | ##return residuals within self.qmin_x and self.qmax_x |
---|
| 855 | from gui_thread import CalcChisqr2D |
---|
| 856 | ## If a thread is already started, stop it |
---|
| 857 | if self.calc_Chisqr!= None and self.calc_Chisqr.isrunning(): |
---|
| 858 | self.calc_Chisqr.stop() |
---|
[0aeabc6] | 859 | |
---|
[077809c] | 860 | self.calc_Chisqr= CalcChisqr2D( data2d= self.data, |
---|
[2b63df0] | 861 | model= self.model, |
---|
| 862 | qmin= self.qmin_x, |
---|
| 863 | qmax = self.qmax_x, |
---|
| 864 | completefn = self.complete_chisqr, |
---|
| 865 | updatefn = None) |
---|
[c77d859] | 866 | |
---|
[2b63df0] | 867 | self.calc_Chisqr.queue() |
---|
| 868 | |
---|
| 869 | except: |
---|
[077809c] | 870 | raise |
---|
[2b63df0] | 871 | |
---|
[c77d859] | 872 | |
---|
[997131a] | 873 | def compute_chisqr(self , smearer=None): |
---|
[c77d859] | 874 | """ |
---|
| 875 | compute chi square given a model and data 1D and set the value |
---|
| 876 | to the tcChi txtcrl |
---|
| 877 | """ |
---|
| 878 | from sans.guiframe.utils import check_value |
---|
| 879 | flag = check_value( self.qmin, self.qmax) |
---|
| 880 | if flag== True: |
---|
| 881 | try: |
---|
| 882 | if hasattr(self.data,"data"): |
---|
| 883 | self.compute_chisqr2D() |
---|
| 884 | return |
---|
| 885 | else: |
---|
[2b63df0] | 886 | self.compute_chisqr1D(smearer=smearer) |
---|
| 887 | return |
---|
[c77d859] | 888 | except: |
---|
[077809c] | 889 | wx.PostEvent(self.parent.parent, StatusEvent(status=\ |
---|
[2b63df0] | 890 | "Chisqr Error: %s"% sys.exc_value)) |
---|
[a8088d7] | 891 | return |
---|
[c77d859] | 892 | |
---|
| 893 | |
---|
| 894 | def select_all_param(self,event): |
---|
| 895 | """ |
---|
| 896 | set to true or false all checkBox given the main checkbox value cb1 |
---|
[d1e0473] | 897 | """ |
---|
| 898 | |
---|
[c77d859] | 899 | self.param_toFit=[] |
---|
| 900 | if self.parameters !=[]: |
---|
[998b6b8] | 901 | if self.cb1.GetValue(): |
---|
[c77d859] | 902 | for item in self.parameters: |
---|
[3fef0a8] | 903 | ## for data2D select all to fit |
---|
| 904 | if self.data.__class__.__name__=="Data2D": |
---|
[c77d859] | 905 | item[0].SetValue(True) |
---|
| 906 | self.param_toFit.append(item ) |
---|
[3fef0a8] | 907 | else: |
---|
| 908 | ## for 1D all parameters except orientation |
---|
| 909 | if not item in self.orientation_params: |
---|
| 910 | item[0].SetValue(True) |
---|
| 911 | self.param_toFit.append(item ) |
---|
| 912 | if len(self.fittable_param)>0: |
---|
| 913 | for item in self.fittable_param: |
---|
| 914 | if self.data.__class__.__name__=="Data2D": |
---|
| 915 | item[0].SetValue(True) |
---|
| 916 | self.param_toFit.append(item ) |
---|
| 917 | else: |
---|
| 918 | ## for 1D all parameters except orientation |
---|
[513115c] | 919 | if not item in self.orientation_params_disp: |
---|
[3fef0a8] | 920 | item[0].SetValue(True) |
---|
| 921 | self.param_toFit.append(item ) |
---|
[c77d859] | 922 | else: |
---|
| 923 | for item in self.parameters: |
---|
| 924 | item[0].SetValue(False) |
---|
| 925 | for item in self.fittable_param: |
---|
| 926 | item[0].SetValue(False) |
---|
| 927 | self.param_toFit=[] |
---|
[330573d] | 928 | self._copy_parameters_state(self.orientation_params, |
---|
| 929 | self.state.orientation_params) |
---|
| 930 | self._copy_parameters_state(self.orientation_params_disp, |
---|
| 931 | self.state.orientation_params_disp) |
---|
| 932 | self._copy_parameters_state(self.parameters, self.state.parameters) |
---|
| 933 | self._copy_parameters_state(self.fittable_param, self.state.fittable_param) |
---|
| 934 | self._copy_parameters_state(self.fixed_param, self.state.fixed_param) |
---|
| 935 | |
---|
| 936 | #self.save_current_state() |
---|
[3595309d] | 937 | if event !=None: |
---|
| 938 | self._undo.Enable(True) |
---|
| 939 | ## post state to fit panel |
---|
| 940 | event = PageInfoEvent(page = self) |
---|
| 941 | wx.PostEvent(self.parent, event) |
---|
| 942 | |
---|
[c77d859] | 943 | |
---|
| 944 | |
---|
| 945 | def select_param(self,event): |
---|
| 946 | """ |
---|
| 947 | Select TextCtrl checked for fitting purpose and stores them |
---|
| 948 | in self.param_toFit=[] list |
---|
| 949 | """ |
---|
| 950 | self.param_toFit=[] |
---|
| 951 | for item in self.parameters: |
---|
| 952 | #Select parameters to fit for list of primary parameters |
---|
[998b6b8] | 953 | if item[0].GetValue(): |
---|
[c77d859] | 954 | if not (item in self.param_toFit): |
---|
| 955 | self.param_toFit.append(item ) |
---|
| 956 | else: |
---|
| 957 | #remove parameters from the fitting list |
---|
| 958 | if item in self.param_toFit: |
---|
| 959 | self.param_toFit.remove(item) |
---|
| 960 | #Select parameters to fit for list of fittable parameters with dispersion |
---|
| 961 | for item in self.fittable_param: |
---|
[998b6b8] | 962 | if item[0].GetValue(): |
---|
[c77d859] | 963 | if not (item in self.param_toFit): |
---|
| 964 | self.param_toFit.append(item) |
---|
| 965 | else: |
---|
| 966 | #remove parameters from the fitting list |
---|
| 967 | if item in self.param_toFit: |
---|
| 968 | self.param_toFit.remove(item) |
---|
| 969 | #Set the value of checkbox that selected every checkbox or not |
---|
| 970 | if len(self.parameters)+len(self.fittable_param) ==len(self.param_toFit): |
---|
| 971 | self.cb1.SetValue(True) |
---|
| 972 | else: |
---|
| 973 | self.cb1.SetValue(False) |
---|
[cfc0913] | 974 | ## save current state of the page |
---|
[330573d] | 975 | self._copy_parameters_state(self.orientation_params, |
---|
| 976 | self.state.orientation_params) |
---|
| 977 | self._copy_parameters_state(self.orientation_params_disp, |
---|
| 978 | self.state.orientation_params_disp) |
---|
| 979 | self._copy_parameters_state(self.parameters, self.state.parameters) |
---|
| 980 | self._copy_parameters_state(self.fittable_param, self.state.fittable_param) |
---|
| 981 | self._copy_parameters_state(self.fixed_param, self.state.fixed_param) |
---|
| 982 | |
---|
| 983 | #self.save_current_state() |
---|
[3595309d] | 984 | if event !=None: |
---|
| 985 | self._undo.Enable(True) |
---|
| 986 | ## post state to fit panel |
---|
| 987 | event = PageInfoEvent(page = self) |
---|
| 988 | wx.PostEvent(self.parent, event) |
---|
| 989 | |
---|
[c77d859] | 990 | |
---|
| 991 | |
---|
[77e23a2] | 992 | def set_model_param_sizer(self, model): |
---|
[c77d859] | 993 | """ |
---|
| 994 | Build the panel from the model content |
---|
| 995 | @param model: the model selected in combo box for fitting purpose |
---|
| 996 | """ |
---|
| 997 | self.sizer3.Clear(True) |
---|
| 998 | self.parameters = [] |
---|
| 999 | self.param_toFit=[] |
---|
| 1000 | self.fittable_param=[] |
---|
| 1001 | self.fixed_param=[] |
---|
[780d095] | 1002 | self.orientation_params=[] |
---|
[60132ef] | 1003 | self.orientation_params_disp=[] |
---|
[c77d859] | 1004 | |
---|
| 1005 | if model ==None: |
---|
| 1006 | self.sizer3.Layout() |
---|
| 1007 | self.SetScrollbars(20,20,200,100) |
---|
| 1008 | return |
---|
[707436d] | 1009 | ## the panel is drawn using the current value of the fit engine |
---|
| 1010 | if self.engine_type==None and self.manager !=None: |
---|
| 1011 | self.engine_type= self.manager._return_engine_type() |
---|
| 1012 | |
---|
[c77d859] | 1013 | box_description= wx.StaticBox(self, -1,str("Model Parameters")) |
---|
| 1014 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
| 1015 | sizer = wx.GridBagSizer(5,5) |
---|
| 1016 | ## save the current model |
---|
| 1017 | self.model = model |
---|
| 1018 | |
---|
| 1019 | keys = self.model.getParamList() |
---|
| 1020 | #list of dispersion paramaters |
---|
| 1021 | self.disp_list=self.model.getDispParamList() |
---|
| 1022 | |
---|
| 1023 | keys.sort() |
---|
| 1024 | |
---|
[6dc9ad8] | 1025 | iy = 0 |
---|
[c77d859] | 1026 | ix = 0 |
---|
| 1027 | self.cb1 = wx.CheckBox(self, -1,"Select all", (10, 10)) |
---|
| 1028 | wx.EVT_CHECKBOX(self, self.cb1.GetId(), self.select_all_param) |
---|
| 1029 | self.cb1.SetValue(False) |
---|
| 1030 | |
---|
| 1031 | sizer.Add(self.cb1,(iy, ix),(1,1),\ |
---|
[eda428b] | 1032 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 5) |
---|
[c77d859] | 1033 | ix +=1 |
---|
| 1034 | self.text2_2 = wx.StaticText(self, -1, 'Values') |
---|
| 1035 | sizer.Add(self.text2_2,(iy, ix),(1,1),\ |
---|
| 1036 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 1037 | ix +=2 |
---|
| 1038 | self.text2_3 = wx.StaticText(self, -1, 'Errors') |
---|
| 1039 | sizer.Add(self.text2_3,(iy, ix),(1,1),\ |
---|
| 1040 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 1041 | self.text2_3.Hide() |
---|
| 1042 | ix +=1 |
---|
| 1043 | self.text2_min = wx.StaticText(self, -1, 'Min') |
---|
| 1044 | sizer.Add(self.text2_min,(iy, ix),(1,1),\ |
---|
| 1045 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 1046 | self.text2_min.Hide() |
---|
| 1047 | ix +=1 |
---|
| 1048 | self.text2_max = wx.StaticText(self, -1, 'Max') |
---|
| 1049 | sizer.Add(self.text2_max,(iy, ix),(1,1),\ |
---|
| 1050 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 1051 | self.text2_max.Hide() |
---|
[6fdfc8f] | 1052 | ix += 1 |
---|
| 1053 | self.text2_4 = wx.StaticText(self, -1, '[Units]') |
---|
| 1054 | sizer.Add(self.text2_4,(iy, ix),(1,1),\ |
---|
| 1055 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 1056 | self.text2_4.Hide() |
---|
[dcf29d7] | 1057 | if self.engine_type=="park": |
---|
| 1058 | self.text2_max.Show(True) |
---|
| 1059 | self.text2_min.Show(True) |
---|
[c77d859] | 1060 | |
---|
| 1061 | for item in keys: |
---|
[780d095] | 1062 | if not item in self.disp_list and not item in self.model.orientation_params: |
---|
[330573d] | 1063 | |
---|
[c77d859] | 1064 | iy += 1 |
---|
| 1065 | ix = 0 |
---|
| 1066 | ## add parameters name with checkbox for selecting to fit |
---|
| 1067 | cb = wx.CheckBox(self, -1, item ) |
---|
| 1068 | cb.SetValue(False) |
---|
| 1069 | wx.EVT_CHECKBOX(self, cb.GetId(), self.select_param) |
---|
| 1070 | sizer.Add( cb,( iy, ix),(1,1), |
---|
[eda428b] | 1071 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 5) |
---|
[d1e0473] | 1072 | |
---|
[c77d859] | 1073 | ## add parameter value |
---|
| 1074 | ix += 1 |
---|
| 1075 | value= self.model.getParam(item) |
---|
[6f2c919] | 1076 | ctl1 = BasicPage.ModelTextCtrl(self, -1, size=(_BOX_WIDTH,20), |
---|
[c77d859] | 1077 | style=wx.TE_PROCESS_ENTER) |
---|
| 1078 | |
---|
[77e23a2] | 1079 | ctl1.SetValue(format_number(value)) |
---|
[c77d859] | 1080 | sizer.Add(ctl1, (iy,ix),(1,1), wx.EXPAND) |
---|
| 1081 | ## text to show error sign |
---|
| 1082 | ix += 1 |
---|
| 1083 | text2=wx.StaticText(self, -1, '+/-') |
---|
| 1084 | sizer.Add(text2,(iy, ix),(1,1),\ |
---|
| 1085 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 1086 | text2.Hide() |
---|
| 1087 | ## txtcrtl to add error from fit |
---|
| 1088 | ix += 1 |
---|
| 1089 | ctl2 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=wx.TE_PROCESS_ENTER) |
---|
| 1090 | sizer.Add(ctl2, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 1091 | ctl2.Hide() |
---|
| 1092 | |
---|
[77e23a2] | 1093 | param_min, param_max= self.model.details[item][1:] |
---|
[c77d859] | 1094 | ix += 1 |
---|
[6f2c919] | 1095 | ctl3 = BasicPage.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/2,20), style=wx.TE_PROCESS_ENTER, |
---|
| 1096 | kill_focus_callback = self._onparamRangeEnter, |
---|
| 1097 | set_focus_callback = self._onparamRangeEnter) |
---|
[298b762] | 1098 | if param_min ==None: |
---|
| 1099 | ctl3.SetValue("") |
---|
| 1100 | else: |
---|
| 1101 | ctl3.SetValue(str(param_min)) |
---|
[c77d859] | 1102 | sizer.Add(ctl3, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 1103 | ctl3.Hide() |
---|
[77e23a2] | 1104 | |
---|
[c77d859] | 1105 | ix += 1 |
---|
[6f2c919] | 1106 | ctl4 = BasicPage.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/2,20), style=wx.TE_PROCESS_ENTER, |
---|
| 1107 | kill_focus_callback = self._onparamRangeEnter, |
---|
| 1108 | set_focus_callback = self._onparamRangeEnter) |
---|
[c77d859] | 1109 | sizer.Add(ctl4, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[298b762] | 1110 | if param_max==None: |
---|
| 1111 | ctl4.SetValue("") |
---|
| 1112 | else: |
---|
| 1113 | ctl4.SetValue(str(param_max)) |
---|
[c77d859] | 1114 | ctl4.Hide() |
---|
[dcf29d7] | 1115 | |
---|
| 1116 | if self.engine_type=="park": |
---|
| 1117 | ctl3.Show(True) |
---|
| 1118 | ctl4.Show(True) |
---|
[6fdfc8f] | 1119 | ix +=1 |
---|
| 1120 | # Units |
---|
| 1121 | try: |
---|
| 1122 | units = wx.StaticText(self, -1, self.model.details[item][0], style=wx.ALIGN_LEFT) |
---|
| 1123 | except: |
---|
| 1124 | units = wx.StaticText(self, -1, "", style=wx.ALIGN_LEFT) |
---|
| 1125 | sizer.Add(units, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[dcf29d7] | 1126 | |
---|
[c77d859] | 1127 | ##[cb state, name, value, "+/-", error of fit, min, max , units] |
---|
| 1128 | self.parameters.append([cb,item, ctl1, |
---|
[240b9966] | 1129 | text2,ctl2, ctl3, ctl4,units]) |
---|
[2d5f7a1] | 1130 | |
---|
[c77d859] | 1131 | iy+=1 |
---|
[2a5bba7] | 1132 | sizer.Add((10,10),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
[5af5183] | 1133 | |
---|
[f20767b] | 1134 | # type can be either Guassian or Array |
---|
[5b53a5c] | 1135 | if len(self.model.dispersion.values())>0: |
---|
| 1136 | type= self.model.dispersion.values()[0]["type"] |
---|
| 1137 | else: |
---|
| 1138 | type = "Gaussian" |
---|
[6dc9ad8] | 1139 | |
---|
| 1140 | iy += 1 |
---|
| 1141 | ix = 0 |
---|
| 1142 | #Add tile for orientational angle |
---|
| 1143 | for item in keys: |
---|
| 1144 | if item in self.model.orientation_params: |
---|
| 1145 | orient_angle = wx.StaticText(self, -1, '[For 2D only]:') |
---|
| 1146 | sizer.Add(orient_angle,(iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 1147 | if not self.data.__class__.__name__ =="Data2D": |
---|
| 1148 | orient_angle.Hide() |
---|
| 1149 | else: |
---|
| 1150 | orient_angle.Show(True) |
---|
| 1151 | break |
---|
[5b53a5c] | 1152 | |
---|
[f20767b] | 1153 | #For Gaussian only |
---|
| 1154 | if type.lower() != "array": |
---|
| 1155 | for item in self.model.orientation_params: |
---|
| 1156 | if not item in self.disp_list: |
---|
| 1157 | iy += 1 |
---|
| 1158 | ix = 0 |
---|
| 1159 | ## add parameters name with checkbox for selecting to fit |
---|
| 1160 | cb = wx.CheckBox(self, -1, item ) |
---|
| 1161 | cb.SetValue(False) |
---|
| 1162 | wx.EVT_CHECKBOX(self, cb.GetId(), self.select_param) |
---|
| 1163 | if self.data.__class__.__name__ =="Data2D": |
---|
[6dc9ad8] | 1164 | cb.Show(True) |
---|
[f20767b] | 1165 | cb.Enable() |
---|
| 1166 | else: |
---|
[6dc9ad8] | 1167 | cb.Hide() |
---|
[f20767b] | 1168 | cb.Disable() |
---|
| 1169 | sizer.Add( cb,( iy, ix),(1,1), |
---|
| 1170 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 5) |
---|
| 1171 | |
---|
| 1172 | ## add parameter value |
---|
| 1173 | ix += 1 |
---|
| 1174 | value= self.model.getParam(item) |
---|
| 1175 | ctl1 = BasicPage.ModelTextCtrl(self, -1, size=(_BOX_WIDTH,20), |
---|
| 1176 | style=wx.TE_PROCESS_ENTER) |
---|
[780d095] | 1177 | |
---|
[f20767b] | 1178 | ctl1.SetValue(format_number(value)) |
---|
| 1179 | if self.data.__class__.__name__ =="Data2D": |
---|
[6dc9ad8] | 1180 | #ctl1.Show(True) |
---|
[f20767b] | 1181 | ctl1.Enable() |
---|
| 1182 | else: |
---|
[6dc9ad8] | 1183 | #ctl1.Hide() |
---|
[f20767b] | 1184 | ctl1.Disable() |
---|
| 1185 | sizer.Add(ctl1, (iy,ix),(1,1), wx.EXPAND) |
---|
| 1186 | ## text to show error sign |
---|
| 1187 | ix += 1 |
---|
| 1188 | text2=wx.StaticText(self, -1, '+/-') |
---|
| 1189 | sizer.Add(text2,(iy, ix),(1,1),\ |
---|
| 1190 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 1191 | text2.Hide() |
---|
| 1192 | ## txtcrtl to add error from fit |
---|
| 1193 | ix += 1 |
---|
| 1194 | ctl2 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=wx.TE_PROCESS_ENTER) |
---|
| 1195 | sizer.Add(ctl2, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 1196 | ctl2.Hide() |
---|
| 1197 | if self.data.__class__.__name__ =="Data2D": |
---|
[6dc9ad8] | 1198 | ctl1.Show(True) |
---|
[f20767b] | 1199 | ctl1.Enable() |
---|
| 1200 | else: |
---|
[6dc9ad8] | 1201 | ctl1.Hide() |
---|
[f20767b] | 1202 | ctl1.Disable() |
---|
| 1203 | param_min, param_max= self.model.details[item][1:] |
---|
| 1204 | ix += 1 |
---|
| 1205 | ctl3 = BasicPage.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/2,20), style=wx.TE_PROCESS_ENTER, |
---|
| 1206 | kill_focus_callback = self._onparamRangeEnter, |
---|
| 1207 | set_focus_callback = self._onparamRangeEnter) |
---|
| 1208 | if param_min ==None: |
---|
| 1209 | ctl3.SetValue("") |
---|
| 1210 | else: |
---|
| 1211 | ctl3.SetValue(str(param_min)) |
---|
| 1212 | sizer.Add(ctl3, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 1213 | ctl3.Hide() |
---|
| 1214 | if self.data.__class__.__name__ =="Data2D": |
---|
[6dc9ad8] | 1215 | #ctl3.Show(True) |
---|
[f20767b] | 1216 | ctl3.Enable() |
---|
| 1217 | else: |
---|
[6dc9ad8] | 1218 | #ctl3.Hide() |
---|
[f20767b] | 1219 | ctl3.Disable() |
---|
| 1220 | ix += 1 |
---|
| 1221 | ctl4 = BasicPage.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/2,20), style=wx.TE_PROCESS_ENTER, |
---|
| 1222 | kill_focus_callback = self._onparamRangeEnter, |
---|
| 1223 | set_focus_callback = self._onparamRangeEnter) |
---|
| 1224 | sizer.Add(ctl4, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 1225 | if param_max ==None: |
---|
| 1226 | ctl4.SetValue("") |
---|
| 1227 | else: |
---|
| 1228 | ctl4.SetValue(str(param_max)) |
---|
| 1229 | ctl4.Hide() |
---|
| 1230 | if self.data.__class__.__name__ =="Data2D": |
---|
[6dc9ad8] | 1231 | #ctl4.Show(True) |
---|
[f20767b] | 1232 | ctl4.Enable() |
---|
| 1233 | else: |
---|
[6dc9ad8] | 1234 | #ctl4.Hide() |
---|
[f20767b] | 1235 | ctl4.Disable() |
---|
| 1236 | if self.engine_type=="park": |
---|
| 1237 | ctl3.Show(True) |
---|
| 1238 | ctl4.Show(True) |
---|
| 1239 | ix +=1 |
---|
| 1240 | # Units |
---|
| 1241 | try: |
---|
| 1242 | units = wx.StaticText(self, -1, self.model.details[item][0], style=wx.ALIGN_LEFT) |
---|
| 1243 | except: |
---|
| 1244 | units = wx.StaticText(self, -1, "", style=wx.ALIGN_LEFT) |
---|
| 1245 | if self.data.__class__.__name__ =="Data2D": |
---|
[6dc9ad8] | 1246 | units.Show(True) |
---|
[f20767b] | 1247 | units.Enable() |
---|
| 1248 | else: |
---|
[6dc9ad8] | 1249 | units.Hide() |
---|
[f20767b] | 1250 | units.Disable() |
---|
| 1251 | sizer.Add(units, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 1252 | |
---|
| 1253 | |
---|
| 1254 | ##[cb state, name, value, "+/-", error of fit, min, max , units] |
---|
| 1255 | self.parameters.append([cb,item, ctl1, |
---|
| 1256 | text2,ctl2, ctl3, ctl4,units]) |
---|
| 1257 | self.orientation_params.append([cb,item, ctl1, |
---|
| 1258 | text2,ctl2, ctl3, ctl4,units]) |
---|
[780d095] | 1259 | |
---|
| 1260 | iy+=1 |
---|
| 1261 | sizer.Add((10,10),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
[c77d859] | 1262 | |
---|
| 1263 | #Display units text on panel |
---|
| 1264 | for item in keys: |
---|
| 1265 | if self.model.details[item][0]!='': |
---|
| 1266 | self.text2_4.Show() |
---|
| 1267 | break |
---|
| 1268 | else: |
---|
| 1269 | self.text2_4.Hide() |
---|
[240b9966] | 1270 | |
---|
| 1271 | self._copy_parameters_state(self.orientation_params, |
---|
| 1272 | self.state.orientation_params) |
---|
| 1273 | self._copy_parameters_state(self.orientation_params_disp, |
---|
| 1274 | self.state.orientation_params_disp) |
---|
| 1275 | self._copy_parameters_state(self.parameters, self.state.parameters) |
---|
| 1276 | self._copy_parameters_state(self.fittable_param, self.state.fittable_param) |
---|
| 1277 | self._copy_parameters_state(self.fixed_param, self.state.fixed_param) |
---|
[c77d859] | 1278 | |
---|
[240b9966] | 1279 | boxsizer1.Add(sizer) |
---|
[c77d859] | 1280 | self.sizer3.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10) |
---|
| 1281 | self.sizer3.Layout() |
---|
[330573d] | 1282 | self.Layout() |
---|
| 1283 | self.Refresh() |
---|
[c77d859] | 1284 | self.SetScrollbars(20,20,200,100) |
---|
[330573d] | 1285 | |
---|
[c77d859] | 1286 | |
---|
| 1287 | |
---|
| 1288 | class HelpWindow(wx.Frame): |
---|
| 1289 | def __init__(self, parent, id, title): |
---|
| 1290 | wx.Frame.__init__(self, parent, id, title, size=(570, 400)) |
---|
| 1291 | |
---|
| 1292 | from sans.models.CylinderModel import CylinderModel |
---|
| 1293 | model = CylinderModel() |
---|
[2d5f7a1] | 1294 | |
---|
[c77d859] | 1295 | from danse.common.plottools.plottables import Data1D |
---|
| 1296 | data= Data1D(x=[1,2], y=[3,4], dy=[0.1, 0,1]) |
---|
| 1297 | |
---|
[cfc0913] | 1298 | from fitpanel import PageInfo |
---|
[c77d859] | 1299 | myinfo = PageInfo(self, model, data=data ) |
---|
| 1300 | |
---|
| 1301 | ## add data |
---|
| 1302 | |
---|
| 1303 | from models import ModelList |
---|
| 1304 | mylist= ModelList() |
---|
| 1305 | |
---|
| 1306 | from sans.models.SphereModel import SphereModel |
---|
| 1307 | from sans.models.SquareWellStructure import SquareWellStructure |
---|
| 1308 | from sans.models.DebyeModel import DebyeModel |
---|
| 1309 | from sans.models.LineModel import LineModel |
---|
| 1310 | name= "shapes" |
---|
| 1311 | list1= [SphereModel] |
---|
| 1312 | mylist.set_list( name, list1) |
---|
| 1313 | |
---|
| 1314 | name= "Shape-independent" |
---|
| 1315 | list1= [DebyeModel] |
---|
| 1316 | mylist.set_list( name, list1) |
---|
| 1317 | |
---|
| 1318 | name= "Structure Factors" |
---|
| 1319 | list1= [SquareWellStructure] |
---|
| 1320 | mylist.set_list( name, list1) |
---|
| 1321 | |
---|
| 1322 | name= "Added models" |
---|
| 1323 | list1= [LineModel] |
---|
| 1324 | mylist.set_list( name, list1) |
---|
| 1325 | |
---|
| 1326 | myinfo.model_list_box = mylist.get_list() |
---|
| 1327 | |
---|
| 1328 | self.page = FitPage(self, myinfo) |
---|
| 1329 | |
---|
| 1330 | |
---|
| 1331 | |
---|
| 1332 | self.Centre() |
---|
| 1333 | self.Show(True) |
---|
| 1334 | |
---|
| 1335 | |
---|
| 1336 | |
---|
| 1337 | if __name__=="__main__": |
---|
| 1338 | app = wx.App() |
---|
| 1339 | HelpWindow(None, -1, 'HelpWindow') |
---|
| 1340 | app.MainLoop() |
---|
| 1341 | |
---|