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